0

I'm trying to plot a bar chart with standard error bars using lsmeans, but I keep getting the same error message:

Error in FUN(X[[i]], ...) : object 'lsmean' not found

I've tried all sorts of different codes to achieve this and never manage to do it.

My model is:

model<-lmer(data=data, Y~X1+X2+X3+X4+(1|Individual))

My lsmeans code (I have back transformed the data after a log transformation on Y:

lsmeans(model,
        ~ X1,
        adjust="tukey")  

X1.post <- lsmeans(model, pairwise ~ X1, type = "response")
X1.post

The code I have just tried is:

ggplot(data) +
  geom_bar( aes(x=X1, y=lmean), stat="identity", fill="skyblue", alpha=0.5) +
  geom_crossbar( aes(x=X1, y=lsmean, ymin=lsmean-se, ymax=lsmean+se), width=0.4, colour="orange", alpha=0.9, size=1.3)

I want to report the lsmeans for X1 which has 5 levels. Please could anyone advise on which code I can use for this purpose?

user438383
  • 5,716
  • 8
  • 28
  • 43
PMan
  • 1
  • Welcome to SO, we will do our best to help but we need more info. Please provide data so that we can reproduce your code, such as pasting the output of `dput(data)` . Also see this info on making a post: https://stackoverflow.com/help/minimal-reproducible-example – sjp Sep 08 '21 at 08:20
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Sep 08 '21 at 15:57
  • It looks to me like your ggplot code requires `data` to have a variable named `lsmean` -- since that code makes no reference to the results of your `lsmeans()` call. Maybe you want to use `as.data.frame(X1.post[[1]])` instead of `data`? – Russ Lenth Sep 15 '21 at 23:36

0 Answers0