1

The lsmip() command in the lsmeans package seems to treat continuous predictors on the x-axis as categorical predictors.

If I have observations from my continuous predictors at discrete but uneven intervals, (such as when you remove the 0.2 level of nitro from the Oats data), lsmip plots them at even intervals anyway.

data("Oats", package = "nlme")
Oats.lmer2sub <- lmer(log(yield) ~ Variety + poly(nitro,2)
               + (1|Block/Variety),  data = subset(Oats, nitro!=0.2))
lsmip(Oats.lmer2sub, Variety ~ nitro, ylab = "Predicted log(yield)", cov.reduce=FALSE)

enter image description here

This seems important to me if I want to show the model predictions at the levels of nitro where I actually observed the data. Theoretically, I should be able to show predicted values at any level of nitro.

lsmip(Oats.lmer2sub, Variety ~ nitro, ylab = "Predicted log(yield)", at=list(nitro=c(0, 0.2, 0.4, 0.45, 0.46,  0.6)))

enter image description here

Is there any way to set the x-axis to space the values of nitro to a scale appropriate for a continuous variable? Meaning skip a space for 0.2 in the first graph, or cluster together the points for 0.45, 0.46 in the second graph?

emudrak
  • 789
  • 8
  • 25
  • No. That function was designed just to make interaction-style plots with factors. However, you can do `df <- lsmip(..., plotit = FALSE)` to save the values in a data frame, and then use some other plotting function to make the plot you want. – Russ Lenth Apr 08 '17 at 03:17

1 Answers1

1

You can save the plotted data in a data frame, then plot those results however you want. In your example:

plotdf <- lsmip(Oats.lmer2sub, Variety ~ nitro, 
          at=list(nitro=c(0, 0.2, 0.4, 0.45, 0.46,  0.6)), 
          plotit = FALSE)

library(lattice)
xyplot(lsmean ~ nitro, groups = ~Variety, 
       type = "o", ylab = "Predicted log(yield)", data = plotdf)

Resulting plot

Community
  • 1
  • 1
Russ Lenth
  • 5,922
  • 2
  • 13
  • 21