Skip to content

Inconsistent results for mixed linear models under Python 2.7 and 3.4  #3604

Open

Description

@sosata

statsmodels.mixedlm generates different results under Python 2.7 and Python 3.4. Moreover, in Python 3.4, the model does not converge when re_formula is used with variable slope.

Here is a simple example:

import statsmodels.formula.api as smf
import pandas as pd
import numpy as np
from copy import deepcopy

np.random.seed(seed=0)

data1 = pd.DataFrame(columns=['x','y','id'])
data2 = pd.DataFrame(columns=['x','y','id'])
data1['x'] = np.random.normal(size=100)
data1['y'] = deepcopy(data1['x'])*3 + np.random.normal(size=100)
data1['id'] = np.ones(100)
data2['x'] = np.random.normal(size=100)
data2['y'] = deepcopy(data2['x'])*2 + np.random.normal(size=100)
data2['id'] = np.ones(100)*2

data = pd.concat([data1,data2])
data = data.reset_index(drop=True)

md = smf.mixedlm('y ~ x', data, groups=data['id'], re_formula='~ x')
mdf = md.fit(method='cg')
print(mdf.summary())

Python 2.7 converges and generates the following results:

Mixed Linear Model Regression Results
==============================================================
Model:               MixedLM   Dependent Variable:   y        
No. Observations:    200       Method:               REML    
No. Groups:          2         Scale:                0.9636  
Min. group size:     100       Likelihood:           -286.7528
Max. group size:     100       Converged:            Yes      
Mean group size:     100.0                                    
--------------------------------------------------------------
                   Coef.  Std.Err.   z    P>|z| [0.025 0.975]
--------------------------------------------------------------
Intercept           -0.048    0.532 -0.091 0.928 -1.091  0.994
x                    2.631    1.673  1.572 0.116 -0.649  5.911
Intercept RE         0.558                                    
Intercept RE x x RE  1.660                                    
x RE                 5.597                                    
==============================================================

Python 3.4 does not converge and gives these results:

/usr/local/lib/python3.4/dist-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  "Check mle_retvals", ConvergenceWarning)
/usr/local/lib/python3.4/dist-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  "Check mle_retvals", ConvergenceWarning)
/usr/local/lib/python3.4/dist-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  "Check mle_retvals", ConvergenceWarning)
/usr/local/lib/python3.4/dist-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  "Check mle_retvals", ConvergenceWarning)
          Mixed Linear Model Regression Results
=========================================================
Model:              MixedLM Dependent Variable: y        
No. Observations:   200     Method:             REML     
No. Groups:         2       Scale:              0.9680   
Min. group size:    100     Likelihood:         -284.9909
Max. group size:    100     Converged:          No       
Mean group size:    100.0                                
---------------------------------------------------------
                    Coef.  Std.Err. z P>|z| [0.025 0.975]
---------------------------------------------------------
Intercept           -0.057                               
x                    2.620                               
Intercept RE         0.034                               
Intercept RE x x RE  0.129                               
x RE                 0.482                               
=========================================================

Which are pretty different for some of the parameters. Any ideas?

