使用贝叶斯模型模拟方案的情况-rstanarm

时间:2018-11-04 16:02:57

标签: r bayesian rstanarm

我正在拟合模型(为简化可重复性,已对其进行了简化)

库(数据集) 库(rstanarm)

set.seed(42)
rm(list = ls(all = TRUE))

prediction_data1 <- data.frame(
        Petal.Length = 1.4
    )

prediction_data2 <- data.frame(
        Petal.Length = 1.4
    )

model <- stan_glm(
        Petal.Width ~ Petal.Length
        , data = iris
        , chains = 3
        , iter = 1000
        , warmup = 100
)

new_predictions1 <- as.data.frame(posterior_predict(model, newdata = prediction_data1))
new_predictions2 <- as.data.frame(posterior_predict(model, newdata = prediction_data2))

colnames(new_predictions1) <- c('Petal.Width')
colnames(new_predictions2) <- c('Petal.Width')

median(new_predictions1$Petal.Width)
median(new_predictions2$Petal.Width)

我想我不应该期望两个相等的“模拟”数据集具有相同的中位数(例如0.2216209和0.2177802)?但是,上面的框架代码是模拟不同场景的正确方法吗(例如Petal.Length = 1.4与Petal.Length = 2.4)?

0 个答案:

没有答案