Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • t-test for subset of one variable against second variable

    I have a randomized control trial with treatment and control taking survey 1, then treatment watches video and takes survey 2.

    I have a variable called group that contains two subsets - treatment and control. I have two other variables, survey_1 and survey_2. I need to run a ttest comparing the mean of the control group survey_1 to the mean of survey_2.

  • #2
    You'll have to make a boatload of assumptions about confounding, but you can try a so-called cell means model. Usually it's used in a factorial ANOVA context, but in your case, it's in a repeated-measures context, and so you'd use it in a mixed-effects model. Mabye something like the following.

    .ÿ
    .ÿversionÿ15.1

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿsetÿseedÿ`=strreverse("1523828")'

    .ÿ
    .ÿquietlyÿsetÿobsÿ14

    .ÿgenerateÿbyteÿpidÿ=ÿ_n

    .ÿgenerateÿdoubleÿpid_uÿ=ÿrnormal()

    .ÿ
    .ÿgenerateÿbyteÿtrtÿ=ÿmod(_n,ÿ2)

    .ÿlabelÿdefineÿGroupsÿ0ÿControlÿ1ÿExperimental

    .ÿlabelÿvaluesÿtrtÿGroups

    .ÿ
    .ÿquietlyÿexpandÿ2

    .ÿbysortÿpid:ÿgenerateÿbyteÿsrvÿ=ÿ_n

    .ÿlabelÿdefineÿSurveysÿ1ÿ"Surveyÿ1"ÿ2ÿ"Surveyÿ2"

    .ÿlabelÿvaluesÿsrvÿSurveys

    .ÿ
    .ÿgenerateÿdoubleÿrspÿ=ÿpid_uÿ+ÿrnormal()

    .ÿquietlyÿreplaceÿrspÿ=ÿ.ÿifÿtrtÿ==ÿ"Control":Groupsÿ&ÿsrvÿ==ÿ"Surveyÿ2":Surveys

    .ÿ
    .ÿ//ÿ"Cellÿmeansÿmodel"
    .ÿxtregÿrspÿ0.trt#1.srvÿ1.trt#1.srvÿ1.trt#2.srv,ÿi(pid)ÿre

    Random-effectsÿGLSÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿÿÿÿ21
    Groupÿvariable:ÿpidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿÿ14

    R-sq:ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
    ÿÿÿÿÿwithinÿÿ=ÿ0.0003ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿÿÿÿ1
    ÿÿÿÿÿbetweenÿ=ÿ0.0219ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿÿÿÿ1.5
    ÿÿÿÿÿoverallÿ=ÿ0.0203ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿÿÿÿ2

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(2)ÿÿÿÿÿÿ=ÿÿÿÿÿÿÿ0.28
    corr(u_i,ÿX)ÿÿÿ=ÿ0ÿ(assumed)ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.8711

    ----------------------------------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿrspÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
    -----------------------+----------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿtrt#srvÿ|
    Experimental#Surveyÿ1ÿÿ|ÿÿÿÿ.445805ÿÿÿ.9058157ÿÿÿÿÿ0.49ÿÿÿ0.623ÿÿÿÿ-1.329561ÿÿÿÿ2.221171
    Experimental#Surveyÿ2ÿÿ|ÿÿÿ.4656917ÿÿÿ.9058157ÿÿÿÿÿ0.51ÿÿÿ0.607ÿÿÿÿ-1.309675ÿÿÿÿ2.241058
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ_consÿ|ÿÿ-.4708248ÿÿÿ.6405085ÿÿÿÿ-0.74ÿÿÿ0.462ÿÿÿÿ-1.726198ÿÿÿÿ.7845487
    -----------------------+----------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿsigma_uÿ|ÿÿ1.4213813
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿsigma_eÿ|ÿÿ.95469132
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿrhoÿ|ÿÿ.68911664ÿÿÿ(fractionÿofÿvarianceÿdueÿtoÿu_i)
    ----------------------------------------------------------------------------------------

    .ÿ
    .ÿtestÿ0.trt#1.srvÿ=ÿ1.trt#2.srv

    ÿ(ÿ1)ÿÿ0b.trt#1b.srvÿ-ÿ1.trt#2.srvÿ=ÿ0

    ÿÿÿÿÿÿÿÿÿÿÿchi2(ÿÿ1)ÿ=ÿÿÿÿ0.26
    ÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿ=ÿÿÿÿ0.6072

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .

    Comment


    • #3
      ok, thank you.

      Comment

      Working...
      X