Activity

  1. kshedden commented on Apr 10, 2017

    @kshedden
    Contributor
  2. sosata commented on Apr 11, 2017

    @sosata
    Author

    I have actually tested this on a real human subject dataset with 206 groups, and the results were drastically different between Python 2.7 and 3.4.

    Plus, although I agree that this simulated dataset is unusual, it does not make sense that the same package under two different versions of Python gives different results.

  3. josef-pkt commented on Apr 11, 2017

    @josef-pkt
    Member

    What are your scipy versions in Python 2.7 and 3.4?

    Unless there is an integer division or similar bug, then the python version is irrelevant. However, if the optimization problems are not "nice", then small changes across scipy.optimize versions can affect optimization and convergence. In well behaved problems the optimizer shouldn't have much effect and should converge to the same values (subject to noise), but if the parameters are not well identified or at the boundary, then small numerical differences could have large effects.
    (That's just in general. I'm not familiar enough with optimization problems in MixedLM to say anything specific.)

  4. kshedden commented on Apr 11, 2017

    @kshedden
    Contributor
  5. sosata commented on Apr 11, 2017

    @sosata
    Author

    Thanks for your replies, Kerby and Josef.

    The versions are different. In Python 2.7, the statsmodels is 0.6.1 and scipy is 0.17.1. In Python 3.4, these are 0.8.0 and 0.19.0 respectively. I will try to upgrade the packages in Python 2.7 and see what happens.

  6. kshedden commented on Apr 11, 2017

    @kshedden
    Contributor
  7. sosata commented on Apr 11, 2017

    @sosata
    Author

    But it is actually the older version that converges. The 0.8.0 version is the one that doesn't converge.

  8. kshedden commented on Apr 11, 2017

    @kshedden
    Contributor
  9. sosata commented on Apr 11, 2017

    @sosata
    Author

    The model under statsmodels 0.6.1 gives the following gradients:

    [ -0.13671187   0.03623293  12.30095826   4.54274359  -1.02528382]
    

    and the model under statsmodels 0.8.0 gives these:

    [ 0.07870292 -0.03229172 -0.11194649]
    

    It seems none of these have converged. Although, I don't understand why one generates 5 gradients and the other 3.

  10. kshedden commented on Apr 11, 2017

    @kshedden
    Contributor
  11. sosata commented on Apr 11, 2017

    @sosata
    Author

    So you suggest that we use the results of 0.8.0 even though it says that it hasn't converged?

  12. josef-pkt commented on Apr 11, 2017

    @josef-pkt
    Member

    I was playing a bit with the example

    It looks to me that the covariance of the random effects is not well converged or well identified, but the local solution still looks good.

    The reported Hessian in the optimization is not positive definite, but the part of the hessian for the fixed effects parameters seems to be fine.

    AFAIK, the fixed effects parameters are still consistently estimated with "incorrect" random effects or misspecified residual correlation. So the fixed effects parameter are pretty close across different specification. However, the cov_params and standard errors differ quite a bit. So those will still be affected by imprecise estimation of the random effects.

    >>> print(smf.ols('y ~ x', data).fit().summary())
                                OLS Regression Results                            
    ==============================================================================
    Dep. Variable:                      y   R-squared:                       0.849
    Model:                            OLS   Adj. R-squared:                  0.849
    Method:                 Least Squares   F-statistic:                     1117.
    Date:                Tue, 11 Apr 2017   Prob (F-statistic):           2.44e-83
    Time:                        11:48:47   Log-Likelihood:                -302.50
    No. Observations:                 200   AIC:                             609.0
    Df Residuals:                     198   BIC:                             615.6
    Df Model:                           1                                         
    Covariance Type:            nonrobust                                         
    ==============================================================================
                     coef    std err          t      P>|t|      [0.025      0.975]
    ------------------------------------------------------------------------------
    Intercept     -0.0277      0.078     -0.355      0.723      -0.182       0.126
    x              2.6554      0.079     33.420      0.000       2.499       2.812
    ==============================================================================
    Omnibus:                        8.821   Durbin-Watson:                   1.954
    Prob(Omnibus):                  0.012   Jarque-Bera (JB):                4.331
    Skew:                           0.092   Prob(JB):                        0.115
    Kurtosis:                       2.303   Cond. No.                         1.02
    ==============================================================================
    
    Warnings:
    [1] Standard Errors assume that the covariance matrix of the errors is correctly specified.>> >
    
    
    >>> md = smf.mixedlm('y ~ x', data, groups=data['id'])
    >>> mdf = md.fit(method='cg')
    m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34_pr\statsmodels\base\model.py:504: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
      "Check mle_retvals", ConvergenceWarning)
    >>> print(mdf.summary())
             Mixed Linear Model Regression Results
    =======================================================
    Model:            MixedLM Dependent Variable: y        
    No. Observations: 200     Method:             REML     
    No. Groups:       2       Scale:              1.2069   
    Min. group size:  100     Likelihood:         -305.3643
    Max. group size:  100     Converged:          Yes      
    Mean group size:  100.0                                
    -------------------------------------------------------
                 Coef.  Std.Err.   z    P>|z| [0.025 0.975]
    -------------------------------------------------------
    Intercept    -0.028    0.131 -0.212 0.832 -0.284  0.228
    x             2.650    0.079 33.424 0.000  2.495  2.806
    groups RE     0.022    0.044                           
    =======================================================
    >>> 
    mdf = md.fit(method='bfgs')
    >>> 
    >>> print(mdf.summary())
             Mixed Linear Model Regression Results
    =======================================================
    Model:            MixedLM Dependent Variable: y        
    No. Observations: 200     Method:             REML     
    No. Groups:       2       Scale:              1.2069   
    Min. group size:  100     Likelihood:         -305.3643
    Max. group size:  100     Converged:          Yes      
    Mean group size:  100.0                                
    -------------------------------------------------------
                 Coef.  Std.Err.   z    P>|z| [0.025 0.975]
    -------------------------------------------------------
    Intercept    -0.028    0.131 -0.212 0.832 -0.284  0.228
    x             2.650    0.079 33.424 0.000  2.495  2.806
    groups RE     0.022    0.044                           
    =======================================================
    
    
    
    >>> md = smf.mixedlm('y ~ x', data, groups=data['id'], re_formula='~ x - 1')
    >>> mdf = md.fit(method='bfgs')
    >>> print(mdf.summary())
             Mixed Linear Model Regression Results
    =======================================================
    Model:            MixedLM Dependent Variable: y        
    No. Observations: 200     Method:             REML     
    No. Groups:       2       Scale:              0.9857   
    Min. group size:  100     Likelihood:         -286.7407
    Max. group size:  100     Converged:          Yes      
    Mean group size:  100.0                                
    -------------------------------------------------------
                 Coef.  Std.Err.   z    P>|z| [0.025 0.975]
    -------------------------------------------------------
    Intercept    -0.057    0.070 -0.804 0.422 -0.194  0.081
    x             2.628    0.495  5.307 0.000  1.657  3.598
    x RE          0.480    0.701                           
    =======================================================
    >> >
    
    
    >>> md = smf.mixedlm('y ~ x', data, groups=data['id'], re_formula='~ x')
    >>> mdf = md.fit(method='lbfgs')
    >>> m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34_pr\statsmodels\regression\mixed_linear_model.py:2039: ConvergenceWarning: The Hessian matrix at the estimated parameter values is not positive definite.
      warnings.warn(msg, ConvergenceWarning)
    
    >>> print(mdf.summary())
    m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34_pr\statsmodels\base\model.py:1058: RuntimeWarning: invalid value encountered in sqrt
      return np.sqrt(np.diag(self.cov_params()))
                Mixed Linear Model Regression Results
    ==============================================================
    Model:               MixedLM   Dependent Variable:   y        
    No. Observations:    200       Method:               REML     
    No. Groups:          2         Scale:                0.9680   
    Min. group size:     100       Likelihood:           -284.9909
    Max. group size:     100       Converged:            Yes      
    Mean group size:     100.0                                    
    --------------------------------------------------------------
                        Coef.  Std.Err.   z    P>|z| [0.025 0.975]
    --------------------------------------------------------------
    Intercept           -0.057    0.064 -0.883 0.377 -0.182  0.069
    x                    2.620    0.322  8.138 0.000  1.989  3.251
    Intercept RE         0.034                                    
    Intercept RE x x RE  0.129                                    
    x RE                 0.482                                    
    ==============================================================
    
    
    >>> mdf.model.score(mdf.params_object)
    array([-0.00211609,  0.00047108, -0.00032323])
    

    cluster robust standard errors are on the larger end compared to the above. But with only two clusters, they shouldn't be very reliable.

    >>> print(smf.ols('y ~ x', data).fit(cov_type='cluster', cov_kwds={'groups':data['id']}).summary())
                                OLS Regression Results                            
    ==============================================================================
    Dep. Variable:                      y   R-squared:                       0.849
    Model:                            OLS   Adj. R-squared:                  0.849
    Method:                 Least Squares   F-statistic:                     29.02
    Date:                Tue, 11 Apr 2017   Prob (F-statistic):              0.117
    Time:                        12:19:03   Log-Likelihood:                -302.50
    No. Observations:                 200   AIC:                             609.0
    Df Residuals:                     198   BIC:                             615.6
    Df Model:                           1                                         
    Covariance Type:              cluster                                         
    ==============================================================================
                     coef    std err          z      P>|z|      [0.025      0.975]
    ------------------------------------------------------------------------------
    Intercept     -0.0277      0.130     -0.212      0.832      -0.283       0.228
    x              2.6554      0.493      5.387      0.000       1.689       3.622
    ==============================================================================
    Omnibus:                        8.821   Durbin-Watson:                   1.954
    Prob(Omnibus):                  0.012   Jarque-Bera (JB):                4.331
    Skew:                           0.092   Prob(JB):                        0.115
    Kurtosis:                       2.303   Cond. No.                         1.02
    ==============================================================================
    
    Warnings:
    [1] Standard Errors are robust tocluster correlation (cluster)
    
    
    >>> print(smf.ols('y ~ x', data).fit(cov_type='hac-panel', cov_kwds={'groups':data['id'].values, 'maxlags':10}).summary())
    
                                OLS Regression Results                            
    ==============================================================================
    Dep. Variable:                      y   R-squared:                       0.849
    Model:                            OLS   Adj. R-squared:                  0.849
    Method:                 Least Squares   F-statistic:                     455.4
    Date:                Tue, 11 Apr 2017   Prob (F-statistic):             0.0298
    Time:                        15:27:17   Log-Likelihood:                -302.50
    No. Observations:                 200   AIC:                             609.0
    Df Residuals:                     198   BIC:                             615.6
    Df Model:                           1                                         
    Covariance Type:            hac-panel                                         
    ==============================================================================
                     coef    std err          z      P>|z|      [0.025      0.975]
    ------------------------------------------------------------------------------
    Intercept     -0.0277      0.091     -0.303      0.762      -0.207       0.151
    x              2.6554      0.124     21.340      0.000       2.412       2.899
    ==============================================================================
    Omnibus:                        8.821   Durbin-Watson:                   1.954
    Prob(Omnibus):                  0.012   Jarque-Bera (JB):                4.331
    Skew:                           0.092   Prob(JB):                        0.115
    Kurtosis:                       2.303   Cond. No.                         1.02
    ==============================================================================
    
    Warnings:
    [1] Standard Errors are robust tocluster correlation (hac-panel)
    
  13. sosata commented on Apr 14, 2017

    @sosata
    Author

    Alright, I also tried MATLAB and R to fit the mixed effects model to our data. They produce different results from both statsmodels 6 and 8, however they are consistent with each other. Therefore it seems there is a problem with the mixedlm function in statsmodels that needs to be fixed.

  14. kshedden commented on Apr 14, 2017

    @kshedden
    Contributor
  15. sosata commented on Apr 17, 2017

    @sosata
    Author

    Sure. This is how we are using each:

    R:

    lme<-lmer(y ~ x + (1+x|subject), data = lmm.data)

    MATLAB:

    formula = 'y ~ x + (1+x|subject)';
    lme =fitlme(data, formula);
    

    Python:

    md = smf.mixedlm('y ~ x', data, groups=data['subject'], re_formula="~x")
    mdf = md.fit()

    In all three, data we want to predict y from x in data, with subject specifying the groups.

  16. joergdietrich commented on Mar 6, 2018

    @joergdietrich

    @kshedden To further add to this issue, the generated mixed lm example (pulled from current master, #4204) shows non-convergence and different results in the lme4 comparison.

    This is after running the notebook locally with statsmodels 0.8.0, scipy 1.0.0 under python 3.6.4.

  17. kshedden commented on Mar 7, 2018

    @kshedden
    Contributor

    @joergdietrich Thanks for the report. We would like this to be as consistent as possible with other packages. However the sitka example in the notebook and the simulated example above both have their MLE and RMLE on the boundary of the parameter space. This may be somewhat common in practice, but it leads to many computational and statistical issues.

    I went back to the simulated example above and ran it in R and in statsmodels using 3 different optimizers. The optimized values of the log-likelihoods are:

    R        -284.9909
    CG       -284.99089658226671
    Powell   -285.00451084828364
    BFGS     -284.99189483242549
    

    The final gradient values (for the transformed parameters in the optimization) are

    CG      3.69642747e-04,   3.15785599e-05,  -1.48518980e-03
    BFGS    1.15947898e+00,  -1.28081785e-04,  -9.35476367e-06
    Powell  0.07870292       -0.03229172       -0.11194649
    

    So CG is pretty well converged but the others are not quite there.

    Looking at the fitted parameters, here is what we get in statsmodels under CG:

    --------------------------------------------------------
                  Coef.  Std.Err.   z    P>|z| [0.025 0.975]
    --------------------------------------------------------
    Intercept     -0.057    0.187 -0.303 0.762 -0.423  0.310
    x              2.620    0.590  4.438 0.000  1.463  3.777
    Group Var      0.034    3.737
    Group x x Cov  0.129    6.487
    x Var          0.482    3.913
    

    And here is what R produces:

    Random effects:
     Groups   Name        Variance Std.Dev. Corr
     id       (Intercept) 0.03434  0.1853
              x           0.48174  0.6941   1.00
     Residual             0.96804  0.9839
    Number of obs: 200, groups:  id, 2
    
    Fixed effects:
                Estimate Std. Error t value
    (Intercept)  -0.0566     0.1484  -0.381
    x             2.6198     0.4959   5.283
    

    These two solutions achieve essentially the same likelihood value, and the parameter estimates themselves are also nearly identical.

    I hope that the discepancies that people are seeing are not just due to misreading the output. We report variance and covariances, so, e.g. the correlation between the two random effects in our output is

    0.129 / sqrt(0.034 * 0.482) = 0.999...
    

    the is the same correlation parameter that R reports as 1, so it is as close as we can hope for in my view.

    I haven't looked at the sitka example in a while, but my recollection is that we achieve a slightly higher log-likelihood value than R.

    We have quite a bit of empirical data here and elsewhere that the log-likelihood, score, and hessian are correctly implemented for the MLE and RMLE. However the optimizers that we use (from scipy) are intended for problems in which the optimum is in the interior of the parameter space. When the optimum is on the boundary, the MLE/RMLE may not even be unique, and even if it is unique, there is no guarantee that these algorithms will find it. I don't know what optimizer R and Matlab are using, but as far as I know it is some type of first order method similar to what scipy uses and therefore is subject to the same limitations.

    I believe we are also all using the same transformed objective function, which profiles out the scale parameter then represents the random effects covariance matrix in terms of its Cholesky factor.

    We should probably restructure the notebooks so that the introductory notebook uses examples that are not on the boundary, then we could have a separate notebook discussing these more advanced issues.

  18. joergdietrich commented on Mar 7, 2018

    @joergdietrich

    @kshedden Thanks for the detailed reply! I'm coming to this as somebody who wants to learn about MixedLM and found lots of examples on the web using R. Not knowing a lot of R, I wanted to understand how these examples match to the different syntax of specifying random effects etc. in statsmodels. Having a mismatch between lme4 and statsmodels is quite confusing in this case.

    I didn't look at the Sitka data set. I gave up after I couldn't make the Pigs analysis match (I'm not sure what simulated data you refer to. The Pigs data seem to be a real data set.).

    model = sm.MixedLM.from_formula("Weight ~ Time", data, re_formula="Time", groups=data["Pig"])
    result = model.fit()
    print(result.summary())
    
    /home/joerg/applications/anaconda3/lib/python3.6/site-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
      "Check mle_retvals", ConvergenceWarning)
    /home/joerg/applications/anaconda3/lib/python3.6/site-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
      "Check mle_retvals", ConvergenceWarning)
    /home/joerg/applications/anaconda3/lib/python3.6/site-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
      "Check mle_retvals", ConvergenceWarning)
    /home/joerg/applications/anaconda3/lib/python3.6/site-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
      "Check mle_retvals", ConvergenceWarning)
    
                  Mixed Linear Model Regression Results
    =================================================================
    Model:               MixedLM    Dependent Variable:    Weight    
    No. Observations:    861        Method:                REML      
    No. Groups:          72         Scale:                 5.7891    
    Min. group size:     11         Likelihood:            -2220.3890
    Max. group size:     12         Converged:             No        
    Mean group size:     12.0                                        
    -----------------------------------------------------------------
                           Coef.  Std.Err.   z    P>|z| [0.025 0.975]
    -----------------------------------------------------------------
    Intercept              15.739    0.672 23.438 0.000 14.423 17.055
    Time                    6.939    0.085 81.326 0.000  6.772  7.106
    Intercept RE           30.266    4.271                           
    Intercept RE x Time RE  0.746    0.304                           
    Time RE                 0.483    0.046                           
    =================================================================
    
    /home/joerg/applications/anaconda3/lib/python3.6/site-packages/statsmodels/base/model.py:496: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
      "Check mle_retvals", ConvergenceWarning)
    /home/joerg/applications/anaconda3/lib/python3.6/site-packages/statsmodels/regression/mixed_linear_model.py:2001: ConvergenceWarning: Gradient optimization failed.
      warnings.warn(msg, ConvergenceWarning)
    

    Quite different output in R:

    %R print(summary(lmer("Weight ~ Time + (1 + Time | Pig)", data=dietox)))
    
    Linear mixed model fit by REML ['lmerMod']
    Formula: Weight ~ Time + (1 + Time | Pig)
       Data: dietox
    
    REML criterion at convergence: 4434.1
    
    Scaled residuals: 
        Min      1Q  Median      3Q     Max 
    -6.4286 -0.5529 -0.0416  0.4841  3.5624 
    
    Random effects:
     Groups   Name        Variance Std.Dev. Corr
     Pig      (Intercept) 19.4935  4.415        
              Time         0.4161  0.645    0.10
     Residual              6.0375  2.457        
    Number of obs: 861, groups:  Pig, 72
    
    Fixed effects:
                Estimate Std. Error t value
    (Intercept) 15.73865    0.55013   28.61
    Time         6.93901    0.07983   86.93
    
    Correlation of Fixed Effects:
         (Intr)
    Time 0.005 
    

    The notebook then goes on to say

    The random intercept and random slope are only weakly correlated (0.294 / sqrt(19.493 * 0.416) ~ 0.1). So next we fit a model in which the two random effects are constrained to be uncorrelated:

    and I can't find these numbers in the statsmodels output. I suspect those numbers may have come out of some earlier scipy version. So this is all quite confusing for somebody like me, who wants to map the many R examples on the web to statsmodels. I think a more introductory notebook, as you suggested above, would indeed be helpful.

    Greetings from a former West Hall (Physics) resident.

  19. kshedden commented on Mar 7, 2018

    @kshedden
    Contributor

    @joergdietrich the example you are showing here has a convergence issue. With the random slope for Time, the fit converges using lbfgs, cg, and powell optimizers, but not using the bfgs optimizer which is the default. (see code below). If we get enough evidence that this is a poor default, we could change it. Another possibiity is that we need to provide better starting values, or perhaps internally standardize the covariates. Or perhaps we need to use a hybrid optimization approach, e.g. start with powell then switch to cg. Thanks for pointing this out.

    import pandas as pd
    import statsmodels.api as sm
    
    df = pd.read_csv("dietox.csv")
    
    model1 = sm.MixedLM.from_formula("Weight ~ Time", re_formula="1+Time", groups="Pig", data=df)
    result1 = model1.fit(method='bfgs')
    
    model2 = sm.MixedLM.from_formula("Weight ~ Time", re_formula="1+Time", groups="Pig", data=df)
    result2 = model2.fit(method='lbfgs')
    
    model3 = sm.MixedLM.from_formula("Weight ~ Time", re_formula="1+Time", groups="Pig", data=df)
    result3 = model3.fit(method='powell')
    
    model4 = sm.MixedLM.from_formula("Weight ~ Time", re_formula="1+Time", groups="Pig", data=df)
    result4 = model4.fit(method='cg')
    
  20. kshedden commented on Mar 7, 2018

    @kshedden
    Contributor

    Another comment on the dietox data -- if we center Time, which is probably the right thing to do anyway on methodological grounds, all four optimization methods converge and agree with R.

    I have a pending PR that adds unit tests for the dietox data. The comments show how each field of the statsmodels fit can be programmatically extracted from the lmer object:

    https://github.com/kshedden/statsmodels/blob/2066531794d8ce50fbaf9e40d50771ca06a4dcea/statsmodels/regression/tests/test_lme.py#L366

  21. kshedden commented on Mar 7, 2018

    @kshedden
    Contributor

    I don't currently have a way to run Jupyter. If someone wants to clean up the notebook and make a PR that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions