Announcement

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

  • Predicting random effects from meqrlogit

    Dear statalist,

    I want to predict the random effects for practice and patient from a null model, mixed effects logistic regression model using meqrlogit. I have 16,745 patients with data over 14, 2-month timeperiods (over 2 years), who are registered within 179 practices. I want to estimate predicted 1)practice level random effects 2)patient level random effects. I am getting results for some but not as many as i thought I would or need to be able to subsequently apply the estimated random effects into another model.

    Would there be any alternative options for predicting random effects or something that I have missed?

    Any help greatly appreciated.
    Bryony

    meqrlogit anticholinergics ||pracid: ||patid :

    Refining starting values:

    Iteration 0: log likelihood = -43219.872 (not concave)
    Iteration 1: log likelihood = -34783.372 (not concave)
    Iteration 2: log likelihood = -30222.608

    Performing gradient-based optimization:

    Iteration 0: log likelihood = -30222.608 (not concave)
    Iteration 1: log likelihood = -29495.26
    Iteration 2: log likelihood = -29236.162
    Iteration 3: log likelihood = -29209.8
    Iteration 4: log likelihood = -29208.463
    Iteration 5: log likelihood = -29208.457
    Iteration 6: log likelihood = -29208.457

    Mixed-effects logistic regression Number of obs = 151,802

    ----------------------------------------------------------------------------
    | No. of Observations per Group Integration
    Group Variable | Groups Minimum Average Maximum Points
    ----------------+-----------------------------------------------------------
    pracid | 282 9 538.3 2,357 7
    patid | 22,845 1 6.6 14 7
    ----------------------------------------------------------------------------

    Wald chi2(0) = .
    Log likelihood = -29208.457 Prob > chi2 = .

    ------------------------------------------------------------------------------
    anticholi~cs | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    _cons | -6.402485 .1315756 -48.66 0.000 -6.660368 -6.144601
    ------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    pracid: Identity |
    var(_cons) | 2.455507 .2387268 2.029488 2.970953
    -----------------------------+------------------------------------------------
    patid: Identity |
    var(_cons) | 31.90439 .7205204 30.52299 33.3483
    ------------------------------------------------------------------------------
    LR test vs. logistic model: chi2(2) = 75220.01 Prob > chi2 = 0.0000

    Note: LR test is conservative and provided only for reference.

    predict b* , reffects relevel(patid)
    (151,630 missing values generated)

    . predict c* , reffects relevel(pracid)
    (151,630 missing values generated)

    tab c1

    random |
    effects for |
    pracid: |
    _cons | Freq. Percent Cum.
    ------------+-----------------------------------
    -4.657479 | 32 18.60 18.60
    -1.281644 | 22 12.79 31.40
    -.083283 | 28 16.28 47.67
    -.0335804 | 9 5.23 52.91
    .6104849 | 27 15.70 68.60
    .8109205 | 19 11.05 79.65
    1.666388 | 15 8.72 88.37
    1.990422 | 20 11.63 100.00
    ------------+-----------------------------------
    Total | 172 100.00

    . tab b1

    random |
    effects for |
    patid: |
    _cons | Freq. Percent Cum.
    ------------+-----------------------------------
    -95.71317 | 4 2.33 2.33
    -31.90439 | 4 2.33 4.65
    -.2211843 | 6 3.49 8.14
    -.2210106 | 6 3.49 11.63
    -.2208492 | 6 3.49 15.12
    -.1600022 | 4 2.33 17.44
    -.1254416 | 3 1.74 19.19
    -.0876188 | 2 1.16 20.35
    -.0484864 | 1 0.58 20.93
    -.0484824 | 1 0.58 21.51
    -.0484799 | 1 0.58 22.09
    -.0484788 | 1 0.58 22.67
    -.0484786 | 1 0.58 23.26
    -.048477 | 1 0.58 23.84
    -.0484761 | 1 0.58 24.42
    -.0484758 | 1 0.58 25.00
    -.0484755 | 1 0.58 25.58
    -.0459889 | 1 0.58 26.16
    6.50e-12 | 2 1.16 27.33
    6.51e-12 | 1 0.58 27.91
    6.73e-12 | 1 0.58 28.49
    6.74e-12 | 1 0.58 29.07
    7.19e-11 | 1 0.58 29.65
    7.24e-11 | 1 0.58 30.23
    7.34e-11 | 1 0.58 30.81
    7.36e-11 | 1 0.58 31.40
    1.008931 | 1 0.58 31.98
    1.009315 | 1 0.58 32.56
    1.469205 | 2 1.16 33.72
    1.469297 | 2 1.16 34.88
    1.469654 | 2 1.16 36.05
    1.469823 | 2 1.16 37.21
    1.469865 | 2 1.16 38.37
    1.470861 | 2 1.16 39.53
    1.471454 | 2 1.16 40.70
    1.471791 | 2 1.16 41.86
    1.471795 | 2 1.16 43.02
    1.520135 | 1 0.58 43.60
    1.520228 | 1 0.58 44.19
    1.520525 | 1 0.58 44.77
    1.520648 | 1 0.58 45.35
    1.520754 | 1 0.58 45.93
    1.520766 | 1 0.58 46.51
    1.52077 | 1 0.58 47.09
    1.521079 | 1 0.58 47.67
    1.521096 | 1 0.58 48.26
    1.521131 | 1 0.58 48.84
    1.521356 | 1 0.58 49.42
    1.521464 | 1 0.58 50.00
    1.521658 | 1 0.58 50.58
    1.522201 | 1 0.58 51.16
    1.522376 | 1 0.58 51.74
    1.52243 | 1 0.58 52.33
    1.522927 | 1 0.58 52.91
    1.663045 | 1 0.58 53.49
    1.664052 | 1 0.58 54.07
    1.664883 | 1 0.58 54.65
    1.665078 | 1 0.58 55.23
    1.665428 | 1 0.58 55.81
    1.665572 | 1 0.58 56.40
    1.66567 | 1 0.58 56.98
    1.665809 | 1 0.58 57.56
    1.666155 | 1 0.58 58.14
    1.666157 | 1 0.58 58.72
    1.666335 | 1 0.58 59.30
    1.66656 | 1 0.58 59.88
    1.666619 | 1 0.58 60.47
    2.24909 | 1 0.58 61.05
    2.252264 | 1 0.58 61.63
    2.25259 | 1 0.58 62.21
    2.375746 | 1 0.58 62.79
    2.600591 | 2 1.16 63.95
    2.716698 | 1 0.58 64.53
    2.716992 | 1 0.58 65.12
    2.71707 | 1 0.58 65.70
    2.717136 | 1 0.58 66.28
    2.718162 | 1 0.58 66.86
    2.767637 | 6 3.49 70.35
    2.792311 | 8 4.65 75.00
    2.91461 | 2 1.16 76.16
    2.91467 | 2 1.16 77.33
    2.914684 | 2 1.16 78.49
    2.915477 | 2 1.16 79.65
    2.915803 | 2 1.16 80.81
    2.917854 | 2 1.16 81.98
    2.918871 | 2 1.16 83.14
    2.918957 | 2 1.16 84.30
    2.919433 | 2 1.16 85.47
    3.284325 | 2 1.16 86.63
    3.881068 | 3 1.74 88.37
    4.249933 | 4 2.33 90.70
    4.253342 | 4 2.33 93.02
    4.253466 | 4 2.33 95.35
    4.256565 | 4 2.33 97.67
    4.265924 | 4 2.33 100.00
    ------------+-----------------------------------
    Total | 172 100.00





  • #2
    This would be easier to read if you made the columns line up. The question is whether you get the same number of group effects as your estimation.

    Comment


    • #3
      Bryony, as we advise in the FAQ, posting both commands and output in the code delimiters (see my signature for more details) makes them more easily readable. Had you done this, it would be even clearer than me copying your text and putting it within code delimiters (everything would line up):

      Code:
      meqrlogit anticholinergics ||pracid: ||patid :
      
      Refining starting values: 
      
      Iteration 0: log likelihood = -43219.872 (not concave)
      Iteration 1: log likelihood = -34783.372 (not concave)
      Iteration 2: log likelihood = -30222.608  
      
      Performing gradient-based optimization: 
      
      Iteration 0: log likelihood = -30222.608 (not concave)
      Iteration 1: log likelihood = -29495.26  
      Iteration 2: log likelihood = -29236.162  
      Iteration 3: log likelihood = -29209.8  
      Iteration 4: log likelihood = -29208.463  
      Iteration 5: log likelihood = -29208.457  
      Iteration 6: log likelihood = -29208.457  
      
      Mixed-effects logistic regression Number of obs = 151,802
      
      ----------------------------------------------------------------------------
      | No. of Observations per Group Integration
      Group Variable | Groups Minimum Average Maximum Points
      ----------------+-----------------------------------------------------------
      pracid | 282 9 538.3 2,357 7
      patid | 22,845 1 6.6 14 7
      ----------------------------------------------------------------------------
      
      Wald chi2(0) = .
      Log likelihood = -29208.457 Prob > chi2 = .
      
      ------------------------------------------------------------------------------
      anticholi~cs | Coef. Std. Err. z P>|z| [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      _cons | -6.402485 .1315756 -48.66 0.000 -6.660368 -6.144601
      ------------------------------------------------------------------------------
      
      ------------------------------------------------------------------------------
      Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
      -----------------------------+------------------------------------------------
      pracid: Identity |
      var(_cons) | 2.455507 .2387268 2.029488 2.970953
      -----------------------------+------------------------------------------------
      patid: Identity |
      var(_cons) | 31.90439 .7205204 30.52299 33.3483
      ------------------------------------------------------------------------------
      LR test vs. logistic model: chi2(2) = 75220.01 Prob > chi2 = 0.0000
      
      Note: LR test is conservative and provided only for reference.
      
      predict b* , reffects relevel(patid)
      (151,630 missing values generated)
      
      . predict c* , reffects relevel(pracid)
      (151,630 missing values generated)
      
      tab c1
      
      random |
      effects for |
      pracid: |
      _cons | Freq. Percent Cum.
      ------------+-----------------------------------
      -4.657479 | 32 18.60 18.60
      -1.281644 | 22 12.79 31.40
      -.083283 | 28 16.28 47.67
      -.0335804 | 9 5.23 52.91
      .6104849 | 27 15.70 68.60
      .8109205 | 19 11.05 79.65
      1.666388 | 15 8.72 88.37
      1.990422 | 20 11.63 100.00
      ------------+-----------------------------------
      Total | 172 100.00
      
      . tab b1
      
      random |
      effects for |
      patid: |
      _cons | Freq. Percent Cum.
      ------------+-----------------------------------
      -95.71317 | 4 2.33 2.33
      -31.90439 | 4 2.33 4.65
      -.2211843 | 6 3.49 8.14
      -.2210106 | 6 3.49 11.63
      -.2208492 | 6 3.49 15.12
      -.1600022 | 4 2.33 17.44
      -.1254416 | 3 1.74 19.19
      -.0876188 | 2 1.16 20.35
      -.0484864 | 1 0.58 20.93
      -.0484824 | 1 0.58 21.51
      -.0484799 | 1 0.58 22.09
      -.0484788 | 1 0.58 22.67
      -.0484786 | 1 0.58 23.26
      -.048477 | 1 0.58 23.84
      -.0484761 | 1 0.58 24.42
      -.0484758 | 1 0.58 25.00
      -.0484755 | 1 0.58 25.58
      -.0459889 | 1 0.58 26.16
      6.50e-12 | 2 1.16 27.33
      6.51e-12 | 1 0.58 27.91
      6.73e-12 | 1 0.58 28.49
      6.74e-12 | 1 0.58 29.07
      7.19e-11 | 1 0.58 29.65
      7.24e-11 | 1 0.58 30.23
      7.34e-11 | 1 0.58 30.81
      7.36e-11 | 1 0.58 31.40
      1.008931 | 1 0.58 31.98
      1.009315 | 1 0.58 32.56
      1.469205 | 2 1.16 33.72
      1.469297 | 2 1.16 34.88
      1.469654 | 2 1.16 36.05
      1.469823 | 2 1.16 37.21
      1.469865 | 2 1.16 38.37
      1.470861 | 2 1.16 39.53
      1.471454 | 2 1.16 40.70
      1.471791 | 2 1.16 41.86
      1.471795 | 2 1.16 43.02
      1.520135 | 1 0.58 43.60
      1.520228 | 1 0.58 44.19
      1.520525 | 1 0.58 44.77
      1.520648 | 1 0.58 45.35
      1.520754 | 1 0.58 45.93
      1.520766 | 1 0.58 46.51
      1.52077 | 1 0.58 47.09
      1.521079 | 1 0.58 47.67
      1.521096 | 1 0.58 48.26
      1.521131 | 1 0.58 48.84
      1.521356 | 1 0.58 49.42
      1.521464 | 1 0.58 50.00
      1.521658 | 1 0.58 50.58
      1.522201 | 1 0.58 51.16
      1.522376 | 1 0.58 51.74
      1.52243 | 1 0.58 52.33
      1.522927 | 1 0.58 52.91
      1.663045 | 1 0.58 53.49
      1.664052 | 1 0.58 54.07
      1.664883 | 1 0.58 54.65
      1.665078 | 1 0.58 55.23
      1.665428 | 1 0.58 55.81
      1.665572 | 1 0.58 56.40
      1.66567 | 1 0.58 56.98
      1.665809 | 1 0.58 57.56
      1.666155 | 1 0.58 58.14
      1.666157 | 1 0.58 58.72
      1.666335 | 1 0.58 59.30
      1.66656 | 1 0.58 59.88
      1.666619 | 1 0.58 60.47
      2.24909 | 1 0.58 61.05
      2.252264 | 1 0.58 61.63
      2.25259 | 1 0.58 62.21
      2.375746 | 1 0.58 62.79
      2.600591 | 2 1.16 63.95
      2.716698 | 1 0.58 64.53
      2.716992 | 1 0.58 65.12
      2.71707 | 1 0.58 65.70
      2.717136 | 1 0.58 66.28
      2.718162 | 1 0.58 66.86
      2.767637 | 6 3.49 70.35
      2.792311 | 8 4.65 75.00
      2.91461 | 2 1.16 76.16
      2.91467 | 2 1.16 77.33
      2.914684 | 2 1.16 78.49
      2.915477 | 2 1.16 79.65
      2.915803 | 2 1.16 80.81
      2.917854 | 2 1.16 81.98
      2.918871 | 2 1.16 83.14
      2.918957 | 2 1.16 84.30
      2.919433 | 2 1.16 85.47
      3.284325 | 2 1.16 86.63
      3.881068 | 3 1.74 88.37
      4.249933 | 4 2.33 90.70
      4.253342 | 4 2.33 93.02
      4.253466 | 4 2.33 95.35
      4.256565 | 4 2.33 97.67
      4.265924 | 4 2.33 100.00
      ------------+-----------------------------------
      Total | 172 100.00
      That said, it looks like you only predicted effects for 172 observations (that is, patient-bimonths). Your regression did look like it used 22,845 patients in 282 practices. Looks like you had an average of 6.6 observations per patient. These numbers don't quite line up with what you described in the post. When you go into your data, do you see anything obvious, like missing data?
      Please use the code delimiters to show code and results - use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Please use the command -dataex- to show a representative sample of data; it is installed already if you have Stata 14.2 or 15.1, else you can install it by typing

      Code:
      ssc install dataex

      Comment


      • #4
        Thank you both for your comment. My apologises for the incorrect formatting and thank you for the advice. I cannot see any missing data from those three variables. Would the data being unbalanced affect this? Patients time within the study is varied?

        Comment


        • #5
          I ran some test code on a Stata dataset that has some minor imbalance. That by itself doesn't cause missing predicted random effects. Code after the post.

          Looking again at your output, the variance of the patient-level random intercept is immense, at 31.9. In the log-odds scale, that is enormous - inverse logit 15 gets you nearly 1, inverse logit -15 gets you nearly 0. Basically, I wonder if some patients are getting basically all the anticholinergics - basically, this is like the traditional separation problem in logistic regression, only applied to your random effects. (See things to consider at the end of this UCLA note.) Could this be the case? How many patients are using anticholinergic medications?

          The aforementioned code, drawn from example 14 in the -mixed- manual entry:

          Code:
          use http://www.stata-press.com/data/r15/veneer, clear
          table patient tooth
          ----------------------------------------------
          Patient   |     Tooth number with patient     
          ID        |    6     7     8     9    10    11
          ----------+-----------------------------------
                  1 |    2     2     2     2     2     2
                  3 |    2     2     2     2     2     2
                  4 |    2     2     2     2     2     2
                  5 |          2     2     2     2      
                  6 |    2     2     2     2     2     2
                  7 |    2     2     2     2     2     2
                  8 |    2     2     2     2     2     2
                  9 |    2     2                        
                 10 |    2     2     2     2     2     2
                 12 |          2     2     2     2      
                 13 |                            2      
                 14 |                2           2      
          ----------------------------------------------
          
          mixed gcf followup base_gcf cda age || patient: followup || tooth:, reml
          predict pat*, reffects relevel(patient)
          predict tooth*, reffects relevel(tooth)
          Basically, if the problem were simple imbalance, patients 5, 9, and 12-14 should all have missing random effects.
          Please use the code delimiters to show code and results - use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

          Please use the command -dataex- to show a representative sample of data; it is installed already if you have Stata 14.2 or 15.1, else you can install it by typing

          Code:
          ssc install dataex

          Comment


          • #6
            Thank you Weiwen for your helpful comment. My issue was indeed that the individual patients use of an anticholinergic was a near perfect prediction of their use of anticholinergics... What i am rather more interested in is the change in a prescription over time (and in other regressions with other factors included). This has provided much more sensible results and the predictions have worked without missing data as I had hoped. Many thanks

            Comment

            Working...
            X