Multilevel Modeling for Psychology and the Social Sciences: Models, Graphs, and PracticeHsiu-Ting Yu 游琇婷 Hsiu-Ting Yu游琇婷
中文
AppendixE

Software Crosswalk: One Model in Every Program, and Troubleshooting

In this appendixthe programs and their defaults; the HSB cross-level model in every program, with a comparison of the estimates; the Riesby growth model; reconciling output across programs; a syntax crosswalk for common model features; troubleshooting by message.

about 30 min read4,914 words6 tables

The chapters fit their models in R and close with a crosswalk box that gives the same models in other programs. This appendix goes one step further for two models: the random intercept and slope model with cross-level interactions for the High School and Beyond data (model M3 of Chapter 6) and the linear growth model for the Riesby data (model G1 of Chapter 19). It shows each model in every program, compares the estimates that the programs produce, explains why output that looks different is often the same result, and ends with a guide to the warnings and errors that multilevel software prints. The R fits, with lme4 (Bates et al., 2015), lmerTest (Kuznetsova et al., 2017), pbkrtest (Halekoh & Højsgaard, 2014), nlme (Pinheiro & Bates, 2000), glmmTMB (Brooks et al., 2017), and brms (Bürkner, 2017), and a Python fit with statsmodels (Seabold & Perktold, 2010) were run for this appendix. The syntax for the other programs was not run, because those programs were not available where the book was produced; it was written from the documentation of recent versions (SAS/STAT for SAS 9.4, IBM SPSS Statistics 29, Stata 18, Mplus 8, and HLM 8) and should be checked against the output of the version at hand. Book-length treatments of multilevel models in particular programs include Singer (1998) and Littell et al. (2006) for SAS, West et al. (2014) for several programs, and the Mplus User’s Guide (Muthén & Muthén, 1998--2017).

E.1The Programs and Their Defaults#

Most apparent disagreements between programs come from defaults rather than from different mathematics. Table E.1 lists, for each program, the default estimator, the default method for tests of fixed effects, the default structure of the covariance matrix of the random effects, and the sample size used in the BIC. A model fitted in two programs with the same estimator and the same covariance structure should reproduce the same estimates to several decimals; if it does not, check the data, the centering, and the coding of the predictors, and then whether each fit reached the maximum of the likelihood (Section E.6).

Table E.1 Default Settings of Programs for Linear Mixed Models
Program (procedure) Estimator Tests of fixed effects Covariance of random effects in BIC
R lme4 (lmer) REML without ; Satterthwaite with lmerTest, Kenward–Roger with pbkrtest Unstructured for (1 + x | g) Observations
R nlme (lme) REML with between-within df Unstructured (pdLogChol) Observations ( under REML)
R glmmTMB ML Unstructured for (1 + x | g) Observations
SAS (PROC MIXED) REML with containment df Variance components (TYPE=VC) unless TYPE=UN Subjects
SPSS (MIXED) REML with Satterthwaite df Variance components (COVTYPE(VC)) unless COVTYPE(UN) Observations ( under REML)
Stata (mixed) ML ; small-sample df with reml dfmethod() Independent unless covariance(unstructured) Observations
Mplus (TWOLEVEL RANDOM) MLR Intercept-slope covariance fixed at zero unless freed with WITH Observations
HLM 8 (HLM2) REML with df for the level-2 coefficients of randomly varying level-1 coefficients; level-1 df for fixed level-1 slopes Unstructured –
JASP (Mixed Models) REML Satterthwaite Correlated, with all possible random slopes, by default –
jamovi (GAMLj) REML Satterthwaite Correlated by default –
Python statsmodels (MixedLM) REML Unstructured for re_formula Observations (ML fits only)
Julia MixedModels ML Unstructured Observations
MLwiN (also R2MLwiN) ML (IGLS) Estimate (SE); Wald on request ( in R2MLwiN) Unstructured for random coefficients at the same level –

Note. Defaults as documented for the versions named at the beginning of this appendix; defaults change between versions and should be checked. Estimator: REML = restricted maximum likelihood, ML = maximum likelihood, MLR = maximum likelihood with robust standard errors. HLM: = number of level-2 units, = number of level-2 predictors in the equation. IGLS: iterative generalized least squares, equivalent to ML for linear models; its restricted form, RIGLS, is equivalent to REML; MLwiN syntax is not shown in this appendix (Chapter 26 mentions MLwiN and its R interface R2MLwiN). in BIC: the sample size in the penalty of the Bayesian information criterion; : observations minus fixed effects; – = not reported by default. Under REML, SAS and SPSS count only the covariance parameters in , and SAS, under either estimator, leaves out of any covariance parameter estimated on the boundary (Chapter 11).

