0

我正在拟合一个模型(为了重现性而非常简化),如下所示:

库(数据集) 库(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)?

4

0 回答 0