[R-sig-ME] Plotting means and error bars for fixed effects in a ME model
chelucero at uchicago.edu
Sun Feb 7 22:51:40 CET 2016
dat <- expand.grid(Condition = c('A', 'B'), Subject = 1:10,
Item = c('popcorn', 'butter', 'rosemary', 'salt',
dat$Subject <- factor(dat$Subject)
size <- nrow(dat)
dat$DV <- numeric(size)
dat[dat$Condition == 'A', 'DV'] <- rnorm(size/2, 8, 1)
dat[dat$Condition == 'B', 'DV'] <- rnorm(size/2, 9, 1)
barplot(tapply(dat$DV, dat$Condition, FUN=mean))
m.1 <- lmer(DV ~ Condition + (1|Subject) + (1|Item), data=dat)
m.2 <- update(m.1, . ~ . - Condition)
I don't want a standard error on anything from the model per se. I want to
build a standard error of the mean for the two Condition means for
charting. My example lmer model takes two random effects into account:
Subject and Item. I want to make a plot in which the standard error of the
mean takes into account both the Subject and Item variance (like my model).
I am only aware of how construct the standard error of the mean taking one
of those into account at a time. Hope I was clearer this time!
On Sun, Feb 7, 2016 at 3:21 PM Paul Johnson <pauljohn32 at gmail.com> wrote:
> On Sun, Feb 7, 2016 at 2:56 PM, Ché Lucero <chelucero at uchicago.edu> wrote:
> > Hello, list.
> > I have a question about error bars on barplotted means of data that has
> > been analyzed with mixed effects models.
> > Mixed effects models allow us to simultaneously model variance from
> > multiple random-effects sources (such as Subjects and Items), a much
> > solution to a problem pointed out (most potently) in my field by Herb
> > in 1973.
> You will get better help if you rephrase your question with a fitted
> lme4 object and let us see what you are trying to do. As it is, your
> question asks us to wade throught a lot of ANOVA jargon. I'd rather
> see your model, data, and the number for which you want the CI.
> It appears that even for glm without random effects, there is no
> settled upon idea for CI on predicted values. You can fall down a
> rabbit hole reading math articles about that. I don't think the
> presence of random effects makes that tougher, its just another
> element to add in the error bands. The model you specify when you fit
> dictates what's correlated.
> I had to improvise some CIs last semester. In the package "arm"
> (support for the Gelman & Hill textbook), there's a function called
> se.coef and they do the usual plus or minus 2 of those to make error
> bars that look like CIs for predicted values. That works because if
> you calculate some linear sum, you can use the variances of individual
> elements to get a Wald type CI.
> I am pretty sure the best answer is simulation with lme4 objects,
> however. But don't have code to share to you.
> Good luck, think about showing everybody code and such that they can focus
> > However, to my knowledge, calculating confidence interval/SEM for means
> > not advanced to take this modeling approach into account. A series of
> > papers - Loftus and Masson 94 (Using confidence intervals in
> > designs) Cousineau 05 (Confidence intervals in within-subject designs:
> > simpler solution) and Morey 05 (Confidence Intervals from Normalized
> > A correction to Cousineau) has specified ways to calculate error bars
> > which the within-Subject error has been accounted for.
> > That approach to calculating error bars for plotting seems to be well
> > matched for when the statistical procedure is a simple repeated measures
> > (for Subjects OR Items) ANOVA. But what about the case where I have both
> > within-Subjects and within-Items (and within-XYZ random factors too)? Is
> > there a way to construct standard errors of the mean for levels of a
> > factor (e.g. Condition) taking more than one random-effect into account
> > mixed effects models do? It would be really great to have the charts
> > visually suggest the same inferences that the ME statistics do, but I
> > find any literature about it.
> > Thanks for your time.
> > -Ché
> > [[alternative HTML version deleted]]
> > _______________________________________________
> > R-sig-mixed-models at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> Paul E. Johnson
> Professor, Political Science Director
> 1541 Lilac Lane, Room 504 Center for Research Methods
> University of Kansas University of Kansas
> http://pj.freefaculty.org http://crmda.ku.edu
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models