Three defaults cause most of the trouble. First, SAS and SPSS give random effects a diagonal (variance components) covariance matrix unless an unstructured matrix is requested, whereas the R packages estimate the covariance of a random intercept and slope by default, Stata assumes independence, and Mplus fixes their covariance at zero unless WITH frees it; a model with a random slope therefore differs across programs unless the structure is stated. Second, Stata, glmmTMB, Mplus, Julia, and MLwiN estimate by ML by default, whereas lme4, nlme, SAS, SPSS, HLM, JASP, jamovi, and statsmodels use REML; the variance components differ systematically between the two (Chapter 9). Third, the programs test fixed effects in different ways, from large-sample tests to tests with Satterthwaite or Kenward–Roger degrees of freedom (Chapter 10), so the same estimate can come with different values.

E.2One Model in Every Program: The HSB Cross-Level Model#

Model M3 of Chapter 6 predicts mathematics achievement from group-centered SES, the school mean of SES, the Catholic sector, and the two cross-level interactions, with a random intercept and a random slope of SES that are allowed to covary:

The data are the merged HSB file of Appendix C, which contains the group-centered SES (ses_cwc) and the sample school mean (meanses), so that every program uses the same variables (7,185 pupils in 160 schools). The syntax below requests REML and an unstructured covariance matrix wherever the program allows it.

R. The four packages use the same model formula, with minor differences in syntax:

R
library(lme4); library(lmerTest)          # lmerTest adds Satterthwaite df
m1 <- lmer(mathach ~ (meanses + catholic) * ses_cwc + (1 + ses_cwc | school),
           data = hsb, REML = TRUE)
summary(m1)                                # summary(m1, ddf = "Kenward-Roger")
library(nlme)
m2 <- lme(mathach ~ (meanses + catholic) * ses_cwc, random = ~ ses_cwc | school,
          data = hsb, method = "REML")
library(glmmTMB)
m3 <- glmmTMB(mathach ~ (meanses + catholic) * ses_cwc + (1 + ses_cwc | school),
              data = hsb, REML = TRUE)
library(brms)                              # Bayesian, default priors (Chapter 13)
m4 <- brm(mathach ~ (meanses + catholic) * ses_cwc + (1 + ses_cwc | school),
          data = hsb, seed = 20270001)
Table E.2 The HSB Cross-Level Model (Chapter 6, Model M3) in Five R and Python Packages
Parameter lme4 nlme glmmTMB statsmodels brms
Intercept 12.128 (0.199) 12.128 (0.199) 12.128 (0.199) 12.128 (0.199) 12.133 (0.204)
Mean SES 5.333 (0.369) 5.333 (0.369) 5.333 (0.369) 5.333 (0.369) 5.335 (0.379)
Catholic 1.227 (0.306) 1.227 (0.306) 1.227 (0.306) 1.227 (0.306) 1.219 (0.316)
SES (group-centered) 2.945 (0.156) 2.945 (0.156) 2.945 (0.156) 2.945 (0.156) 2.945 (0.155)
Mean SES SES 1.039 (0.299) 1.039 (0.299) 1.039 (0.300) 1.039 (0.300) 1.043 (0.301)
Catholic SES 1.643 (0.240) 1.643 (0.240) 1.643 (0.240) 1.643 (0.240) 1.644 (0.243)
2.380 2.380 2.380 2.379 2.445 (0.389)
0.101 0.101 0.101 0.101 0.113 (0.134)
0.192 0.192 0.192 0.192 0.123 (0.181)
36.721 36.721 36.721 36.721 36.748 (0.618)
46,503.66 46,503.66 46,503.66 46,503.66 –

Note. REML estimates with standard errors in parentheses; brms: posterior means with posterior standard deviations in parentheses (default priors; four chains of 2,000 iterations, the first 1,000 of them warmup). , : variances of the school intercepts and SES slopes; : their covariance; : level-1 residual variance. : minus twice the REML log-likelihood. Versions: R 4.3.3, lme4 1.1-35.1, lmerTest 3.1-3, pbkrtest 0.5.5, nlme 3.1-164, glmmTMB 1.1.8, brms 2.23.0, statsmodels 0.15.0.

SAS. PROC MIXED with TYPE=UN and Satterthwaite degrees of freedom:

SAS
proc mixed data=hsb method=reml covtest;
  class school;
  model mathach = meanses catholic ses_cwc meanses*ses_cwc catholic*ses_cwc
        / solution ddfm=satterthwaite;
  random intercept ses_cwc / subject=school type=un;
run;

SPSS. MIXED with COVTYPE(UN); the variables after WITH are covariates:

SPSS
MIXED mathach WITH meanses catholic ses_cwc
  /FIXED=meanses catholic ses_cwc meanses*ses_cwc catholic*ses_cwc
  /METHOD=REML
  /PRINT=SOLUTION TESTCOV
  /RANDOM=INTERCEPT ses_cwc | SUBJECT(school) COVTYPE(UN).

Stata. mixed with factor-variable notation, REML, and Satterthwaite degrees of freedom:

Stata
mixed mathach c.meanses c.ses_cwc i.catholic c.meanses#c.ses_cwc ///
      i.catholic#c.ses_cwc || school: ses_cwc, ///
      covariance(unstructured) reml dfmethod(satterthwaite)

Mplus. Mplus has no REML; with ESTIMATOR = ML its estimates correspond to the ML fits of the R packages (REML = FALSE), and the default MLR changes only the standard errors, which then differ from the model-based standard errors of the other programs. The variable names are those of the Mplus file in the export archive of Appendix C:

Mplus
DATA:     FILE = hsb.dat;
VARIABLE: NAMES = school minority female ses mathach size catholic pracad
                  disclim himinty meanses_ n_j meanses ses_cwc;
          USEVARIABLES = mathach ses_cwc meanses catholic;
          WITHIN = ses_cwc;  BETWEEN = meanses catholic;
          CLUSTER = school;  MISSING = ALL (-999);
ANALYSIS: TYPE = TWOLEVEL RANDOM;  ESTIMATOR = ML;
MODEL:    %WITHIN%
          s | mathach ON ses_cwc;
          %BETWEEN%
          mathach s ON meanses catholic;
          mathach WITH s;

HLM. HLM 8 is driven by menus. The multivariate data matrix (MDM) is built from a pupil file and a school file sorted by school, for example the SPSS files hsb_pupils.sav and hsb_schools.sav of the export archive. The model is specified equation by equation:

with SES entered group-mean centered and activated. The school file of the archive contains the school mean SES as distributed with the data (meanses_rb), which differs slightly from the sample mean used here (Appendix C); to reproduce Table E.2 exactly, the sample mean has to be added to the school file.

JASP and jamovi. In JASP, the Linear Mixed Models analysis of the Mixed Models module takes mathach as the dependent variable, meanses, catholic, and ses_cwc as fixed-effects variables with the two interactions added in the model terms, and school as the random-effects grouping factor with a random slope of ses_cwc and the Correlations option checked. In jamovi, the Linear Mixed Model analysis of the GAMLj module takes the same variables, with the random effects entered as Intercept | school and ses_cwc | school and correlated. Both fit the model with lme4 (JASP through afex), but their defaults change the parameterization: JASP codes nominal predictors with sum-to-zero contrasts and includes random slopes for every fixed effect that varies within schools, and GAMLj centers covariates at their grand means. To reproduce the lme4 column of Table E.2, enter catholic as a 0/1 scale variable (or choose treatment coding), keep only the random intercept and the ses_cwc slope, and in GAMLj set the scaling of covariates to none; when only the coding or centering differs, the random part and the other coefficients agree, but the intercept, the SES slope, and (under sum coding) the Catholic terms do not.

Python and Julia. In Python, statsmodels fits the model with a formula and a grouping variable; in Julia, MixedModels uses a formula in lme4 style and estimates by ML unless REML is requested:

Python
import statsmodels.formula.api as smf
m = smf.mixedlm("mathach ~ (meanses + catholic) * ses_cwc", hsb,
                groups=hsb["school"], re_formula="~ses_cwc")
fit = m.fit(reml=True)
Text
using MixedModels, CSV, DataFrames
hsb = CSV.read("hsb.csv", DataFrame)
m = fit(MixedModel, @formula(mathach ~ (meanses + catholic) * ses_cwc +
        (1 + ses_cwc | school)), hsb; REML = true)

