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

栏目: R语言 · 发布时间: 7年前

内容简介:http://stackoverflow.com/questions/33316686/r-plotting-predictions-of-mass-polr-ordinal-model

我使用MASS的polr函数(在这种情况下是给不同种类的奶酪的数据),在序数数据上使用比例赔率累积logit模型:

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")

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

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

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

我想知道,如果从预期的方式报告的效果包,也可以绘制像每种奶酪的平均喜好与95%conf间隔这一点?

编辑:原来我也问过如何获得Tukey posthoc测试,但同时我发现那些可以使用

library(multcomp)
summary(glht(fit, mcp(cheese = "Tukey")))

或使用包lsmeans as

summary(lsmeans(fit, pairwise ~ cheese, adjust="tukey", mode = "linear.predictor"),type="response")

Russ Lenth只是向我指出,只需使用选项模式=“平均值”(?模型)的lsmeans即可获得平均偏好和95%置信区间(同样适用于使用包序号的clm或clmm模型) :

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

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

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)

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

http://stackoverflow.com/questions/33316686/r-plotting-predictions-of-mass-polr-ordinal-model


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Hacking Growth

Hacking Growth

Sean Ellis、Morgan Brown / Crown Business / 2017-4-25 / USD 29.00

The definitive playbook by the pioneers of Growth Hacking, one of the hottest business methodologies in Silicon Valley and beyond. It seems hard to believe today, but there was a time when Airbnb w......一起来看看 《Hacking Growth》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具