R:绘制MASS polr序数模型的预测

Tom*_*ers 15 r posthoc categorical-data lsmeans

我安装在序数据的比例优势累计逻辑模型使用MASSpolr使用功能(在这种情况下,数据给出了不同种类的奶酪偏好):

data=read.csv("https://www.dropbox.com/s/psj74dx8ohnrdlp/cheese.csv?dl=1")
data$response=factor(data$response, ordered=T) # make response into ordered factor
head(data)
  cheese response count
1      A        1     0
2      A        2     0
3      A        3     1
4      A        4     7
5      A        5     8
6      A        6     8
library(MASS)
fit=polr(response ~ cheese, weights=count, data=data, Hess=TRUE, method="logistic")
Run Code Online (Sandbox Code Playgroud)

为了绘制模型的预测,我使用了一个效果图

library(effects)
library(colorRamps)
plot(allEffects(fit),ylab="Response",type="probability",style="stacked",colors=colorRampPalette(c("white","red"))(9))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想知道,如果根据effects包装报告的预测方法,还可以绘制类似于每种奶酪的平均偏好以及95%的配置间隔吗?

编辑:最初我也问过如何获得Tukey posthoc测试,但在此期间我发现那些可以使用

library(multcomp)
summary(glht(fit, mcp(cheese = "Tukey")))
Run Code Online (Sandbox Code Playgroud)

或使用包lsmeans作为

summary(lsmeans(fit, pairwise ~ cheese, adjust="tukey", mode = "linear.predictor"),type="response")
Run Code Online (Sandbox Code Playgroud)

Tom*_*ers 2

Russ Lenth 善意地向我指出,可以简单地使用lsmeans( option mode="mean")获得平均偏好和 95% 置信区间?models(同样也适用于使用 package 的 aclmclmm模型拟合ordinal):

df=summary(lsmeans(fit, pairwise ~ cheese, mode = "mean"),type="response")$lsmeans
 cheese mean.class        SE df asymp.LCL asymp.UCL
 A        6.272828 0.1963144 NA  5.888058  6.657597
 B        3.494899 0.2116926 NA  3.079989  3.909809
 C        4.879440 0.2006915 NA  4.486091  5.272788
 D        7.422159 0.1654718 NA  7.097840  7.746478
Run Code Online (Sandbox Code Playgroud)

这给了我我正在寻找的情节:

library(ggplot2)
library(ggthemes)
ggplot(df, aes(cheese, mean.class)) + geom_bar(stat="identity", position="dodge", fill="steelblue", width=0.6) + 
     geom_errorbar(aes(ymin=asymp.LCL, ymax=asymp.UCL), width=0.15, position=position_dodge(width=0.9)) + 
     theme_few(base_size=18) + xlab("Type of cheese") + ylab("Mean preference") + 
     coord_cartesian(ylim = c(1, 9)) + scale_y_continuous(breaks=1:9)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述