[英]Confidence intervals on predictions for a Bayesian linear regression model
我正在寻找关于贝叶斯线性回归(MHadaptive)的优秀文章
给出后可信区间的输出
BCI(mcmc_r)
# 0.025 0.975
# slope -5.3345970 6.841016
# intercept 0.4216079 1.690075
# epsilon 3.8863393 6.660037
我现在使用什么函数从这些参数构建具有置信区间的模型?
为什么不使用从MCMC获得的分布来预测从任何点x
的y
的分布? 在您正在使用的示例中,以下是相关部分,其中eggmass = y且length = x
##@ 3.1 @##
## Function to compute predictions from the posterior
## distribution of the salmon regression model
predict_eggmass<-function(pars,length)
{
a <- pars[, 1] #intercept
b <- pars[, 2] #slope
sigma <- pars[, 3] #error
pred_mass <- a + b * length
pred_mass <- rnorm(length(a), pred_mass, sigma)
return(pred_mass)
}
### -- ###
##@ 3.2 @##
## generate prediction
pred_length <- 80 # predict for an 80cm individual
pred <- predict_eggmass(mcmc_salmon$trace, length=pred_length)
## Plot prediction distribution
hist(pred, breaks=30, main='', probability=TRUE)
## What is the 95% BCI of the prediction?
pred_BCI <- quantile(pred, p=c(0.025, 0.975))
2.5% 97.5%
33.61029 43.16795
我认为您在评论中引用的分布在此处可用作pred
,置信区间为pred_BCI
。
如果要查看每个参数的后边缘密度,可以将density()
与存储在mcmc_r
对象的trace
组件中的mcmc_r
。
library(MHadaptive)
data(mcmc_r)
BCI(mcmc_r)
# 0.025 0.975 post_mean
# a -6.6113522 7.038858 0.001852978
# b 0.2217377 1.543519 0.902057671
# epsilon 3.8094802 6.550360 4.957292114
head(mcmc_r$trace)
# [,1] [,2] [,3]
# [1,] 3.1448136 0.7211228 5.449728
# [2,] 2.2287645 0.7155189 4.602004
# [3,] 2.0812509 0.8035820 4.224071
# [4,] 1.2444855 0.8448825 4.737466
# [5,] 3.2765630 0.5947548 4.740052
# [6,] 0.4271876 0.9014841 5.333821
plot(density(mcmc_r$trace[,3]), main=mcmc_r$par_names[3])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.