Announcement

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

  • Best method for doing Mixed ANOVA in STATA?

    Hello everyone, I'm trying to analyze this 2x2 factorial design I have, where one factor is between-subjects and the other is within-subjects. In SPSS it's straight forward, just do a repeated measures anova and add your between subjects factor. But I'm trying to learn STATA, so here I am. Should I try to do this using the split-plot ANOVA commands, or should use a mixed model using the mixed command?

    Thank you in advance
    Last edited by butler bj; 05 Nov 2015, 15:05.

  • #2
    Unless I misunderstand you, your study sounds like a conventional randomized complete blocks design.
    Code:
    anova response treatment block
    anova does have a repeated() option, but it isn't necessary here, because you have only two levels of your within-subjects factor. You wouldn't need to resort to mixed unless you have an unbalanced dataset.

    Comment


    • #3
      On further thought, it seems that I misunderstood. You can set up a split-plot ANOVA in Stata easily enough (see below) as shown in the example in the help file for anova, and illustrated at length at the UCLA ATS site.

      .ÿversionÿ14.1

      .ÿ
      .ÿclearÿ*

      .ÿsetÿmoreÿoff

      .ÿsetÿseedÿ`=date("2015-11-06",ÿ"YMD")'

      .ÿquietlyÿsetÿobsÿ24

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

      .ÿgenerateÿbyteÿsubjectÿ=ÿ_n

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

      .ÿforvaluesÿtimeÿ=ÿ1/2ÿ{
      ÿÿ2.ÿÿÿÿÿÿÿÿÿgenerateÿdoubleÿresponse`time'ÿ=ÿuÿ+ÿ`time'ÿ*ÿ`time'ÿ*ÿrnormal()
      ÿÿ3.ÿ}

      .ÿpreserve

      .ÿquietlyÿreshapeÿlongÿresponse,ÿi(subject)ÿj(time)

      .ÿ
      .ÿ*
      .ÿ*ÿSplit-plotÿANOVA
      .ÿ*
      .ÿanovaÿresponseÿtreatmentÿ/ÿsubject|treatmentÿtimeÿtreatment#time,ÿrepeated(time)

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿÿÿÿÿÿÿÿÿ48ÿÿÿÿR-squaredÿÿÿÿÿ=ÿÿ0.5841
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿRootÿMSEÿÿÿÿÿÿ=ÿÿÿÿ2.59036ÿÿÿÿAdjÿR-squaredÿ=ÿÿ0.1115

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿPartialÿSSÿÿÿÿÿÿÿÿÿdfÿÿÿÿÿÿÿÿÿMSÿÿÿÿÿÿÿÿFÿÿÿÿProb>F
      ÿÿÿÿÿÿÿ------------------+----------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿModelÿ|ÿÿÿ207.3088ÿÿÿÿÿÿÿÿÿ25ÿÿÿÿ8.292352ÿÿÿÿÿÿ1.24ÿÿ0.3098
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿtreatmentÿ|ÿÿ9.6980773ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ9.6980773ÿÿÿÿÿÿ1.12ÿÿ0.3005
      ÿÿÿÿÿÿÿsubject|treatmentÿ|ÿÿÿ189.7406ÿÿÿÿÿÿÿÿÿ22ÿÿÿ8.6245729ÿÿ
      ÿÿÿÿÿÿÿ------------------+----------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿtimeÿ|ÿÿ3.1235067ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ3.1235067ÿÿÿÿÿÿ0.47ÿÿ0.5022
      ÿÿÿÿÿÿÿÿÿÿtreatment#timeÿ|ÿÿ4.7466128ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ4.7466128ÿÿÿÿÿÿ0.71ÿÿ0.4094
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿ147.61956ÿÿÿÿÿÿÿÿÿ22ÿÿÿ6.7099801ÿÿ
      ÿÿÿÿÿÿÿ------------------+----------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿTotalÿ|ÿÿ354.92836ÿÿÿÿÿÿÿÿÿ47ÿÿÿ7.5516673ÿÿ


      Between-subjectsÿerrorÿterm:ÿÿsubject|treatment
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿLevels:ÿÿ24ÿÿÿÿÿÿÿÿ(22ÿdf)
      ÿÿÿÿÿLowestÿb.s.e.ÿvariable:ÿÿsubject
      ÿÿÿÿÿCovarianceÿpooledÿover:ÿÿtreatmentÿÿ(forÿrepeatedÿvariable)

      Repeatedÿvariable:ÿtime
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿHuynh-Feldtÿepsilonÿÿÿÿÿÿÿÿ=ÿÿ1.0476
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ*Huynh-Feldtÿepsilonÿresetÿtoÿ1.0000
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿGreenhouse-Geisserÿepsilonÿ=ÿÿ1.0000
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿBox'sÿconservativeÿepsilonÿ=ÿÿ1.0000

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ------------ÿProbÿ>ÿFÿ------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿÿÿÿÿdfÿÿÿÿÿÿFÿÿÿÿRegularÿÿÿÿH-FÿÿÿÿÿÿG-GÿÿÿÿÿÿBox
      ÿÿÿÿÿÿÿ------------------+----------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿtimeÿ|ÿÿÿÿÿÿ1ÿÿÿÿÿ0.47ÿÿÿ0.5022ÿÿÿ0.5022ÿÿÿ0.5022ÿÿÿ0.5022
      ÿÿÿÿÿÿÿÿÿÿtreatment#timeÿ|ÿÿÿÿÿÿ1ÿÿÿÿÿ0.71ÿÿÿ0.4094ÿÿÿ0.4094ÿÿÿ0.4094ÿÿÿ0.4094
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿÿÿÿ22
      ÿÿÿÿÿÿÿ-----------------------------------------------------------------------

      .ÿ
      .ÿ*
      .ÿ*ÿMANOVA
      .ÿ*
      .ÿrestore

      .ÿmanovaÿresponse1ÿresponse2ÿ=ÿtreatment

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿÿÿÿÿÿÿÿÿ24

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWÿ=ÿWilks'ÿlambdaÿÿÿÿÿÿLÿ=ÿLawley-Hotellingÿtrace
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPÿ=ÿPillai'sÿtraceÿÿÿÿÿRÿ=ÿRoy'sÿlargestÿroot

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿStatisticÿÿÿÿÿÿÿÿdfÿÿÿÿF(df1,ÿÿÿÿÿdf2)ÿ=ÿÿÿFÿÿÿProb>F
      ÿÿÿÿÿÿÿÿÿÿ-----------+-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿtreatmentÿ|Wÿÿÿ0.9503ÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ2.0ÿÿÿÿÿ21.0ÿÿÿÿÿ0.55ÿ0.5854ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Pÿÿÿ0.0497ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.0ÿÿÿÿÿ21.0ÿÿÿÿÿ0.55ÿ0.5854ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Lÿÿÿ0.0523ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.0ÿÿÿÿÿ21.0ÿÿÿÿÿ0.55ÿ0.5854ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Rÿÿÿ0.0523ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.0ÿÿÿÿÿ21.0ÿÿÿÿÿ0.55ÿ0.5854ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ22
      ÿÿÿÿÿÿÿÿÿÿ-----------+-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿTotalÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ23
      ÿÿÿÿÿÿÿÿÿÿ-------------------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿeÿ=ÿexact,ÿaÿ=ÿapproximate,ÿuÿ=ÿupperÿboundÿonÿF

      .ÿ
      .ÿ//Treatmentÿ×ÿTimeÿInteraction
      .ÿmatrixÿinputÿYÿ=ÿ(-1ÿ1)

      .ÿmanovatestÿtreatment,ÿytransform(Y)

      ÿTransformationÿofÿtheÿdependentÿvariables
      ÿ(1)ÿÿÿÿ-ÿresponse1ÿ+ÿresponse2

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWÿ=ÿWilks'ÿlambdaÿÿÿÿÿÿLÿ=ÿLawley-Hotellingÿtrace
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPÿ=ÿPillai'sÿtraceÿÿÿÿÿRÿ=ÿRoy'sÿlargestÿroot

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿStatisticÿÿÿÿÿÿÿÿdfÿÿÿÿF(df1,ÿÿÿÿÿdf2)ÿ=ÿÿÿFÿÿÿProb>F
      ÿÿÿÿÿÿÿÿÿÿ-----------+-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿtreatmentÿ|Wÿÿÿ0.9688ÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.71ÿ0.4094ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Pÿÿÿ0.0312ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.71ÿ0.4094ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Lÿÿÿ0.0322ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.71ÿ0.4094ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Rÿÿÿ0.0322ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.71ÿ0.4094ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ22
      ÿÿÿÿÿÿÿÿÿÿ-------------------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿeÿ=ÿexact,ÿaÿ=ÿapproximate,ÿuÿ=ÿupperÿboundÿonÿF

      .ÿ
      .ÿ//ÿMainÿEffectsÿofÿTime
      .ÿmatrixÿinputÿTÿ=ÿ(0.5ÿ0.5ÿ1)

      .ÿmanovatestÿ,ÿtest(T)ÿytransform(Y)

      ÿTransformationÿofÿtheÿdependentÿvariables
      ÿ(1)ÿÿÿÿ-ÿresponse1ÿ+ÿresponse2

      ÿTestÿconstraint
      ÿ(1)ÿÿÿÿ.5*0.treatmentÿ+ÿ.5*1.treatmentÿ+ÿ_consÿ=ÿ0

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWÿ=ÿWilks'ÿlambdaÿÿÿÿÿÿLÿ=ÿLawley-Hotellingÿtrace
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPÿ=ÿPillai'sÿtraceÿÿÿÿÿRÿ=ÿRoy'sÿlargestÿroot

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿStatisticÿÿÿÿÿÿÿÿdfÿÿÿÿF(df1,ÿÿÿÿÿdf2)ÿ=ÿÿÿFÿÿÿProb>F
      ÿÿÿÿÿÿÿÿÿÿ-----------+-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿmanovatestÿ|Wÿÿÿ0.9793ÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.47ÿ0.5022ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Pÿÿÿ0.0207ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.47ÿ0.5022ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Lÿÿÿ0.0212ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.47ÿ0.5022ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Rÿÿÿ0.0212ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ0.47ÿ0.5022ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ22
      ÿÿÿÿÿÿÿÿÿÿ-------------------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿeÿ=ÿexact,ÿaÿ=ÿapproximate,ÿuÿ=ÿupperÿboundÿonÿF

      .ÿ
      .ÿ//ÿMainÿEffectsÿofÿTreatment
      .ÿmatrixÿdefineÿYÿ=ÿJ(1,ÿ2,ÿ1)

      .ÿmanovatestÿtreatment,ÿytransform(Y)

      ÿTransformationÿofÿtheÿdependentÿvariables
      ÿ(1)ÿÿÿÿresponse1ÿ+ÿresponse2

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWÿ=ÿWilks'ÿlambdaÿÿÿÿÿÿLÿ=ÿLawley-Hotellingÿtrace
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPÿ=ÿPillai'sÿtraceÿÿÿÿÿRÿ=ÿRoy'sÿlargestÿroot

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿStatisticÿÿÿÿÿÿÿÿdfÿÿÿÿF(df1,ÿÿÿÿÿdf2)ÿ=ÿÿÿFÿÿÿProb>F
      ÿÿÿÿÿÿÿÿÿÿ-----------+-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿtreatmentÿ|Wÿÿÿ0.9514ÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.12ÿ0.3005ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Pÿÿÿ0.0486ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.12ÿ0.3005ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Lÿÿÿ0.0511ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.12ÿ0.3005ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Rÿÿÿ0.0511ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.12ÿ0.3005ÿe
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|-------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ22
      ÿÿÿÿÿÿÿÿÿÿ-------------------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿeÿ=ÿexact,ÿaÿ=ÿapproximate,ÿuÿ=ÿupperÿboundÿonÿF

      .ÿ
      .ÿexit

      endÿofÿdo-file


      .

      Comment


      • #4
        Originally posted by Joseph Coveney View Post
        On further thought, it seems that I misunderstood. You can set up a split-plot ANOVA in Stata easily enough (see below) as shown in the example in the help file for anova, and illustrated at length
        Awesome, thank you for your help!

        Comment

        Working...
        X