gpt4 book ai didi

r - 贝叶斯线性回归模型预测的置信区间

转载 作者:行者123 更新时间:2023-12-03 19:35:30 41 4
gpt4 key购买 nike

我在看 an excellent post on Bayesian Linear Regression (MHadaptive)

给出输出
后可信区间

BCI(mcmc_r)
#            0.025    0.975
# slope      -5.3345970 6.841016
# intercept    0.4216079 1.690075
# epsilon  3.8863393 6.660037

我现在使用什么函数来根据这些参数构建具有置信区间的模型?

最佳答案

为什么不使用您从 MCMC 获得的分布来预测 y 的分布?从任何一点 x ?在您使用的示例中,以下是相关部分,其中 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 .

关于r - 贝叶斯线性回归模型预测的置信区间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10584009/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com