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


i have 2x2x2 factorial design 1 random effect. data (dat) 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 plot 2 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 use following code plots:

pd <- position_dodge(0.82)   ggplot(dat, aes(x=colour, y=marbles, fill = level)) + theme_bw() +    stat_summary(geom="bar", fun.y=mean, position = "dodge") +     stat_summary(geom="errorbar", fun.data=mean_cl_boot, position = pd)+   + facet_grid(~size) 

i'm unsure on how replace terms coefficients model estimates. ideas on how can plot estimates of final model in gpplot2? helpful if can suggest easy way print model estimates too

in addition, there anyway can ggplot2 display bars on top of graphs showing interactions significant?

here's 1 approach plotting predictions linear mixed effects model factorial design. can access fixed effects coefficient estimates fixef(...) or coef(summary(...)). can access random effects estimates ranef(...).

library(lme4) 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)  dat$preds1 <- predict(mod1,type="response") dat$preds2 <- predict(mod2,type="response")  dat<-melt(dat,1:5)  pred.plot <- ggplot() +   geom_point(data = dat, aes(x = size, y = value,                              group = interaction(factor(level),factor(colour)),                             color=factor(colour),shape=variable)) +   facet_wrap(~level) +   labs(x="size",y="marbles") 

enter image description here

these fixed effects predictions data presented in post. points colors overlapping, depend on data included in model. combination of factors choose represent via axes, facets, or shapes may shift visual emphasis of graph.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -