# Questions tagged [lme4]

385 questions

0

12

Views

### Mixed ANOVA (lme) returns error for alphabetic variable

I have a large data set with persons who answered questionnaires at several measurement points. I want to run an ANOVA using the lme function with my 'SERIAL' variable as identifying the persons (which is the serial code of a person in letters and numbers, e.g. YVEDPEPGV9). So person YVEDPEPGV9 answ...
j_brokelm

1

729

Views

### mixed() vs lmer() output for fixed effect factor labels: numeric vs character

I've noticed that when specifying a model using the lmer function in the lme4 package which contains factor-type predictors, the suffix indicating the level of the predictor is a character string of that factor level, as is the case for treatment here: library(afex) data(obk.long) m1
luser

0

80

Views

### Deviation of random effect stuck at 0 for underdispserd poisson data

I recently found a rather unexpected behavior of glmer for underdispersed data: the number of eggs laid in 4 nestboxes placed in 53 forest plots. The standard deviation estimates get stuck at 0 even if there are quite some between-group variation also the residual standard deviation is not reported....
Lionel

0

380

Views

### modelling interaction terms in random effects and coding of daytime in growth models lme4

I have a question regarding model setup in R and after a long and thorough search I did not find a thread answering either of my two questions: Im gonna describe the setup first: Its a repeated measures dataset with two different interventions (food and training), each of them have two levels. All p...
mrie

0

276

Views

### Prediction intervals from model average

Is it possible to get prediction intervals from a model average in R? I've used the MuMIn package to model-average several linear mixed models (that I fit using lme4::lmer()). The MuMIn package supports model predictions & st. errors of estimates (if all of the component models support the estimati...
filups21

1

39

Views

### R: how to extract random effects from nlmer output

library(lme4) startvec

0

93

Views

### Designating numeric variables as factors within lme4

Is there any way to specify contrast matrices within an lmer if the variable in question is not a factor outside the lmer? As an example, toy data of a 2 x 4 mixed model with group, a between-subjects factor, and time a within-subjects factor. I am testing the between-group differences in score at l...
llewmills

0

39

Views

### lmerTest::rand() behaves strangely when variable names contain '.'

I have some experience with lme4, but today I tried lmerTest for the first time and was surprised by some results when using the rand() function to examine the random components. (I know this is not advised by the authors of lme4!) In troubleshooting, I think I discovered some undesired behavior: wh...
ErinMcJ

0

282

Views

### Fitting GLM (family = inverse.gaussian) on simulated AR(1)-data.

I am encountering quite an annoying and to me incomprehensible problem, and I hope some of you can help me. I am trying to estimate the autoregression (influence of previous measurements of variable X on current measurement of X) for 4 groups that have a positively skewed distribution to various deg...
Jeroen Mulder

0

70

Views

### repeated measures linear regression R

I have an experiment with 16 subjects. Each subject has 3 base line measurements of a continuous variable Age, BMI and bloodlevelA Each subject then undergoes the same study protocol of treatment over 5 days (days 1-5). On each day a further blood measurement is made (bloodlevelB). mydata is in long...
MLyall

0

45

Views

### ezANOVA to lme4?

