均匀(0,50)与均匀(0,500)的先前范围

时间:2019-03-29 16:13:06

标签: bayesian rstan

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

对于sigma,我想使用无信息的先验(如书中所建议)sigma ~ uniform(0,50) 但是,模拟面临问题,并返回接近50的sigma(平均值)。如果我使用uniform(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)

0 个答案:

没有答案
相关问题