在R中使用glm(..)获得95%的置信区间 [英] Get 95% confidence interval with glm(..) in R
本文介绍了在R中使用glm(..)获得95%的置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一些数据
dat = data.frame(y = c(9,7,7,7,5,6,4,6,3,5,1,5), x = c(1,1,2,2,3,3,4,4,5,5,6,6), color = rep(c('a','b'),6))
以及这些数据的绘图
require(ggplot)
ggplot(dat, aes(x=x,y=y, color=color)) + geom_point() + geom_smooth(method='lm')
使用功能 MCMCglmm()
…
require(MCMCglmm)
summary(MCMCglmm(fixed = y~x/color, data=dat))
我得到了估计值的上下95%的间隔,使我知道两个斜率(颜色= a和颜色= b)是否显着不同.
I get the lower and upper 95% interval for the estimate allowing me to know if the two slopes (color = a and color = b) are significantly different.
查看此输出时...
summary(glm(y~x/color, data=dat))
...我看不到置信区间!
... I can't see the confidence interval!
我的问题是:
使用函数 glm()
时,如何对估计值具有上下95%的置信度?
How can I have these lower and upper 95% interval confidence for the estimates when using the function glm()
?
推荐答案
使用 confint
mod = glm(y~x/color, data=dat)
summary(mod)
Call:
glm(formula = y ~ x/color, data = dat)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.11722 -0.40952 -0.04908 0.32674 1.35531
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 8.8667 0.4782 18.540 0.0000000177
x -1.2220 0.1341 -9.113 0.0000077075
x:colorb 0.4725 0.1077 4.387 0.00175
(Dispersion parameter for gaussian family taken to be 0.5277981)
Null deviance: 48.9167 on 11 degrees of freedom
Residual deviance: 4.7502 on 9 degrees of freedom
AIC: 30.934
Number of Fisher Scoring iterations: 2
confint(mod)
Waiting for profiling to be done...
2.5 % 97.5 %
(Intercept) 7.9293355 9.8039978
x -1.4847882 -0.9591679
x:colorb 0.2614333 0.6836217
这篇关于在R中使用glm(..)获得95%的置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文