lmer

plot mixed effects model in ggplot

别来无恙 提交于 2019-12-03 18:26:54
问题 I am new with mixed effect models and I need your help please. I have plotted the below graph in ggplot: ggplot(tempEf,aes(TRTYEAR,CO2effect,group=Myc,col=Myc)) + facet_grid(~N) + geom_smooth(method="lm",se=T,size=1) + geom_point(alpha = 0.3) + geom_hline(yintercept=0, linetype="dashed") + theme_bw() However, I would like to represent a mixed effects model instead of lm in geom_smooth , so I can include SITE as a random effect. The model would be the following: library(lme4) tempEf$TRTYEAR <-

How to plot random intercept and slope in a mixed model with multiple predictors?

[亡魂溺海] 提交于 2019-12-03 07:38:50
Is it possible to plot the random intercept or slope of a mixed model when it has more than one predictor? With one predictor I would do like this: #generate one response, two predictors and one factor (random effect) resp<-runif(100,1, 100) pred1<-c(resp[1:50]+rnorm(50, -10, 10),resp[1:50]+rnorm(50, 20, 5)) pred2<-resp+rnorm(100, -10, 10) RF1<-gl(2, 50) #gamm library(mgcv) mod<-gamm(resp ~ pred1, random=list(RF1=~1)) plot(pred1, resp, type="n") for (i in ranef(mod$lme)[[1]]) { abline(fixef(mod$lme)[1]+i, fixef(mod$lme)[2]) } #lmer library(lme4) mod<-lmer(resp ~ pred1 + (1|RF1)) plot(pred1,

How does lmer (from the R package lme4) compute log likelihood?

依然范特西╮ 提交于 2019-12-02 21:05:11
I'm trying to understand the function lmer. I've found plenty of information about how to use the command, but not much about what it's actually doing (save for some cryptic comments here: http://www.bioconductor.org/help/course-materials/2008/PHSIntro/lme4Intro-handout-6.pdf ). I'm playing with the following simple example: library(data.table) library(lme4) options(digits=15) n<-1000 m<-100 data<-data.table(id=sample(1:m,n,replace=T),key="id") b<-rnorm(m) data$y<-rand[data$id]+rnorm(n)*0.1 fitted<-lmer(b~(1|id),data=data,verbose=T) fitted I understand that lmer is fitting a model of the form

How to modify slots lme4 >1.0

▼魔方 西西 提交于 2019-12-02 10:50:07
问题 I have been using the code below to successfully modify the 'Zt', 'L', and 'A' slots of models fit using lme4 versions <1.0. I just updated to lme4 1.0-4 today and found that the model objects are different. Can anyone provide insight/guidance as to how to modify these slots in the new lmer model objects? dat<-structure(list(pop1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 10L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L,

What does this mean in lme4: function 'dataptr' not provided by package 'Rcpp'

故事扮演 提交于 2019-12-01 05:34:31
问题 I'm trying to do LMM using lme4, and this message pops up: Error in initializePtr() : function 'dataptr' not provided by package 'Rcpp' What should I do? 回答1: After a while, I got it. 1) Reinstall the latest version of Rcpp is the solution. 2) If you are not using lme4, but you also have this problem ("function 'dataptr' not provided by package 'Rcpp'") in combination with dyn.load(), it might be worth noting do not forget to include library(Rcpp) or require(Rcpp) on your code before dyn.load

increase iterations for new version of lmer?

夙愿已清 提交于 2019-11-30 06:38:10
问题 I just updated lme4 to version 1.0-4 and when I run lmer() my mixed effects model, which was converging before, now prints this warning: Warning message: In (function (fn, par, lower = rep.int(-Inf, n), upper = rep.int(Inf, : failure to converge in 10000 evaluations So, I'd like to try to increase the number of iterations to see if I can fix this. (I must say I have no idea what is causing the warning, as the first part of the message sounds a bit opaque). In any case, I read in the

plot mixed effects model in ggplot

不羁的心 提交于 2019-11-29 21:44:16
I am new with mixed effect models and I need your help please. I have plotted the below graph in ggplot: ggplot(tempEf,aes(TRTYEAR,CO2effect,group=Myc,col=Myc)) + facet_grid(~N) + geom_smooth(method="lm",se=T,size=1) + geom_point(alpha = 0.3) + geom_hline(yintercept=0, linetype="dashed") + theme_bw() However, I would like to represent a mixed effects model instead of lm in geom_smooth , so I can include SITE as a random effect. The model would be the following: library(lme4) tempEf$TRTYEAR <- as.numeric(tempEf$TRTYEAR) mod <- lmer(r ~ Myc * N * TRTYEAR + (1|SITE), data=tempEf) I have included

How to unscale the coefficients from an lmer()-model fitted with a scaled response

删除回忆录丶 提交于 2019-11-28 09:24:11
I fitted a model in R with the lmer() -function from the lme4 package. I scaled the dependent variable: mod <- lmer(scale(Y) ~ X + (X | Z), data = df, REML = FALSE) I look at the fixed-effect coefficients with fixef(mod) : > fixef(mod) (Intercept) X1 X2 X3 X4 0.08577525 -0.16450047 -0.15040043 -0.25380073 0.02350007 It is quite easy to calculate the means by hand from the fixed-effects coefficients. However, I want them to be unscaled and I am unsure how to do this exactly. I am aware that scaling means substracting the mean from every Y and deviding by the standard deviation. But both, mean

In R, plotting random effects from lmer (lme4 package) using qqmath or dotplot: how to make it look fancy?

随声附和 提交于 2019-11-28 02:47:50
The qqmath function makes great caterpillar plots of random effects using the output from the lmer package. That is, qqmath is great at plotting the intercepts from a hierarchical model with their errors around the point estimate. An example of the lmer and qqmath functions are below using the built-in data in the lme4 package called Dyestuff. The code will produce the hierarchical model and a nice plot using the ggmath function. library("lme4") data(package = "lme4") # Dyestuff # a balanced one-way classiï¬cation of Yield # from samples produced from six Batches summary(Dyestuff) # Batch is

How to unscale the coefficients from an lmer()-model fitted with a scaled response

送分小仙女□ 提交于 2019-11-27 02:24:57
问题 I fitted a model in R with the lmer() -function from the lme4 package. I scaled the dependent variable: mod <- lmer(scale(Y) ~ X + (X | Z), data = df, REML = FALSE) I look at the fixed-effect coefficients with fixef(mod) : > fixef(mod) (Intercept) X1 X2 X3 X4 0.08577525 -0.16450047 -0.15040043 -0.25380073 0.02350007 It is quite easy to calculate the means by hand from the fixed-effects coefficients. However, I want them to be unscaled and I am unsure how to do this exactly. I am aware that