The estimates compared. Table E.2 shows the REML estimates of lme4, nlme, glmmTMB, and statsmodels, and the posterior means of brms. The four likelihood-based fits agree: the largest difference between them in any estimate is about 0.0004, and the REML log-likelihood is the same in all four ( = 46,503.66). The ML fits of lme4, nlme, and statsmodels agree to the same degree (largest difference 0.0005). The standard errors of glmmTMB and statsmodels are slightly larger for some coefficients, most for the terms involving SES (for the interaction of mean SES and SES, 0.2996 against 0.2989), because these two programs derive them from the observed information matrix of all parameters jointly, which includes the uncertainty of the covariance parameters, whereas lme4 and nlme compute them from with the covariance parameters treated as known; when that uncertainty is ignored, glmmTMB also gives 0.2989.

The Bayesian fit agrees closely for the fixed effects, whose posterior standard deviations are close to the REML standard errors, but not for the covariance parameters: the posterior of the slope variance is wide and strongly skewed (median 0.064, 95% credible interval [0.000, 0.475]), so its mean, 0.113, lies above the REML estimate, 0.101, and well above its own median, and the covariance is pulled toward zero (0.123 against 0.192), because the data carry little information about so small a variance (Chapter 13). Every was below 1.01, and the smallest bulk or tail effective sample size over all parameters was 775.

The table also checks the syntax for the other programs: SAS, SPSS, and Stata with REML and an unstructured covariance matrix, and HLM with the sample school mean, should reproduce its first column to the precision they print, and Mplus with ESTIMATOR = ML the ML estimates (for example, a slope variance of 0.065 instead of 0.101).

E.3The Riesby Growth Model#

Model G1 of Chapter 19 is a linear growth model for the Hamilton depression ratings of the Riesby data, with a random intercept and a random slope of week that covary, estimated by ML from the 375 observed ratings of 66 patients. In long format, every program specifies it like the HSB model, with the occasion as level 1 and the patient as level 2:

R
lmer(hamd ~ week + (1 + week | id), data = riesby, REML = FALSE)
SAS
proc mixed data=riesby method=ml covtest;
  class id;
  model hamd = week / solution ddfm=satterthwaite;
  random intercept week / subject=id type=un;
run;
Stata
mixed hamd week || id: week, covariance(unstructured)

In SPSS, /METHOD=ML and /RANDOM=INTERCEPT week | SUBJECT(id) COVTYPE(UN); in Mplus, the same two-level setup as for HSB with week as the within-level variable, or a latent growth model in wide format (Chapter 22); in HLM, a two-level model with WEEK uncentered at level 1. Table E.3 shows that the four packages agree to within 0.002.

Table E.3 The Riesby Linear Growth Model (Chapter 19, Model G1) in Four R and Python Packages
Parameter lme4 nlme glmmTMB statsmodels
Intercept 23.577 (0.546) 23.577 (0.547) 23.577 (0.546) 23.577 (0.546)
Week 2.377 (0.209) 2.377 (0.209) 2.377 (0.209) 2.377 (0.209)
12.631 12.629 12.629 12.629
2.079 2.079 2.079 2.079
1.421 1.421 1.421 1.421
12.216 12.217 12.217 12.217
2,219.04 2,219.04 2,219.04 2,219.04

Note. ML estimates with standard errors in parentheses. , : variances of the patient intercepts (week 0) and slopes; : their covariance; : level-1 residual variance. : minus twice the log-likelihood.

E.4Reconciling Output Across Programs#

When the estimates of two programs differ, five questions usually find the reason.

Same estimator? REML and ML estimates of the variance components differ, most for the smallest ones: the SES slope variance of the HSB model is 0.101 under REML and 0.065 under ML. The fixed effects differ much less. By default, Mplus and Stata estimate by ML, so their default output must be compared with ML fits; the MLR default of Mplus also changes the standard errors.

Same parameters? Programs report the random part in different forms: lme4, glmmTMB, and Julia print variances, standard deviations, and correlations; nlme prints standard deviations and correlations; SAS, SPSS, Mplus, statsmodels, and Stata (unless the option stddeviations is given) print variances and covariances, and HLM prints both forms. Squaring the standard deviations and multiplying the correlation by both standard deviations converts one form into the other. Programs also label the elements of the covariance matrix differently: the covariance appears as UN(2,1) in SAS, UN (2,1) in SPSS, cov(ses_cwc,_cons) in Stata, MATHACH WITH S at the between level in Mplus, and as the off-diagonal element of the matrix in HLM.

