lme4

How to plot mixed-effects model estimates in ggplot2 in R?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 04:34:15
I have a 2x2x2 factorial design with one random effect. The data (dat) is as follows: colour size level marbles set Blue Large Low 80 1 Blue Large High 9 2 Blue Small Low 91 1 Blue Small High 2 1 White Large Low 80 2 White Large High 9 1 White Small Low 91 2 White Small High 2 1 I want to plot two models: mod1 <- lmer(marbles ~ colour + size + level + colour:size + colour:level + size:level + (1|set), data = dat) mod2 <- lmer(marbles ~ colour + size + level +(1|set), data = dat) I usually use the following code to do my plots: pd <- position_dodge(0.82) ggplot(dat, aes(x=colour, y=marbles,

fitting a linear mixed model to a very large data set

喜夏-厌秋 提交于 2019-12-06 03:01:14
问题 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 intercept term. I have 64-bit R and 16Gb RAM and I'm working from a central server. RStudio is the most recent server version. model <- lmer(tc~sex+age+lho+atc+(1|patient), data=master,REML=TRUE) lho sex tc age atc patient 18 M 16.61 45-54 H 628143

How to specify different random effects in nlme vs. lme4?

自闭症网瘾萝莉.ら 提交于 2019-12-06 02:04:18
问题 I want to specify different random effects in a model using nlme::lme (data at the bottom). The random effects are: 1) intercept and position varies over subject ; 2) intercept varies over comparison . This is straightforward using lme4::lmer : lmer(rating ~ 1 + position + (1 + position | subject) + (1 | comparison), data=d) > ... Random effects: Groups Name Std.Dev. Corr comparison (Intercept) 0.31877 subject (Intercept) 0.63289 position 0.06254 -1.00 Residual 0.91458 ... However, I want to

lmer error: grouping factor must be < number of observations

扶醉桌前 提交于 2019-12-05 18:20:23
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"), class = "factor"), speed = c(0.0296315046039244, 0.0366986630049636, 0.0294297725505692, 0

Post-hoc test for glmer

为君一笑 提交于 2019-12-05 06:18:56
I'm analysing my binomial dataset with R using a generalized linear mixed model (glmer, lme4-package). I wanted to make the pairwise comparisons of a certain fixed effect ("Sound") using a Tukey's post-hoc test (glht, multcomp-package). Most of it is working fine, but one of my fixed effect variables ("SoundC") has no variance at all (96 times a "1" and zero times a "0") and it seems that the Tukey's test cannot handle that. All pairwise comparisons with this "SoundC" give a p-value of 1.000 whereas some are clearly significant. As a validation I changed one of the 96 "1"'s to a "0" and after

rank deficiency warning mixed model lmer

无人久伴 提交于 2019-12-05 02:55:57
问题 I have a dataset with 142 data entries: 121 individuals measured on two occasions (two years, before and after treatment, Year = 0 or 1), in the second year 46 individuals were in treated plots and the rest were in control plots (treatment = 0 or 1). Here's some example data: ID <- c("480", "480", "620", "620","712","712") Year <- c("0", "1", "0", "1","0", "1") Plot <- c("14", "14", "13", "13","20","20") Treat <- c("0", "0", "0", "1", "0", "1") Exp <- c("31", "43", "44", "36", "29", "71")

Prediction with lme4 on new levels

﹥>﹥吖頭↗ 提交于 2019-12-04 21:09:05
问题 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 doesn't seem to be the case. Here's a minimum working example: library(lme4) d = data.frame(x = rep(1:10, times = 3), y = NA, grp = rep(1:3, each = 10)) d$y[d$grp == 1] = 1:10 + rnorm(10) d$y[d$grp == 2] = 1:10 * 1.5 + rnorm(10) d$y[d$grp == 3] = 1:10

Frequency weights in R (multilevel using lme4)

廉价感情. 提交于 2019-12-04 19:42:05
I'm building a multilevel model with lme4 (two levels: a class and a student level with educational data). I'm using the ICCS 2009 data: http://www.iea.nl/iccs_2009.html ). ICCS 2009 advise the use weights. I made a “within-school student weight” as the product of the class and student level weight factors. I also made the sums of the weights equal to the sample size. My question: how can I specify in R that I want to use this weight as a frequency weight. Do I have to use the "survey" package? iccs is a complex survey (see chapter 3 of the user guide) and the R survey package cannot (yet)

lme4::glmer vs. Stata's melogit command

社会主义新天地 提交于 2019-12-04 19:36:42
问题 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 for – maybe 50 or so fixed effects. I’m fitting the model to a binary outcome using lme4::glmer in R, with random intercepts for each subject. I can't go into specifics on the data, but the basic format of the glmer command I used was: fit <- glmer

Plotting results of lme4 with ggplot2

我是研究僧i 提交于 2019-12-04 17:31:42
I used lme4 for a linear mixed-effects model lme.m1 <- lmer(I1 ~ P1 + Period * Actor + (1 | Actor), data=Q) There are 8 Actors and I have three Periods. Now I would like to plot (using ggplot2) the different lines in 8 different facets (which does not seem to be difficult). However, I do not know how to draw three different lines (because of the three different periods) for each actor in the same facet. I used the following code from http://www.sagepub.com/long/chapters/rcode/82689_10rc.txt : plot.m1 <- data.frame(lme.m1@frame, fitted.re = fitted(lme.m1)) head(plot.m1) fixed.m1 <- data.frame