366 votes
Accepted

Crossed vs nested random effects: how do they differ and how are they specified correctly in lme4?

(This is a fairly long answer, there is a summary at the end) You are not wrong in your understanding of what nested and crossed random effects are in the scenario that you describe. However, your ...
Robert Long's user avatar
  • 60.8k
95 votes
Accepted

"Model failed to converge" warning in lmer()

"Solving" the issue you experience in the sense of not receiving warnings about failed convergence is rather straightforward: you do not use the default BOBYQA optimiser but instead you opt to use the ...
usεr11852's user avatar
  • 44.2k
54 votes
Accepted

Dealing with singular fit in mixed models

When you obtain a singular fit, this is often indicating that the model is overfitted – that is, the random effects structure is too complex to be supported by the data, which naturally leads to the ...
Robert Long's user avatar
  • 60.8k
45 votes
Accepted

How to use ordinal logistic regression with random effects?

In principle you can make the machinery of any logistic mixed model software perform ordinal logistic regression by expanding the ordinal response variable into a series of binary contrasts between ...
Ben Bolker's user avatar
  • 43.7k
31 votes
Accepted

How to perform post-hoc test on lmer model?

You could use emmeans::emmeans() or lmerTest::difflsmeans(), or multcomp::glht(). I prefer <...
Kayle Sawyer's user avatar
31 votes
Accepted

lme() and lmer() giving conflicting results

tl;dr if you change the optimizer to "nloptwrap" I think it will avoid these issues (probably). Congratulations, you've found one of the simplest examples of multiple optima in a statistical ...
Ben Bolker's user avatar
  • 43.7k
30 votes
Accepted

How to fit a mixed model with response variable between 0 and 1?