Same tests? The fixed effects are the same, but their tests differ. For the Catholic-by-SES interaction of the HSB model, the Satterthwaite approximation gives 143.2 degrees of freedom and the Kenward–Roger approximation 142.0, whereas nlme assigns the interaction the level-1 degrees of freedom (7,022) because it contains a level-1 variable, ignoring that the SES slope varies across schools, and HLM, which gives the coefficients of a random slope degrees of freedom, assigns it 157; for the sector effect itself, nlme uses 157 and Satterthwaite 149.6. With 160 schools the conclusions are the same, but with few clusters the choice matters (Chapter 10).

Same fit statistics? A REML log-likelihood cannot be compared with an ML log-likelihood, and REML likelihoods of models with different fixed effects cannot be compared at all (Chapters 9 to 11). lme4 reports the REML criterion ( = 46,503.66 for the HSB model; extract it with REMLcrit(), not deviance(fit, REML = TRUE)) for REML fits and the deviance ( = 46,496.43) for ML fits. The information criteria also differ in their penalty: for the ML fit of the HSB model, AIC is 46,516.43, BIC with the number of pupils is 46,585.23, and BIC with the number of schools, as SAS computes it, is 46,547.18; Stata gives the latter with estat ic, n(160), and in other programs it can be computed from the log-likelihood. Only differences between models fitted in the same program with the same definitions are meaningful.

Same data? Programs delete incomplete cases differently when variables are missing, and centering must be done identically; for the Riesby data, all programs must use the same 375 observed ratings. The HLM example above is a reminder that a variable with the same name, here the school mean of SES, can be computed in more than one way.

E.5Syntax Crosswalk for Common Model Features#

Table E.4 gives the syntax for the most common features of the models in this book in four programs. The chapters’ crosswalk boxes show complete examples; the table is meant as a quick reference.

Table E.4 Syntax for Common Features of Linear Mixed Models in Four Programs
Feature R lme4 SAS PROC MIXED SPSS MIXED Stata mixed
Random intercept (1 | g) random intercept / subject=g; /RANDOM=INTERCEPT | SUBJECT(g) || g:
Correlated intercept and slope (1 + x | g) random intercept x / subject=g type=un; /RANDOM=INTERCEPT x | SUBJECT(g) COVTYPE(UN) || g: x, cov(unstructured)
Uncorrelated intercept and slope (1 + x || g) type=vc (default) COVTYPE(VC) (default) || g: x (default)
Three levels, nested (1 | s) + (1 | s:c) random intercept / subject=s; random intercept / subject=c(s); /RANDOM=INTERCEPT | SUBJECT(s) /RANDOM=INTERCEPT | SUBJECT(s*c) || s: || c:
Crossed (1 | a) + (1 | b) two random statements with subject=a and subject=b two /RANDOM subcommands || _all: R.a || b: (a: the factor with fewer levels)
ML instead of REML REML = FALSE method=ml /METHOD=ML default (reml for REML)
Kenward–Roger df summary(m, ddf = "Kenward-Roger") after library(lmerTest) ddfm=kr /CRITERIA=DFMETHOD(KENWARDROGER) reml dfmethod(kroger)
AR(1) residuals nlme::lme(..., correlation = corAR1(form = ~ time | id)) repeated time / subject=id type=ar(1); with time in CLASS /REPEATED=time | SUBJECT(id) COVTYPE(AR1) residuals(ar 1, t(time))

Note. g, s, c, a, b: identifiers of clusters, schools, classes, and two crossed classifications; x: a predictor with a random slope; id, time: person and occasion. SAS needs the identifiers in the CLASS statement (or the data sorted by them); SPSS accepts identifiers of any type. In Stata, R.a declares the crossed factor a as a set of random effects at the level of the whole sample. Mplus specifies these features with TYPE = TWOLEVEL or THREELEVEL, WITHIN, BETWEEN, and CLUSTER (for crossed classifications, TYPE = CROSSCLASSIFIED with Bayesian estimation); see the crosswalk boxes of Chapters 5, 6, 8, and 26.

E.6Troubleshooting#