I have a question regarding ezANOVA and lme4 -- I would like to run my stats using lme4 instead of using ezANOVA, but am not sure how to write the lme4 equation. Here is what I use for ezANOVA: ezANOVA(data = SG10Long, wid = Subject, dv = Att, within = .(Day, Cue), between = Group, type = 3, detaile...
PeterPer

1

112

Views

### Log-likelihood calculation given estimated parameters

In general: I want to calculate the (log) likelihood of data N given the estimated model parameters from data O. More specifically, I want to know if my ll_given_modPars function below exists in one of the may R packages dealing with data modeling (lme4, glmm, etc.) as shown in this abstract example...
pFiaux

0

27

Views

### Call to lme4 extremely slow when run from rmarkdown

I am applying the lmer() function from the lme4 package to a series of rows in a matrix. The calculations take a few minutes. I have included precisely the same code in an Rmarkdown document. When I process the document with rmarkdown::render(), the same bit of code takes an order of magnitude longe...
January

1

318

Views

### Using a factor as both fixed and random in linear mixed models

I would like to know if it is acceptable to use a factor as both fixed and random. My understanding is that it is not a general practice. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3881361/ http://avesbiodiv.mncn.csic.es/estadistica/curso2011/regm26.pdf In the following model, I am using Sp as a...
candle786

0

106

Views

### Error using broom::tidy on a linear mixed model created with lmerTest

I am trying to use the tidy function in the broom R package to display results from a linear mixed model created with lmer from lmerTest. I get an error and I don't know if it's from a bug or incorrectly using the library. Perhaps this isn't supposed to work, but in that case, what is recommended f...
tkerwin

0

104

Views

### Running a linear mixed model (lmer, lme4) with pre-defined variance components in R

I am creating a linear mixed model for which I did estimate/define my variance components in advance. Now I would like to add them to the function but I dont know how to do this. The currently used 'lmer'-function from the 'lme4'-package does estimate the variance components by itself and I dont kno...
T. Grüter

0

39

Views

### Inclusion of correlation structure glmer function of package lme4

I am using the glmer function of the lme4 package of R. My answer is Bernoulli and my data are longitudinal. In the bild Package, I have already found article using Mc1 or MC2 for correlation structures. Is there any way I can use the glmer function and be able to include a correlation structure? If...
Cleber Iack

1

34

Views

### Call variables for regression in lmer function

I am calling the lmer function from the lme4 package. The function works if I hard code the column names. If I refer to it as a variable, though, it throws an error. My ultimate goal is to call a string that includes '+' between each column name. Here is an example lmer call: colnames(df) COL_A, C...
nak5120

0

87

Views

### Mixed GLMM Model - Issues with using weights (Using R package 'lme4'

I am trying to implement a mixed and weighted logistic regression model using the glmer function from the package 'lme4' in R. This is how my function looks mixed
user8530894

1

101

Views

### R: Confidence interval for sigma in a purely fixed effect model

Is there a standard way to estimate confidence interval for the variance parameter of a linear model with fixed-effect. E.g. given: reg=lm(formula = 100/mpg ~ disp + hp + wt + am, data = mtcars) how can I get the confidence interval for the variance parameter. confint only details fixed effect and l...
user1835313

0

88

Views

### lmer: Anova gives Warning message: In beta - betaH : longer object length is not a multiple of shorter object length

I am performing a simple general linear mixed model, using lmer. I would like to find out if there are any differences in flower visitor abundance between nutrient treatment plots. I have 7 nutrient treatment plots, each replicated once in 3 blocks. The treatments are: control, N, P, K, NPK, f_cont...
Lisanne

0

144

Views

### Straight-forward AND open-source alternatives to asreml-r for spatial models?

In the past, I have used asreml-r to account for spatial auto-correlation in agricultural field trials that were laid out in a “row and range” design. It is relatively easy to use the asreml package to specify a spatial model (i.e. rcov=~at(LOCATION):ar1(ROW):ar1(RANGE)) Unfortunately, asreml-r...
Nic George

2

185

Views

### Looking for a post hoc for a type 2 Anova (mixed-effects model)

My question is how do I run a post hoc on a type 2 Anova (mixed-effects model)? So far I am using the glmer() from the 'lme4' package, the Anova() from the 'car' package, and trying to run a HSD test from the 'agricolae' package. After searching for some time this is the best that I could find, how...
Maria

0

158

Views

### Convergence issues with GLMM from lme4

I am new to mixed models and am having some trouble getting my models to converge. I've looked at the other questions on Stack Overflow and elsewhere and worked through this sheet, but with no luck. I have several variables derived from sweep net transects and pitfall traps, such as abundance, diver...
James

0

46

Views

### Plotting mixed models in ggplot

I constructed a mixed model and now using sjp.lmer, I am plotting predicted values against each of my predictor. The name of the fitted model is mdl.lmer and the names.vec is the vector of names of the predictor.I want to do a loop like this such that the all plots are present in a single pdf pdf('m...
Crop89

0

22

Views

### lmer mixte multilevel regression not working on data without noise

I there. I am encountering some problems with the lmer function. I am trying to test it on simple data, and I don't get what I expected but warnings and errors. Here is the example library(lme4) library(lme4) library(data.table) library(ggplot2) set.seed(115) Nid = 20 Nx = 15 b
denis

0

42

Views

### in R, find Cholesky of a crossproduct (e.g. XtX) without forming XtX

In the lme4 vignette named Computational Methods (if that link doesn't work, go here and then click on 'Computational Methods') Doug Bates mentions that the Cholesky factorization of XtX can be taken with CHOLMOD without forming XtX (that is, just using Xt) (page 18, right after equation 54). Is tha...
pdb

0

31

Views

### Account for a factor variability in a logistic GLMM in lme4

We did a field study in which we tried to understand which factors significantly explain the probability of a group of animals (5 species in total) crossing through 30 wildlife road-crossing structures. The response variable is binomial (yes=crossed; no = did not cross) and was recorded by animal sp...
user7618183

0

132

Views

### Multiple random effects without interaction in nlme::lme

Let consider this simple model consisting in two independent random effects: $$y_{ijk} = \mu + \delta1_i + \delta2_j + \epsilon_{i,j,k}$$ where \delta1_i and \delta2_j are independent random effect (i.e. \delta1_i \sim N(0,\sigma_1^2) iid, \delta2_i \sim N(0,\sigma_1^2) iid, both independent). Defin...
user1835313

0

29

Views

I am feeling a bit lost in analyzing my counterbalanced within-subject experimental data and I need to know if I am on the right track. I ran a small pilot study where I randomly assigned participants to 4 counterbalanced conditions because I had 4 levels in a within-subject factor. So the four coun...
Kaelyn S.

0

56

Views

### lme4 level-2 residual covariance and standard error

I'm trying to reproduce the examples in Multilevel Analysis by Snijders & Bosker but I can't find how to calculate S.E. of the covariance of the level-2 residual. I found 2 related questions on SO: Extracting covariance of level-2 residuals from lme4 output Standard Error of variance component from...
leoce

1

185

Views

### Error when estimating CI for GLMM using confint()

I have a set of GLMM's fitted with a binary response variable and a set of continuous variables, and I would like to get confidence intervals for each model. I've been using confint() function, at 95% and with the profile method, and it works without any problems if it is applied to a model with no...
Teresa

0

29

Views

### how random structures affect the results of fixed effects?

I want to ask about linear mixed models. The significance of the fixed variable is changed with a random structure. For example, suppose there are 5 variables: RT(response variable), covariate variable1(C.V.1), C.V.2, I.V.1, I.V.2. all variables are within-subject variables excepting RT. What I want...
Soyoung

0

31

Views

### Specifying random effect nested under an interaction of fixed effects

Probably an easy one. I have data with fixed and random effects I'd like to fit a mixed effects model to: set.seed(1) df
dan

0

116

Views

### Syntax for glmer function for use with glmulti?

Using glmer, I can run a logistic regression mixed model just fine. But when I try to do the same using glmulti, I get errors (described below). I think the problem is with the function I am specifying for use in glmulti. I want a function that specifies a logistic regression model for data containi...
Emily

0

27

Views

### Confidence Intervals for prediction of a logistic generalized linear mixed model (GLMM)

I am running a logistic generalized linear mixed model and would like to plot my effects together with confidence intervals. I use the lme4 package to fit my model: glmer (cbind(positive, negative) ~ F1 * F2 * F3 + V1 + F1 * I(V1^2) + V2 + F1 * I(V2^2) + V3 + I(V3^2) + V4 + I(V4^2) + F4 + (1|OLRE)...

0

169

Views

### Error: Invalid grouping factor specification, Subject

I'm trying to run a multilevel logistic regression model in R. Here is my model: modA
Yvette Graveline

1

79

Views

### How to extract slope and intercept values for different groups from interact_plots in jtools when plotting linear fixed effects models

I am trying to extract the slope and intercept for each of my groups from my linear mixed effects models. The model was constructed using lmer in the lme4 library, and I can view the results for each group using interact_plot from the jtools library. How do I get the slope and intercept for each of...
stets

0

20

Views

### random slope only for certain level in mixed model

I have a model of the form lmer(y ~ x1 + I(x1^2) + x2 + I(x2^2) + x3 + (x3|level1/level2)) If I want x1 to vary depending on the level1 and 2 lmer(y ~ x1 + I(x1^2) + x2 + I(x2^2) + x3 + (x3 + x1 + I(x1^2)|level1/level2)) How do I allow x1 + I(x1^2) to vary only according to level1 and not level2. Is...
Crop89

0

39

Views

### R: Covariance matrix for the random effect in mixed effects model

According to this post, matrix Omega and sigma are in the results of lmer when we fitting the mixed effect model. And here is my result. Random effects: Groups Name Variance Std.Dev. Corr subject X21 8.558e+00 2.925380 X22 2.117e-03 0.046011 -1.00 X23 2.532e-05 0.0050...
Nan