It makes sense to start with a simpler case of no random effects. There are four ways to deal with continuous zero-to-one response variable that behaves like a fraction or a probability (this is our ...
amoeba's user avatar
  • 105k
29 votes

Dealing with singular fit in mixed models

This is a very interesting thread, with interesting answers and comments! Since this hasn't been brought up yet, I wanted to point out that we have very little data for each subject (as I understand ...
Isabella Ghement's user avatar
27 votes
Accepted

Why does treatment coding result in a correlation between random slope and intercept?

Treatment coding doesn't always or necessarily result in intercept/slope correlation, but it tends to more often than not. It's easiest to see why this is the case using pictures, and considering the ...
Jake Westfall's user avatar
26 votes
Accepted

How exactly does a "random effects model" in econometrics relate to mixed models outside of econometrics?

Summary: the "random-effects model" in econometrics and a "random intercept mixed model" are indeed the same models, but they are estimated in different ways. The econometrics way is to use FGLS, and ...
Randel's user avatar
  • 6,711
25 votes

r glmer warnings: model fails to converge & model is nearly unidentifiable

There is a nice description of how to troubleshoot this issue here: https://rstudio-pubs-static.s3.amazonaws.com/33653_57fc7b8e5d484c909b615d8633c01d51.html Basically, the recommendations are to ...
Jeffrey Girard's user avatar
24 votes
Accepted

Why is this linear mixed model singular?

As you have discovered, this happens when one of the variance components is estimated as zero. This typically has one of two explanations: the random effects structure is over-fitted - usually ...
Robert Long's user avatar
  • 60.8k
23 votes

How exactly does a "random effects model" in econometrics relate to mixed models outside of econometrics?

This answer doesn't comment on mixed models, but I can explain what the random-effects estimator does and why it screws up on that graph. Summary: the random-effects estimator assumes $E[u_i \mid x ] ...
Matthew Gunn's user avatar
  • 22.3k
21 votes

R - lmer vs glmer

lmer is used to fit linear mixed-effect models, so it assumes that the residual error has a Gaussian distribution. If your dependent variable A is a binary outcome (...
matteo's user avatar
  • 3,213
21 votes

How exactly does a "random effects model" in econometrics relate to mixed models outside of econometrics?

In this answer, I would like to elaborate a little on Matthew's +1 answer regarding the GLS perspective on what the econometrics literature calls the random effects estimator. GLS perspective ...
Christoph Hanck's user avatar
19 votes
Accepted

Conflicting results of summary() and anova() for a mixed model with interactions in lmer+lmerTest

In what is undoubtedly a newbie mistake, I have solved the problem I previously detailed above. The key to getting lmerTest::anova() and ...
James S.'s user avatar
  • 421
19 votes
Accepted

What to do with random effects correlation that equals 1 or -1?

Singular random-effect covariance matrices Obtaining a random effect correlation estimate of +1 or -1 means that the optimization algorithm hit "a boundary": correlations cannot be higher than +1 or ...
amoeba's user avatar
  • 105k
17 votes
Accepted

Intraclass Correlation Coefficient in mixed model with random slopes

Basically there's no single number or estimate that can summarize the degree of clustering in a random slopes model. The intra-class correlation (ICC) can only be written as a simple proportion of ...
Jake Westfall's user avatar
17 votes
Accepted

Why does gls model without random effects yield a similar fit to mixed effects model?

Random effects also model correlations. To explain this more formally, the model that both lme() and gls() are fitting is the ...
Dimitris Rizopoulos's user avatar
16 votes

Calculating $R^2$ in mixed models using Nakagawa & Schielzeth's (2013) R2glmm method

I am answering by pasting Douglas Bates's reply in the R-Sig-ME mailing list, on 17 Dec 2014 on the question of how to calculate an $R^2$ statistic for generalized linear mixed models, which I believe ...
Robert Long's user avatar
  • 60.8k
16 votes
Accepted

Number of random effects is not correct in lmer model

(1 + year | ID0) specify a random intercept and a random slope, both grouped by ID0, and additionally their correlation. See the ...
Roland's user avatar
  • 6,661
16 votes

How can I test for differences in variation between groups in a mixed model (lme4)?

A few points: sometimes log-transforming data can clear up heteroscedasticity nicely; this would be my first attempt, especially as you have a positive responses variable (song length), so we would ...
Ben Bolker's user avatar
  • 43.7k
16 votes
Accepted

How to decide whether to set REML to True or False?

In my (not entirely uninformed) opinion you're getting some questionable advice, from the web page and from the comments you received. you can use REML (or ML) whenever you want (regardless of the ...
Ben Bolker's user avatar
  • 43.7k
16 votes
Accepted

The origin of the Wilkinson-style notation such as (1|id) for random effects in mixed models formulae in R

The notation | has been around in nlme docs since version 3.1-1 and that is probably late 1999; we can easily check that on CRAN ...
usεr11852's user avatar
  • 44.2k
16 votes

Is parsimony crucial for statistical inference?

You ask two questions: How important is parsimony? Should you use backward stepwise elimination? The second one is easy: No, you shouldn't. This has been discussed here many times. It doesn't work ...
Peter Flom's user avatar
  • 120k
15 votes
Accepted

glmer vs lmer, what is best for a binomial outcome?

1) In previous versions of the lme4 package, you could run lmer using the binomial family. ...
Robert Long's user avatar
  • 60.8k
15 votes
Accepted

Confidence intervals on predictions for a non-linear mixed model (nlme)

What you've done here looks reasonable. The short answer is that for the most part the issues of predicting confidence intervals from mixed models and from nonlinear models are more or less orthogonal,...
Ben Bolker's user avatar
  • 43.7k
15 votes
Accepted

Compute partial $\eta^2$ for all fixed effects anovas from a lme4 model

First, I think @Henrik's answer here is sound and should (at least in excerpts) be stated on this site: The fact that calculating a global measure of model fit (such as R2) is already riddled ...
statmerkur's user avatar
  • 5,950
15 votes
Accepted

Mixed effects model: Compare random variance component across levels of a grouping variable

There's more than one way to test this hypothesis. For example, the procedure outlined by @amoeba should work. But it seems to me that the simplest, most expedient way to test it is using a good old ...
Jake Westfall's user avatar
14 votes
Accepted

Meaning of a convergence warning in glmer

Before going in to the code, allow me to give you a quick primer on trust region methods. Let $f(x)$ be your objective function and $x_k$ be your current iterate. Iteration $k$ of a generic trust ...
Bill Woessner's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible