Announcement

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

  • mixed model not concave

    Hi Statalists,

    I was trying to run a mixed model with Stata 15, however failed to do so with "not concave" error message.

    The codes were simple:
    Code:
    mixed var1 var2 || id: var2
    My total sample size is 700+, with 30 ids having repeated measures. I wonder if repeated observations (n=30+) nested within each id are insufficient sample size?

    Thanks for any help in advance!
    Yingyi

  • #2
    Originally posted by Yingyi Lin View Post
    I wonder if repeated observations (n=30+) nested within each id are insufficient sample size?
    It seems that 30 ids each with 30 repeated observations is sufficient sample size for convergence (see below).

    .ÿclearÿ*

    .ÿ
    .ÿsetÿseedÿ`=strreverse("1448922")'

    .ÿ
    .ÿquietlyÿdrawnormÿinterceptÿslope,ÿdoubleÿcorr(1ÿ-0.5ÿ\ÿ-0.5ÿ1)ÿn(30)

    .ÿgenerateÿbyteÿidÿ=ÿ_n

    .ÿ
    .ÿquietlyÿexpandÿ30

    .ÿ
    .ÿgenerateÿdoubleÿvar2ÿ=ÿruniform()ÿ-ÿ0.5

    .ÿgenerateÿdoubleÿvar1ÿ=ÿinterceptÿ+ÿvar2ÿ+ÿvar2ÿ*ÿslopeÿ+ÿrnormal()

    .ÿ
    .ÿmixedÿvar1ÿc.var2ÿ||ÿid:ÿvar2ÿ,ÿnolrtestÿnolog

    Mixed-effectsÿMLÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿÿÿ900
    Groupÿvariable:ÿidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿÿ30

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿÿÿ30
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿÿÿ30.0
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿÿÿ30

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(1)ÿÿÿÿÿÿ=ÿÿÿÿÿÿ13.91
    Logÿlikelihoodÿ=ÿ-1325.8725ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.0002

    ------------------------------------------------------------------------------
    ÿÿÿÿÿÿÿÿvar1ÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
    -------------+----------------------------------------------------------------
    ÿÿÿÿÿÿÿÿvar2ÿ|ÿÿÿ.6816853ÿÿÿ.1827821ÿÿÿÿÿ3.73ÿÿÿ0.000ÿÿÿÿÿ.3234389ÿÿÿÿ1.039932
    ÿÿÿÿÿÿÿ_consÿ|ÿÿÿ.1533372ÿÿÿ.1637727ÿÿÿÿÿ0.94ÿÿÿ0.349ÿÿÿÿ-.1676513ÿÿÿÿ.4743257
    ------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    ÿÿRandom-effectsÿParametersÿÿ|ÿÿÿEstimateÿÿÿStd.ÿErr.ÿÿÿÿÿ[95%ÿConf.ÿInterval]
    -----------------------------+------------------------------------------------
    id:ÿIndependentÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(var2)ÿ|ÿÿÿ.5677303ÿÿÿ.2479673ÿÿÿÿÿÿ.2411921ÿÿÿÿ1.336352
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(_cons)ÿ|ÿÿÿ.7714017ÿÿÿ.2077733ÿÿÿÿÿÿ.4550023ÿÿÿÿ1.307819
    -----------------------------+------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(Residual)ÿ|ÿÿÿ.9737553ÿÿÿ.0474503ÿÿÿÿÿÿ.8850576ÿÿÿÿ1.071342
    ------------------------------------------------------------------------------

    .ÿ
    .ÿdisplayÿinÿsmclÿasÿtextÿe(converged)
    1

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    But 30 × 30+ is closer to 900+ than to 700+.

    Comment


    • #3
      Stock advice in this case is to fit a simpler model, e.g. one with just a random intercept, then save the parameter estimates, then fit your random slopes model from the saved parameters as start values.

      Code:
      mixed var1 var2 || id:
      matrix b = e(b)
      mixed var1 var2 || id:, from(b)
      I am assuming your log likelihood gets to a point where it's not visibly increasing, but you are getting "not concave" errors. If Stata still won't converge, one thing you can do is to find the point where that happens, then tell Stata to run only that number of iterations, then you can inspect the parameters to see what, specifically, is wrong. For example, say you hit 20 iterations, then the LL hits its asymptote. You can type:

      Code:
      mixed var1 var2 || id:, iterate(20)
      Any parameter with a missing standard error is suspect. Of course, what to do about it can be less clear. If you can't get convergence after fitting the random intercept-only model, run the next bit of code and post the results in code delimiters, and we shall see if we can help.
      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
        Originally posted by Joseph Coveney View Post
        It seems that 30 ids each with 30 repeated observations is sufficient sample size for convergence (see below).

        .ÿclearÿ*

        .ÿ
        .ÿsetÿseedÿ`=strreverse("1448922")'

        .ÿ
        .ÿquietlyÿdrawnormÿinterceptÿslope,ÿdoubleÿcorr(1ÿ-0.5ÿ\ÿ-0.5ÿ1)ÿn(30)

        .ÿgenerateÿbyteÿidÿ=ÿ_n

        .ÿ
        .ÿquietlyÿexpandÿ30

        .ÿ
        .ÿgenerateÿdoubleÿvar2ÿ=ÿruniform()ÿ-ÿ0.5

        .ÿgenerateÿdoubleÿvar1ÿ=ÿinterceptÿ+ÿvar2ÿ+ÿvar2ÿ*ÿslopeÿ+ÿrnormal()

        .ÿ
        .ÿmixedÿvar1ÿc.var2ÿ||ÿid:ÿvar2ÿ,ÿnolrtestÿnolog

        Mixed-effectsÿMLÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿÿÿ900
        Groupÿvariable:ÿidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿÿ30

        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿÿÿ30
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿÿÿ30.0
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿÿÿ30

        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(1)ÿÿÿÿÿÿ=ÿÿÿÿÿÿ13.91
        Logÿlikelihoodÿ=ÿ-1325.8725ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.0002

        ------------------------------------------------------------------------------
        ÿÿÿÿÿÿÿÿvar1ÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
        -------------+----------------------------------------------------------------
        ÿÿÿÿÿÿÿÿvar2ÿ|ÿÿÿ.6816853ÿÿÿ.1827821ÿÿÿÿÿ3.73ÿÿÿ0.000ÿÿÿÿÿ.3234389ÿÿÿÿ1.039932
        ÿÿÿÿÿÿÿ_consÿ|ÿÿÿ.1533372ÿÿÿ.1637727ÿÿÿÿÿ0.94ÿÿÿ0.349ÿÿÿÿ-.1676513ÿÿÿÿ.4743257
        ------------------------------------------------------------------------------

        ------------------------------------------------------------------------------
        ÿÿRandom-effectsÿParametersÿÿ|ÿÿÿEstimateÿÿÿStd.ÿErr.ÿÿÿÿÿ[95%ÿConf.ÿInterval]
        -----------------------------+------------------------------------------------
        id:ÿIndependentÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(var2)ÿ|ÿÿÿ.5677303ÿÿÿ.2479673ÿÿÿÿÿÿ.2411921ÿÿÿÿ1.336352
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(_cons)ÿ|ÿÿÿ.7714017ÿÿÿ.2077733ÿÿÿÿÿÿ.4550023ÿÿÿÿ1.307819
        -----------------------------+------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvar(Residual)ÿ|ÿÿÿ.9737553ÿÿÿ.0474503ÿÿÿÿÿÿ.8850576ÿÿÿÿ1.071342
        ------------------------------------------------------------------------------

        .ÿ
        .ÿdisplayÿinÿsmclÿasÿtextÿe(converged)
        1

        .ÿ
        .ÿexit

        endÿofÿdo-file


        .


        But 30 × 30+ is closer to 900+ than to 700+.
        Hey Joseph, thanks for your reply. My total sample size is 700+ (level 1: study participants), and repeated measures (repeated twice) within only 30 participants (level 2). I wonder if 30 is too small here to successfully converge? Thanks.

        Comment


        • #5
          Hey Weiwen, thanks for your reply and I tried your simpler codes and they worked! Thanks again!

          Comment


          • #6
            Originally posted by Weiwen Ng View Post
            Stock advice in this case is to fit a simpler model, e.g. one with just a random intercept, then save the parameter estimates, then fit your random slopes model from the saved parameters as start values.

            Code:
            mixed var1 var2 || id:
            matrix b = e(b)
            mixed var1 var2 || id:, from(b)
            I am assuming your log likelihood gets to a point where it's not visibly increasing, but you are getting "not concave" errors. If Stata still won't converge, one thing you can do is to find the point where that happens, then tell Stata to run only that number of iterations, then you can inspect the parameters to see what, specifically, is wrong. For example, say you hit 20 iterations, then the LL hits its asymptote. You can type:

            Code:
            mixed var1 var2 || id:, iterate(20)
            Any parameter with a missing standard error is suspect. Of course, what to do about it can be less clear. If you can't get convergence after fitting the random intercept-only model, run the next bit of code and post the results in code delimiters, and we shall see if we can help.
            why when I use the from option of mixed, the Stata shows that option from() not allowed
            thanks

            Comment


            • #7
              Originally posted by Fred Lee View Post
              why when I use the from option of mixed, the Stata shows that option from() not allowed
              mixed doesn't allow from() for starting values. If you want to use that option to fit a hierarchical linear model, then you can use meglm.

              Comment

              Working...
              X