Announcement

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

  • mixed vs. xtreg, re

    Here are four ways to estimate the same model (I think):
    Code:
    xtreg absent ib(2).classtype ib("k").gradenum i.schid, re xtreg absent ib(2).classtype ib("k").gradenum i.schid, re mle mixed absent ib(2).classtype ib("k").gradenum i.schid || stdntid: mixed absent ib(2).classtype ib("k").gradenum i.schid || _all: R.stdntid
    Version 1 runs in 2 seconds. Version 2 runs in 10 seconds. Version 3 takes 50 seconds to return the same result as version 2. Version 4 just spins without returning a result.

    What accounts for these differences? I'm especially confused about why version 3 takes so much longer than version 2, and why version 4 doesn't finish when version 3 does.

  • #2
    -mixed- is a more general command than -xtreg, re- and the code is set up to work with multiple levels, and cross-level interactions. Consequently, it takes a longer time to compute the likelihood function on each iteration because it has to go through many branches of the code.

    As for the last one, when you use the _all: R.stdntid, the variable stdntid is handled in a different way that results in creating a very large matrix that must then be manipulated in the calculations. I vaguely recall that with the _all: R.stdntid, the computation time is exponentially dependent on the number of different values of stdntid, which is not the case for plain old stdntid:. That's why in the explanation in the manual of crossed-effects, where you have to set up a construction like _all: R.var1 || var2: to pick as var1 the variable with the fewest number of distinct values.

    By the way, I'm guessing that if you were patient enough, the fourth method would eventually give you results. But it could take many hours, or even days if your data set is large.

    Comment


    • #3
      I've always found -mixed- to be a slow command. It takes a long time to fit simple models that HLM, for example, fits very quickly.

      Comment


      • #4
        Another difference is that they often use different numbers of integration points and methods. If I recall, the default number of integration points for melogit is 7 and the number for xtlogit, re is 12. Also, crossed-effects often use the Laplace method where others use the gauss-hermite variations.

        But you’re right. I estimated a model using xtreg, re that worked in a few minutes but mixed would not converge.

        Comment


        • #5
          I am not an expert on -mixed-, I think I used it no more than three times in my life. Once to fit a two way random effects model, which -xtreg, re- cannot. But the general principle is that

          1) If an estimator is closed form matrix formula, it will be a lot faster than numerical optimisation of a likelihood function. E.g., one can fit multivariate regression both by -mvreg- and -sem-
          Code:
          . sysuse auto, clear
          (1978 Automobile Data)
          
          . timer clear
          
          . timeit 1: mvreg price mpg = headroom trunk weight, noheader
          
          ------------------------------------------------------------------------------
                       |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          price        |
              headroom |  -726.8171   460.0698    -1.58   0.119    -1644.397    190.7632
                 trunk |   28.34831   107.5862     0.26   0.793    -186.2256    242.9222
                weight |   2.321676    .506973     4.58   0.000      1.31055    3.332802
                 _cons |   940.6103   1292.159     0.73   0.469    -1636.519     3517.74
          -------------+----------------------------------------------------------------
          mpg          |
              headroom |   .0049958   .6427576     0.01   0.994    -1.276944    1.286935
                 trunk |  -.0968366   .1503073    -0.64   0.522     -.396615    .2029419
                weight |  -.0056531   .0007083    -7.98   0.000    -.0070657   -.0042404
                 _cons |   39.68369   1.805258    21.98   0.000     36.08321    43.28416
          ------------------------------------------------------------------------------
          
          . timeit 2: sem (price mpg <- headroom trunk weight), nolog
          
          Endogenous variables
          
          Observed:  price mpg
          
          Exogenous variables
          
          Observed:  headroom trunk weight
          
          Structural equation model                       Number of obs     =         74
          Estimation method  = ml
          Log likelihood     = -1734.0399
          
          ------------------------------------------------------------------------------
                       |                 OIM
                       |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          Structural   |
            price      |
              headroom |  -726.8171   447.4627    -1.62   0.104    -1603.828    150.1938
                 trunk |   28.34831   104.6381     0.27   0.786    -176.7386    233.4352
                weight |   2.321676   .4930807     4.71   0.000     1.355255    3.288096
                 _cons |   940.6103    1256.75     0.75   0.454    -1522.575    3403.796
            -----------+----------------------------------------------------------------
            mpg        |
              headroom |   .0049958   .6251444     0.01   0.994    -1.220265    1.230256
                 trunk |  -.0968366   .1461885    -0.66   0.508    -.3833608    .1896877
                weight |  -.0056531   .0006889    -8.21   0.000    -.0070032   -.0043029
                 _cons |   39.68369    1.75579    22.60   0.000      36.2424    43.12497
          -------------+----------------------------------------------------------------
           var(e.price)|    5848147   961429.4                       4237226     8071513
             var(e.mpg)|   11.41472   1.876568                      8.270439     15.7544
          ------------------------------------------------------------------------------
          Note: The LR test of model vs. saturated is not reported because the fitted
                model is not full rank.
          
          . timer list
             1:      0.03 /        1 =       0.0300
             2:      0.08 /        1 =       0.0760

          2) What Clyde said, if code goes from general to specific, even if both methods are numerical optimisation of a likelihood function, the more general model might be maximising more complicated likelihood and not using simplification which occur in particular cases. E.g., in linear multivariate regression it is known that the OLS estimator coincides with the ML estimator, but -sem- does not use this fact, and goes the general way of optimising the general likelihood.

          In general whenever possible one should use the simple model.

          Comment


          • #6
            However, I think there are faster ways to do what mixed does. Because HLM, for example, fits the same models much faster.

            Comment


            • #7
              Are there faster routines in other for mixed models? Certainly. Mplus and SAS come to mind. I don’t know the exact reason why they are faster (likely a mix of more efficient algorithms with compiled rather than interpreted code).

              I would really like to see mixed run faster for simple hierarchical models, if possible.

              Comment

              Working...
              X