Announcement

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

  • predicting a linear slope, an intercept, and a quadratic slope after a linear mixed model

    Hello All,

    I am estimating a linear slope, a quadratic slope and an intercept of one specific variable. I want to predict these variables because I want to use them as independent variables in another analysis.
    Below is my code for the mixed model. In this code fit is my outcome, cycle is the linear slope, cycle2 is the quadratic slope, and my intercept is a random intercept by ID.

    Code:
    mixed fit cycle cycle2 ///
    > || ID: cycle, covariance(uns) variance
    
    Performing EM optimization: 
    
    Performing gradient-based optimization: 
    
    Iteration 0:   log likelihood = -14436.131  
    Iteration 1:   log likelihood = -14436.131  
    
    Computing standard errors:
    
    Mixed-effects ML regression                     Number of obs     =      9,056
    Group variable: ID                              Number of groups  =        935
    
                                                    Obs per group:
                                                                  min =          1
                                                                  avg =        9.7
                                                                  max =         15
    
                                                    Wald chi2(2)      =     103.19
    Log likelihood = -14436.131                     Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
             fit |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           cycle |  -.1170634   .0120247    -9.74   0.000    -.1406314   -.0934953
          cycle2 |   .0054118   .0007144     7.58   0.000     .0040116    .0068119
           _cons |   5.792452   .0551227   105.08   0.000     5.684413     5.90049
    ------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    ID: Unstructured             |
                      var(cycle) |   .0134116    .001063      .0114819    .0156657
                      var(_cons) |   1.373924   .0900777      1.208248    1.562318
                cov(cycle,_cons) |  -.0655636   .0080507     -.0813426   -.0497845
    -----------------------------+------------------------------------------------
                   var(Residual) |   1.016058    .016739      .9837744    1.049402
    ------------------------------------------------------------------------------
    LR test vs. linear model: chi2(3) = 4571.58               Prob > chi2 = 0.0000
    
    Note: LR test is conservative and provided only for reference.
    I tried the below code to predict the linear slope, the quadratic slope, and the intercept. But I get an error message (see below).

    Code:
     predict fit1_slope fit_slope2 fit_int1, reffects
    too many variables specified
    you must specify 2 new variable(s)
    r(103);
    
    end of do-file
    
    r(103);
    Since predict refffects is limited to two variables, how can I predict everything I need? Did I misunderstand anything?

    Best wishes and thank you for your time.
    Patrick

  • #2
    With regard to getting the predictions you want, -predict, reffects- is not restricted, in general, two two terms. Rather, you have asked -predict- to do something that is not possible: predict observation level values for cov(cycle _cons). There is no such individual level effect: the covariance is a sample-level description of the association between the intercept and the slope of cycle and it has no individual-level manifestations. Stata simply did the favor of telling you that, in your particular estimates, there are 2 predictable effects. If you use a model with more random effects, Stata will be happy to -predict- them all, but it will never -predict- a covariance between them.

    That said, I don't like your model in the first place. Having a random slope for cycle, but not for cycle squared imposes a very bizarre constraint on your model that is unlikely to have any scientific justification. I would do this as:

    Code:
    mixed fit cycle cycle2  || ID: cycle cycle2, covariance(uns)
    Also note that in current versions of Stata, it is unnecessary to specify that -variance- option, as you get that by default.

    Comment


    • #3
      Hello Clyde,

      Thank you very much for your helpful and quick feedback. Based on your feedback I adjusted my code to the below but I had two remaining questions.

      1) Do I have to list my variables in predict in a specific order? How do I know for sure that Stata, predicted cycle2 for fit_slope2?
      2) I had not realized that cycle2 needed to be also included as a random effect. Now that I think about it makes a lot more sense. I can't just use the fixed effect and say that I included it as a random effect. Thank you for catching this. Do you have any recommendations for resources that I might be able to read on this? It has been challenging to find online resources that explain why and what we should do in certain types of analysis (specifically longitudinal analysis), and how to apply these in Stata.

      Code:
      mixed fit cycle cycle2 ///
      > || ID: cycle cycle2, covariance(uns) variance
      
      Performing EM optimization: 
      
      Performing gradient-based optimization: 
      
      Iteration 0:   log likelihood = -14344.794  
      Iteration 1:   log likelihood = -14325.313  
      Iteration 2:   log likelihood = -14304.234  
      Iteration 3:   log likelihood = -14295.435  
      Iteration 4:   log likelihood = -14295.261  
      Iteration 5:   log likelihood = -14295.261  
      
      Computing standard errors:
      
      Mixed-effects ML regression                     Number of obs     =      9,056
      Group variable: ID                              Number of groups  =        935
      
                                                      Obs per group:
                                                                    min =          1
                                                                    avg =        9.7
                                                                    max =         15
      
                                                      Wald chi2(2)      =      69.89
      Log likelihood = -14295.261                     Prob > chi2       =     0.0000
      
      ------------------------------------------------------------------------------
               fit |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
             cycle |    -.11662   .0161174    -7.24   0.000    -.1482095   -.0850306
            cycle2 |     .00543   .0009773     5.56   0.000     .0035146    .0073454
             _cons |   5.792282   .0562097   103.05   0.000     5.682113    5.902451
      ------------------------------------------------------------------------------
      
      ------------------------------------------------------------------------------
        Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
      -----------------------------+------------------------------------------------
      ID: Unstructured             |
                        var(cycle) |   .1098868   .0106865      .0908167    .1329613
                       var(cycle2) |   .0003621   .0000385       .000294     .000446
                        var(_cons) |   1.490072   .1282373      1.258786    1.763854
                 cov(cycle,cycle2) |   -.005921    .000627     -.0071498   -.0046921
                  cov(cycle,_cons) |   -.219294   .0324397     -.2828748   -.1557133
                 cov(cycle2,_cons) |   .0089131   .0018477      .0052916    .0125346
      -----------------------------+------------------------------------------------
                     var(Residual) |   .9248033   .0159376      .8940879    .9565739
      ------------------------------------------------------------------------------
      LR test vs. linear model: chi2(6) = 4853.32               Prob > chi2 = 0.0000
      
      Note: LR test is conservative and provided only for reference.
      
      . 
      end of do-file
      
      . do "/var/folders/jm/09q0bdrn4rx0_z64txpj22gm0000gn/T//SD01246.000000"
      
      . predict fit1_slope fit_slope2 fit_int1, reffects
      (3 missing values generated)
      (3 missing values generated)
      (3 missing values generated)
      Best wishes,
      Patrick

      Comment


      • #4
        Although I can't find a guarantee of this in the documentation, I believe that Stata will take the variables in your -predict- command from left to right, and assign them to the random effects in the -mixed- output from top to bottom.

        In any case, if you -describe- the predicted random effects, you will see they have labels that tell you exactly which random effect they correspond to.

        Comment

        Working...
        X