lme4

lmer error: grouping factor must be < number of observations

本秂侑毒 提交于 2020-01-02 06:39:31
问题 I am attempting to run a mixed effect model on some data but struggling with one of the fixed effects, I think primarily due to it a factor?! Sample data: data4<-structure(list(code = structure(1:10, .Label = c("10888", "10889", "10890", "10891", "10892", "10893", "10894", "10896", "10897", "10898", "10899", "10900", "10901", "10902", "10903", "10904", "10905", "10906", "10907", "10908", "10909", "10910", "10914", "10916", "10917", "10919", "10920", "10922", "10923", "10924", "10925", "10927"

Errors trying to run glmer with paired data and repeated measures (lme4)

守給你的承諾、 提交于 2020-01-01 19:27:08
问题 I want to analyze the effect of 2 treatments on the variation of the abundance of a plant species along a time gradient. The experimental design consist of exclosures (treatment = no moose), paired with control plots (treatment = moose). A site consist of 1 exclosure + 1 control plot. There are 15 sites (so 15 exclosures + 15 paired plots = 30 experimental units). Each experimental units has is unique "id". The abundance (proportion : continuous value between 0 and 1) of fir has been

How to predict and graph non-linear varying slopes in lmer or glmer?

≡放荡痞女 提交于 2020-01-01 05:48:05
问题 My goal is to calculate predicted values from a varying-intercept, varying-slope multilevel model using the lmer and glmer functions of the lme4 package in R. To make this concrete and clear, I present here a toy example with the "mtcars" data set: Here's how I usually create predicted values from a varying-intercept, varying-slope multilevel model (this code should work just fine): # loading in-built cars dataset data(mtcars) # the "gear" column will be the group-level factor, so we'll have

Plotting predicted values from lmer as a single plot

廉价感情. 提交于 2020-01-01 03:44:07
问题 I am working on graphing the predicted values from a multilevel model (using the lme4 package). I am able to do this successfully using the Effect() function. As shown below: library(lme4) library(effects) m1=lmer(price~depth*cut+(1|cut),diamonds) plot(Effect(c("cut","depth"),m1)) But, I want to present these same data as a single plot with a legend. Using ggplots, I can do this; but, I lose the error bars, as shown below: ggplot(data.frame(Effect(c("cut","depth"),m1)), aes(x=depth,y=fit

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

五迷三道 提交于 2019-12-31 09:16:16
问题 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 = lme(response ~ fixed1 + fixed2, random = ~1 | random1, method="REML",data) AIC(mod1,mod2) Is there something similar to gls() for the lme4 package which would allow me to build mod3 with no random effects and compare it to mod4 built using lmer() which does

Fixing variance values in lme4

一笑奈何 提交于 2019-12-29 06:30:29
问题 I am using the lme4 R package to create a linear mixed model using the lmer() function. In this model I have four random effects and one fixed effect (intercept). My question is about the estimated variances of the random effects. Is it possible to specify initial values for the covariance parameters in a similar way as it can be done in SAS with the PARMS argument. In the following example, the estimated variances are: c(0.00000, 0.03716, 0.00000, 0.02306) I would like to fix these to (for

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

核能气质少年 提交于 2019-12-28 04:49:22
问题 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 function from lme4 package. But then, functions coef and confint do not work any more for me! > mix1 = lmer(resp ~ 0 + var1 + var1:var2 + (1|var3)) # var1, var3 categorical, var2 continuous > coef(mix1) Error in coef(mix1) : unable to align random and

warning messages using glmer function from lme4 package R

∥☆過路亽.° 提交于 2019-12-24 19:02:05
问题 I am trying to fit a logistic random intercept model using glmer function from package lme4. Unfortunately I am getting the following warning messages and clearly wrong results (for the coefficients). Warning messages: 1: In vcov.merMod(object, use.hessian = use.hessian) : variance-covariance matrix computed from finite-difference Hessian is not positive definite: falling back to var-cov estimated from RX 2: In vcov.merMod(object, correlation = correlation, sigm = sig) : variance-covariance

lmerTest:::anova uses lazy loading of data sets?

*爱你&永不变心* 提交于 2019-12-24 10:57:44
问题 Ran into this problem while trying to get the empirical distribution of the K-R degrees of freedom... This seems like fairly dangerous behaviour? Does it constitute a bug? Reproducible example: ## import lmerTest package library(lmerTest) ## an object of class merModLmerTest m <- lmer(Informed.liking ~ Gender+Information+Product +(1|Consumer), data=ham) # simulate data from fitted model simData=ham simData$Informed.liking=unlist(simulate(m)) # fit model to simulated data m1 <- lmer(Informed

Extracting covariance of level-2 residuals from lme4 output

人盡茶涼 提交于 2019-12-24 08:14:06
问题 I need to know how to extract the level-2 residual covariance from a random-slopes lmer object. library(lme4) fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy) summary(fm1) This is the random effects table Random effects: Groups Name Variance Std.Dev. Corr Subject (Intercept) 612.09 24.740 Days 35.07 5.922 0.07 Residual 654.94 25.592 Number of obs: 180, groups: Subject, 18 I know that the value 0.07 under the Corr is the covariance correlation coefficient and I can use this to