Questions tagged [mixed-models]

Programming problems related to the analysis of statistical models with random-effects terms, also variously: repeated measures, hierarchical, multilevel models

Overview

"Mixed models" refers to a class of models that are variously known as: mixed-effects models, multilevel models, hierarchical linear models,... This class of models was developed to account for correlation that may occur within nested data. A classic example is the estimation of test scores of students: if test scores are correlated within classes, schools, districts, etc., mixed models allow the modeler to simultaneously estimate the differences between individual students and between the groups to which they belong (with the possibility of including covariates at all levels).

References

StatsExchangers often recommend the following resources for learning more about mixed models:

Software packages

Mixed models are available in the following statistical packages:

  • lme4 and nlme for R
  • PROC MIXED and GLIMMIX for SAS
  • MLwiN
  • xtreg, xtmixed, xtlogit, xtmelogit, xtmepoisson, and other xt* commands; user-contributed package GLLAMM for Stata
  • Mplus
  • HLM

Tag usage

Questions on tag should be about implementation and programming problems, not about the statistical or theoretical properties of the technique. Consider whether your question might be better suited to Cross Validated, the StackExchange site for statistics, machine learning and data analysis.

1368 questions
11
votes
2 answers

lme4::glmer vs. Stata's melogit command

Lately I have been trying to fit a lot of random effects models to relatively big datasets. Let’s say about 50,000 people (or more) observed at up to 25 time points. With such a large sample size, we include a lot of predictors that we’re adjusting…
Jonathan Gellar
  • 303
  • 1
  • 8
11
votes
2 answers

How to have multiple groups in Python statsmodels linear mixed effects model?

I am trying to use the Python statsmodels linear mixed effects model to fit a model that has two random intercepts, e.g. two groups. I cannot figure out how to initialize the model so that I can do this. Here's the example. I have data that looks…
Sourav Dey
  • 387
  • 1
  • 4
  • 14
10
votes
2 answers

How to cope with a singular fit in a linear mixed model (lme4)?

I am running several linear mixed models for an study about birds with the variable nest as a random variable. The thing is that in some of these models I get what is called 'singular fit': my nest random variable has a variance and st error of…
Iraida
  • 101
  • 1
  • 1
  • 8
10
votes
2 answers

robust standard errors for mixed-effects models in lme4 package of R

I am using the lme4 package for linear mixed effect modeling the mixed-effect model is below: fm01 <- lmer(sublat <- goal + (1|userid)) the above command returns an S4 object called fm01 this object includes fixed effects and their OLS standard…
Adrienne
  • 163
  • 2
  • 9
10
votes
3 answers

test for significance of interaction in linear mixed models in nlme in R

I use lme function in the nlme R package to test if levels of factor items has significant interaction with levels of factor condition. The factor condition has two levels: Control and Treatment, and the factor items has 3 levels: E1,...,E3. I use…
alittleboy
  • 10,616
  • 23
  • 67
  • 107
9
votes
0 answers

Using `ordinal::clmm` model to make predictions on new data

I have some repeated measures, ordinal response data: dat <- data.frame( id = factor(sample(letters[1:5], 50, replace = T)), response = factor(sample(1:7, 50, replace = T), ordered = T), x1 = runif(n = 50, min = 1, max = 10), x2 = runif(n =…
jrudd
  • 91
  • 2
9
votes
1 answer

Fitting the same models in nlme and lme4

The data are from here library(nlme) dat0 <- read.table("aids.dat2",head=T) dat1 <- dat0[dat0$day<=90, ] # use only first 90-day data dat2 <- dat1[!apply(is.na(dat1),1,any),] # remove missing data # Next, let's treat the data as longitudinal…
Adrian
  • 9,229
  • 24
  • 74
  • 132
9
votes
1 answer

GLMER warning: variance-covariance matrix [...] is not positive definite or contains NA values

I sometimes find that my GLMMs from glmer, package lme4, show the following warning messages, when their summary is called: Warning messages: 1: In vcov.merMod(object, use.hessian = use.hessian) : variance-covariance matrix computed from…
kdarras
  • 389
  • 1
  • 5
  • 16
9
votes
0 answers

Bayesian error-in-variables (total least squares) model in R using MCMCglmm

I am fitting some Bayesian linear mixed models using the MCMCglmm package in R. My data includes predictors that are measured with error. I'd therefore like to build a model that takes this into account. My understanding is that a basic mixed…
Alberto
  • 133
  • 5
9
votes
1 answer

fitting a linear mixed model to a very large data set

I want to run a mixed model (using lme4::lmer) on 60M observations of the following format; all predictor/dependent variables are categorical (factors) apart from the continuous dependent variable tc; patient is the grouping variable for a random…
steve
  • 115
  • 1
  • 7
8
votes
1 answer

Singularity in backsolve at level 0, block 1 in LME model

dput for data, copy from https://pastebin.com/1f7VuBkx (too large to include here) data.frame': 972 obs. of 7 variables: $ data_mTBS : num 20.3 22.7 0 47.8 58.7 ... $ data_tooth: num 1 1 1 1 1 1 1 1 1 1 ... $ Adhesive : Factor w/ 4 levels…
Mohammed Ahmed
  • 79
  • 1
  • 1
  • 7
8
votes
0 answers

lme4 glmer for r caret package train function

I am trying to adapt the glm method from caret::train to be used for a Generalized Linear Mixed Effects Model. I have used the following code to set-up the function: `GLMERmod <- list(type="Classification", library="lme4", loop=NULL) parameters <-…
daileyco
  • 743
  • 5
  • 13
8
votes
1 answer

Are random effect variables automatically taken as factors in lmer (or lme) in R?

I understand that having a continuous or numeric variable as a random effect in a mixed effects model doesn't make much sense (e.g., see here). But what I'm wondering is if lme4::lmer or nlme::lme in R purposefully prevent you from doing…
theforestecologist
  • 4,667
  • 5
  • 54
  • 91
8
votes
1 answer

Incorporating time series into a mixed effects model in R (using lme4)

I've had a search for similar questions and come up short so apologies if there are related questions that I've missed. I'm looking at the amount of time spent on feeders (dependent variable) across various conditions with each subject visiting…
wonderburg
  • 95
  • 1
  • 1
  • 5
8
votes
2 answers

Extracting coefficients and their standard error for each unit in an lme model fit

How could I extract coefficients (b0 and b1) with their respectively standard errors for each experimental unit (plot )in a linear mixed model such as this one: Better fits for a linear model with this same dataset(df), and for the fitted model…
Juanchi
  • 1,147
  • 2
  • 18
  • 36
1
2
3
90 91