Announcement

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

  • lrtest claims differing df when comparing identical models

    Hi,

    Today I came across something strange and I can't figure out a way to fix it, so I hope someone where can help.

    I've been comparing a number of mixed models using lrtest. My syntax has worked for weeks, but after I made some updates with my sample Stata started refusing to perform the lrtest sending the following error message: "df(unrestricted) = df(restricted) = 27 r(498);"

    At first I thought I had made some mistake while adding some new variables, or that my samples in some models might differ from others, but all models include the same number of groups and observations, and the error persists even when I try to compare the exact same model where there really shouldn't be any differences in df.


    SYNTAX:

    mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1 w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl exercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1
    est store mm8

    mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1 w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl exercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1
    est store mm9

    lrtest mm8 mm9, stats



    OUTPUT:

    mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1
    > w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl ex
    > ercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1

    Mixed-effects ML regression Number of obs = 7,896
    Group variable: idauniq Number of groups = 3,948

    Obs per group:
    min = 2
    avg = 2.0
    max = 2

    Wald chi2(23) = 1173.60
    Log likelihood = -19000.72 Prob > chi2 = 0.0000

    ------------------------------------------------------------------------------
    memory | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    omitted
    ------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    idauniq: Unstructured |
    var(time) | .1471689 . . .
    var(_cons) | 10.77624 .8145419 9.292392 12.49703
    cov(time,_cons) | -1.017548 . . .
    -----------------------------+------------------------------------------------
    var(Residual) | 4.163565 .100336 3.971482 4.364938
    ------------------------------------------------------------------------------
    LR test vs. linear model: chi2(3) = 877.44 Prob > chi2 = 0.0000

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

    . est store mm8

    mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1
    > w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl ex
    > ercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1

    Mixed-effects ML regression Number of obs = 7,896
    Group variable: idauniq Number of groups = 3,948

    Obs per group:
    min = 2
    avg = 2.0
    max = 2

    Wald chi2(23) = 1173.60
    Log likelihood = -19000.72 Prob > chi2 = 0.0000

    ------------------------------------------------------------------------------
    memory | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    omitted
    ------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    idauniq: Unstructured |
    var(time) | .1471689 . . .
    var(_cons) | 10.77624 .8145419 9.292392 12.49703
    cov(time,_cons) | -1.017548 . . .
    -----------------------------+------------------------------------------------
    var(Residual) | 4.163565 .100336 3.971482 4.364938
    ------------------------------------------------------------------------------
    LR test vs. linear model: chi2(3) = 877.44 Prob > chi2 = 0.0000

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

    . est store mm9

    . lrtest mm8 mm9, stats
    df(unrestricted) = df(restricted) = 27
    r(498);

    .
    end of do-file




    Thank you!
    Last edited by Josephine Bob; 03 Jul 2019, 10:47.

  • #2
    Josephine, Welcome to Statalist.

    Take a look at the Statalist FAQ, especially pt 12. Using code tags will make your output easier to read. As it stands, two or more consecutive spaces get reduced to one so your columns are not lining up correctly.

    I don't understand the question. The subject says "lrtest claims differing df when comparing identical models". But, in your example, it says the DF do NOT differ for identical models, which is what it should say. So, I don't understand what the problem is. Maybe you just gave a bad example, or maybe I am missing something.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 18.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      @Josephine Bob The reason you get that error I believe is because you stored the same model twice under different names– mm8 and mm9. Try changing your covars == 1 in the second model to covars == 2 or any other number. Or try adding or removing one variable in the second model if you want to stick to covars==1.

      mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1 w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl exercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1
      est store mm8

      mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1 w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl exercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1
      est store mm9


      Try: for the second model:
      mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1 w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl depressl exercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==2
      est store mm9

      OR

      mixed memory bbmi ageincl4 sex4 edu2 edu3 weal2 weal3 limitil4 hepsyde4 w4pacomb1 w4alco1 time bmisl ageincl4sl sexsl medusl hedusl measl heasl illnessl exercisesl alcoholsl|| id:time, cov(unstr) var nolog || if covars ==1 // here variable "depress" has been removed
      est store mm9

      Comment

      Working...
      X