Warnings and errors from multilevel software fall into a few groups, and each group has its usual causes and remedies (Table E.5). Table E.6 lists 15 messages that the examples of this appendix reproduce in R and Python, with the exact wording printed by the versions used in this book. Four of the examples use a small simulated data set of 10 clusters of five observations without any cluster variance, which is the typical situation in which a random slope cannot be estimated: lme4 reports a boundary (singular) fit, glmmTMB a non-positive-definite Hessian and singular convergence, and nlme stops with an error; the fourth example, with two predictors that are multiples of each other, adds a message about rank deficiency to the singular fit.

Table E.5 Common Warnings and Errors, Their Usual Causes, and Remedies
Problem Typical messages Usual causes Remedies
Boundary (singular) fit lme4: “boundary (singular) fit”; SAS: “Estimated G matrix is not positive definite”; SPSS: “The final Hessian matrix is not positive definite although all convergence criteria are satisfied”; Stata: “(not concave)” or “(backed up)” in the last iterations A variance estimated as zero or a correlation as ; too few clusters for the random part Confirm with other optimizers or starting values that it is the maximum; simplify the random part or report the singular fit; or use weakly informative priors in a Bayesian fit (Chapters 8, 9, 13, 14)
Failure to converge lme4: “Model failed to converge with max|grad|”; glmmTMB: “Model convergence problem”; nlme: “iteration limit reached”; statsmodels: “ConvergenceWarning”; SAS: “Did not converge”; SPSS: “Iteration was terminated but convergence has not been achieved”; Stata: “convergence not achieved”; Mplus: “THE MODEL ESTIMATION DID NOT TERMINATE NORMALLY …” Poorly scaled predictors, an overparameterized random part, or an optimizer stopping early Rescale or center predictors; refit with several optimizers or starting values (allFit() in lme4, PARMS in SAS) and keep the largest log-likelihood (same estimator and approximation); simplify the random part (Chapter 9)
Scaling lme4: “Some predictor variables are on very different scales”; “Model is nearly unidentifiable: very large eigenvalue” Predictors measured in very different units Divide predictors by a constant; the fit is unchanged, only the units change (Chapter 9)
Rank deficiency lme4: “fixed-effect model matrix is rank deficient”; SAS and SPSS print a coefficient of 0 marked as redundant A predictor that is a linear function of others, including a cluster-level variable collinear with cluster dummies Remove the redundant predictor; check the coding of categorical variables
Untrustworthy standard errors Mplus: “THE STANDARD ERRORS OF THE MODEL PARAMETER ESTIMATES MAY NOT BE TRUSTWORTHY FOR SOME PARAMETERS DUE TO …”; glmmTMB: “non-positive-definite Hessian” A parameter at a boundary, or a flat likelihood Inspect the parameter named in the message; simplify the model or use likelihood-ratio tests and profile intervals instead of Wald statistics (Chapters 10 and 11)

Note. Messages of programs not run for this book are quoted in the form in which they are commonly printed, shortened where marked by an ellipsis; their exact wording differs between versions. Chapters: where the problem and its remedies are discussed.

Table E.6 Messages Reproduced by the Examples of Section E.6
Program Example Message (verbatim)
R lme4 Random slope, 10 clusters of 5, no cluster variance : boundary (singular) fit: see help(isSingular)
R lme4 Random slope of SES multiplied by 1,000 (HSB) : Model failed to converge with max|grad| = 3.68138 (tol = 0.002, component 1)
R lme4 Random slope of SES multiplied by 1,000 (HSB) : Model is nearly unidentifiable: very large eigenvalue  - Rescale variables?;Model is nearly unidentifiable: large eigenvalue ratio  - Rescale variables?
R lme4 Two predictors that are multiples of each other, 10 clusters of 5, no cluster variance : fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
R lme4 Two predictors that are multiples of each other, 10 clusters of 5, no cluster variance : boundary (singular) fit: see help(isSingular)
R lme4 Logistic model with age multiplied by 1,000 (contraception) : Some predictor variables are on very different scales: consider rescaling
R lme4 Logistic model with age multiplied by 1,000 (contraception) : Model failed to converge with max|grad| = 0.0887584 (tol = 0.002, component 1)
R lme4 Logistic model with age multiplied by 1,000 (contraception) : Model is nearly unidentifiable: very large eigenvalue  - Rescale variables?;Model is nearly unidentifiable: large eigenvalue ratio  - Rescale variables?
R glmmTMB Random slope, 10 clusters of 5, no cluster variance : Model convergence problem; non-positive-definite Hessian matrix. See vignette(troubleshooting)
R glmmTMB Random slope, 10 clusters of 5, no cluster variance : Model convergence problem; singular convergence (7). See vignette(troubleshooting), help(diagnose)
R nlme Random slope, 10 clusters of 5, no cluster variance : nlminb problem, convergence error code = 1   message = iteration limit reached without convergence (10)
R glmmTMB HSB model M3 estimated by ML : Model convergence problem; non-positive-definite Hessian matrix. See vignette(troubleshooting)
Python statsmodels HSB M3, REML, method = lbfgs : Maximum Likelihood optimization failed to converge. Check mle_retvals
Python statsmodels HSB M3, REML, method = lbfgs : MixedLM optimization failed, trying a different optimizer may help.
Python statsmodels HSB M3, REML, method = lbfgs : Gradient optimization failed, |grad| = 11.107297

