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
69
votes
1 answer

Restart mixed effect model estimation with previously estimated values

I'm using lmer() in package lme4 to estimate mixed effects models. This works well, but now I want to run the estimation process for a fixed number of iterations, then resume the process by specifying start values, as calculated by the last…
Andrie
  • 176,377
  • 47
  • 447
  • 496
41
votes
2 answers

Linear mixed model with crossed repeated effects and AR1 covariance structure, in R

I have within-subject physiological data from participants (part), who have all looked at stimuli (reading newspapers) on three rounds (round), which each have five papers (paper), and within each there are variable number of visits (visit) in the…
RandomMonitor
  • 439
  • 1
  • 8
  • 16
40
votes
7 answers

How to get coefficients and their confidence intervals in mixed effects models?

In lm and glm models, I use functions coef and confint to achieve the goal: m = lm(resp ~ 0 + var1 + var1:var2) # var1 categorical, var2 continuous coef(m) confint(m) Now I added random effect to the model - used mixed effects models using lmer…
Tomas
  • 57,621
  • 49
  • 238
  • 373
30
votes
2 answers

lme4::lmer reports "fixed-effect model matrix is rank deficient", do I need a fix and how to?

I am trying to run a mixed-effects model that predicts F2_difference with the rest of the columns as predictors, but I get an error message that says fixed-effect model matrix is rank deficient so dropping 7 columns / coefficients. From this…
Lisa
  • 909
  • 2
  • 13
  • 31
25
votes
2 answers

Extract prediction band from lme fit

I have following model x <- rep(seq(0, 100, by=1), 10) y <- 15 + 2*rnorm(1010, 10, 4)*x + rnorm(1010, 20, 100) id <- NULL for(i in 1:10){ id <- c(id, rep(i,101)) } dtfr <- data.frame(x=x,y=y, id=id) library(nlme) with(dtfr, summary( lme(y~x,…
ECII
  • 10,297
  • 18
  • 80
  • 121
23
votes
2 answers

How to compare a model with no random effects to a model with a random effect using lme4?

I can use gls() from the nlme package to build mod1 with no random effects. I can then compare mod1 using AIC to mod2 built using lme() which does include a random effect. mod1 = gls(response ~ fixed1 + fixed2, method="REML", data) mod2 =…
It Figures
  • 403
  • 1
  • 3
  • 11
19
votes
3 answers

Speed up lmer function in R

I would like to share some of my thoughts when trying to improve the model fitting time of a linear mixed effects model in R using the lme4 package. Dataset Size: The dataset consists, approximately, of 400.000 rows and 32 columns. Unfortunately,…
mammask
  • 285
  • 1
  • 3
  • 10
19
votes
4 answers

Large fixed effects binomial regression in R

I need to run a logistic regression on a relatively large data frame with 480.000 entries with 3 fixed effect variables. Fixed effect var A has 3233 levels, var B has 2326 levels, var C has 811 levels. So all in all I have 6370 fixed effects. The…
Phil
  • 954
  • 1
  • 8
  • 22
17
votes
2 answers

Get 95% confidence interval with glm(..) in R

Here are some data dat = data.frame(y = c(9,7,7,7,5,6,4,6,3,5,1,5), x = c(1,1,2,2,3,3,4,4,5,5,6,6), color = rep(c('a','b'),6)) and the plot of these data if you wish require(ggplot) ggplot(dat, aes(x=x,y=y, color=color)) + geom_point() +…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
16
votes
1 answer

Mixed effects logistic regression

I'm attempting to implement mixed effects logistic regression in python. As a point of comparison, I'm using the glmer function from the lme4 package in R. I've found that the statsmodels module has a BinomialBayesMixedGLM that should be able to fit…
YTD
  • 457
  • 3
  • 11
15
votes
1 answer

Mixed Effects Models in Spark or other technology

Is it possible to run a mixed-effects regression model in Spark? (as we can do with lme4 in R, with MixedModels in Julia or with Statsmodels MixedLM in Python). Any example would be great. I've read there is a GLMix function but I don't know if the…
skan
  • 7,423
  • 14
  • 59
  • 96
13
votes
2 answers

Prediction with lme4 on new levels

I'm trying to fit a mixed effects model and then use that model to generate estimates on a new dataset that may have different levels. I expected that the estimates on a new dataset would use the mean value of the estimated parameters, but that…
random_forest_fanatic
  • 1,232
  • 1
  • 12
  • 30
12
votes
2 answers

Random Effects in Longitudinal Multilevel Imputation Models Using MICE

I am trying to impute data in dataset with a longitudinal design. There are two predictors (experimental group, and time) and one outcome variable (score). The clustering variable is id. Here is the toy data set.seed(345) A0 <- rnorm(4,2,.5) B0 <-…
llewmills
  • 2,959
  • 3
  • 31
  • 58
12
votes
2 answers

Python Statsmodels Mixedlm (Mixed Linear Model) random effects

I am a bit confused about the output of Statsmodels Mixedlm and am hoping someone could explain. I have a large dataset of single family homes, including the previous two sale prices/sale dates for each property. I have geocoded this entire dataset…
Tommy Shay
  • 141
  • 1
  • 1
  • 3
11
votes
1 answer

Implementing Longitudinal Random Forest with LongituRF package in R

I have some high dimensional repeated measures data, and i am interested in fitting random forest model to investigate the suitability and predictive utility of such models. Specifically i am trying to implement the methods in the LongituRF package.…
1
2 3
90 91