Announcement

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

  • Quadratic term in mixed model

    Dear Stata experts,

    I study the impact of different variables on children's growth with a mixed model.
    I put the time (age) in quadratic form.
    I don't know where I am supposed to put the Age², in the fixed effects or random effects?

    I did that before but I'm not sure:
    xtmixed outcome var1 var2 var3 var4 var5 agej agej2 || patient_id: agej, cov(uns) reml

    I thank you in advance for your help,

    Rémy

  • #2
    It has to be both. First of all, any variable (whether we are dealing with a quadratic model or not) which appears in the random slopes section must also be present in the fixed effects part of the model or the estimates of the random slopes will be incorrect. Then, specifically in the case of a quadratic model, it makes no sense to have random slope for the linear term but not the quadratic term--in fact that would be a very bizarre model indeed.

    Note also that since version 13, -xtmixed- has been renamed -mixed-. Stata still recognizes -xtmixed-, but at some point in the future, that might cease to happen, so best to get in the habit of calling it -mixed-.

    Comment


    • #3
      Thank you very much for your help Clyde.
      I work on Sata 11, that's why I used "xtmixed".

      Comment


      • #4
        Dear Stata experts,

        I tried to launched the model but I have error message and I don't understand why.

        model: xtmixed poidsg sexe sexe#agej sexe#agej2 agej agej2|| patient_id: agej agej2, cov(unstr) reml

        I have two types of messages, in large quantities:
        note: 1.sexenouveaune#7921.agej2 omitted because of collinearity
        note: 1.sexenouveaune#8100.agej2 identifies no observations in the sample


        I checked, there isn't missing value.
        Do you have an idea for this problem?

        I thank you in advance for your help,

        Rémy

        Comment


        • #5
          in an interaction, Stata interprets variables that don't identify their "type" as being categorical; put "c." in front of your age variables; see
          Code:
          help fvvarlist
          note also that making your own interaction variables (I gather that agej2 is agej*agej) is generally not a good idea as it will impair use of the -margins- command (and possibly other post-hoc commands); again, see the previously noted help file

          Comment


          • #6
            Thank you for your help,​i​​​​​t works.
            I don't understand for my variable agej2.
            I saw the help but how do I write the interaction with sexe for example.
            sexe#c.agej#c.agej?
            And in the random part, do I write c.agej#c.agej too instead of agej2?

            Comment


            • #7
              Hello.

              I have a very similar question regarding the usage of quadratic terms in mixed models. I stumbled upon various useful suggestions on constructing mixed model.

              Originally posted by Clyde Schechter View Post
              It has to be both. First of all, any variable (whether we are dealing with a quadratic model or not) which appears in the random slopes section must also be present in the fixed effects part of the model or the estimates of the random slopes will be incorrect. Then, specifically in the case of a quadratic model, it makes no sense to have random slope for the linear term but not the quadratic term--in fact that would be a very bizarre model indeed.
              I am presently running a mixed effects model on Stata 15 with continuous dep var and continuous indep var collected at baseline and a one-time follow up after follow-up (median = 4 years)

              Below is my code
              Code:
              mixed c.Z_HOMA c.stxLept_MSD_T##c.time##c.time##c.surveytime c.Age i.sex i.Country c.Z_SBP c.AVM_1_week_T c.Z_TRG i.smoke_occcat i.alc_lifecat i.dm_fhT club_mbr_T c.Z_Waist_To_Height c.stxAdip_MSD_T  c.stxLept_MSD_T c.stxTNF_a_MSD_T c.stxIP_10_MSD_T c.stxIL_8_MSD_T c.stxIL_15_MSD_T c.stxIL_1Ra_MSD_T c.stxIL_6_MSD_T c.stxCRP_MSD_T || ID_cohort: time, cov(unstr) iterate(100)
              I prepared the code with the help of information from the following link
              https://www.statalist.org/forums/for...62#post1384462

              But now I am confused between the suggestion offered on this post and the link I referred above. whether to use the quadratic term for time in random part of the model or not. Does the usage of quadratic term for time in random part is model specific. If yes, how one decides? I also referred to below link to get clarity on this issue but was unsuccesful

              https://stats.stackexchange.com/ques...in-random-part

              Any help is appreciated.

              Thanks in advance

              Comment


              • #8
                In the post you link to, I overlooked the fact that the quadratic term had been omitted from the random effects part of the model. My focus there was on the issue of whether or not the discrete dka variable should be interacted with duration (and duration squared). I wasn't really even paying attention to the random effects part of that model. Had I been, I would have pointed out that it is nonsensical to have linear and quadratic terms in the fixed effects portion but only have a random slope for the linear term. I wish I had noticed that and said that, but I didn't.

                To be perfectly clear, it is never appropriate to have linear and quadratic terms in the fixed effects part of the model but only have a random slope for one of those two. If you want random slopes for that variable, you must have them for both the linear and quadratic.

                Good news: with version 16, Stata now supports factor variable notation in the random effects portions of the model, so doing this, and using -margins- afterwards is now much simpler than before.

                Comment


                • #9
                  Thank you so much Clyde for your quick reply and giving clarity on the issue. Unfortunately, I don't have Stata 16. To continue in Stata 15, if I want to use the quadratic term for time, is my below code then correct?
                  Code:
                   
                   mixed c.Z_HOMA c.stxLept_MSD_T##c.time##c.time c.Age i.sex i.Country c.Z_SBP c.AVM_1_week_T c.Z_TRG i.smoke_occcat i.alc_lifecat i.dm_fhT club_mbr_T c.Z_Waist_To_Height c.stxAdip_MSD_T  c.stxLept_MSD_T c.stxTNF_a_MSD_T c.stxIP_10_MSD_T c.stxIL_8_MSD_T c.stxIL_15_MSD_T c.stxIL_1Ra_MSD_T c.stxIL_6_MSD_T c.stxCRP_MSD_T || ID_cohort: time##time, cov(unstr) iterate(100)
                  Thank you again for your time.

                  Best Regards

                  Comment

                  Working...
                  X