Two further cases from the HSB model show that a warning is not the only sign of trouble, and that its absence is no guarantee. Estimated by ML, the model gave glmmTMB a non-positive-definite Hessian and a slope variance of 0.018 (logLik() returns NA for this fit; its objective gives a log-likelihood of 23,248.24, 0.03 below the maximum), whereas lme4, nlme, and statsmodels agreed on 0.065; the likelihood is flat in this small variance, and the warning correctly flags that the optimizer stopped short of the maximum. Estimated by REML with the alternative optimizer of nlme (lmeControl(opt = "optim")), the model stopped at a slope variance of 0.0003 with a REML log-likelihood 0.56 below the maximum, without any message. Comparing the log-likelihood across optimizers or programs, which takes one line of code, finds both problems, provided that the fits maximize the same likelihood (the same estimator and, for generalized models, the same approximation). statsmodels with the L-BFGS optimizer alone also stopped early, but it said so (Table E.6); its default sequence of optimizers reached the maximum.

References

Bates, D., Mächler, M., Bolker, B., & Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1–48. https://doi.org/10.18637/jss.v067.i01
Brooks, M. E., Kristensen, K., Benthem, K. J. van, Magnusson, A., Berg, C. W., Nielsen, A., Skaug, H. J., Mächler, M., & Bolker, B. M. (2017). glmmTMB balances speed and flexibility among packages for zero-inflated generalized linear mixed modeling. The R Journal, 9(2), 378–400. https://doi.org/10.32614/RJ-2017-066
Bürkner, P.-C. (2017). brms: An R package for Bayesian multilevel models using Stan. Journal of Statistical Software, 80(1), 1–28. https://doi.org/10.18637/jss.v080.i01
Halekoh, U., & Højsgaard, S. (2014). A Kenward–Roger approximation and parametric bootstrap methods for tests in linear mixed models: The R package pbkrtest. Journal of Statistical Software, 59(9), 1–32. https://doi.org/10.18637/jss.v059.i09
Kuznetsova, A., Brockhoff, P. B., & Christensen, R. H. B. (2017). lmerTest package: Tests in linear mixed effects models. Journal of Statistical Software, 82(13), 1–26. https://doi.org/10.18637/jss.v082.i13
Littell, R. C., Milliken, G. A., Stroup, W. W., Wolfinger, R. D., & Schabenberger, O. (2006). SAS for mixed models (2nd ed.). SAS Institute.
Muthén, L. K., & Muthén, B. O. (1998--2017). Mplus user’s guide (8th ed.). Muthén & Muthén.
Pinheiro, J. C., & Bates, D. M. (2000). Mixed-effects models in S and S-PLUS. Springer.
Seabold, S., & Perktold, J. (2010). Statsmodels: Econometric and statistical modeling with Python. Proceedings of the 9th Python in Science Conference, 92–96. https://doi.org/10.25080/Majora-92bf1922-011
Singer, J. D. (1998). Using SAS PROC MIXED to fit multilevel models, hierarchical models, and individual growth models. Journal of Educational and Behavioral Statistics, 23(4), 323–355.
West, B. T., Welch, K. B., & Gałecki, A. T. (2014). Linear mixed models: A practical guide using statistical software (2nd ed.). CRC Press. https://doi.org/10.1201/b17198
Cite this bookYu, H.-T. (2026). Multilevel modeling for psychology and the social sciences: Models, graphs, and practice (Web ed.). Appendix E.