首页 > 解决方案 > 统一(0,50)与统一(0,500)的先前范围

问题描述

我刚刚开始使用贝叶斯分析和 rstan。我运行以下非常简单的示例(借用 Richard McElreath 的《Statistical Rethinking》一书 - 他正在使用他的函数,但我想直接在 rstan 中对其进行编码)

对于 sigma,我想使用非信息性先验(如本书所建议) sigma ~ uniform(0,50) 但是,模拟面临问题并返回接近 50 的 sigma(平均值)。如果我使用 auniform(0,70)那么 sigma 接近 70。但是通过使用更广泛的先验sigma ~ uniform(0,500)一切正常。我的问题是,由于数据的方差约为 5,为什么先验uniform(0,50)不起作用?谢谢

library(rstan)
library(rethinking)
library(dplyr)

data(Howell1)
dat1 <- Howell1
d2 <- dat1[ dat1$age >= 18 , ]

plot( d2$height ~ d2$weight )
lm(d2$height ~ d2$weight) %>% summary


model.stan2 <- '
data{
 int <lower=1> N;
 real weight_bar;
 vector[N] height;
 vector[N] weight;
}

parameters{
 real alpha;
 real beta;
 real<lower=0> sigma;
}
model{
 vector[N] mu;

// Priors
 alpha ~ normal(178, 20); 
 beta ~ lognormal(0,1); 
 sigma ~ uniform(0,50);  

 mu = alpha + beta*(weight - weight_bar); 

// Likelihood
 height ~ normal( mu, sigma);
}
'

stan_samples2 <- stan(model_code = model.stan2, 
    data = list(
        N= nrow(d2),
        height=d2$height, 
        weight=d2$weight,
        weight_bar= mean(d2$weight)
        )
    )

precis(stan_samples2)

标签: rbayesianrstan

解决方案


推荐阅读