Hello,
I’m fairly new to using Stan to fit models and was looking at RStan: the R interface to Stan vignette with the 8 schools problem.
The model fit in this example is of the following format (I’m using a centered parameterization for now as I want to explore the sampling problems later on):
data {
int<lower = 0> J;
real y[J];
real<lower = 0> sigma[J];
}
parameters {
real mu;
real<lower = 0> tau;
vector[J] theta;
}
model {
theta ~ normal(mu, tau);
y ~ normal(theta, sigma);
}
Also, the data is of the following form:
schools_data <- list(
J = 8,
y = c(28, 8, -3, 7, -1, 1, 18, 12),
sigma = c(15, 10, 16, 11, 9, 11, 10, 18)
)
From the model, you can see that the hyperparameters were given a default prior, which I understand to be uniform across the domain. However, suppose I wanted to conduct a prior predictive check using this prior specification, how can I do so?
Will something like this suffice where I set “a” to be a large value (possibly even Inf if Stan allows):
data {
int<lower = 1> J;
real<lower = 0> sigma[J];
}
model {
}
generated quantities {
real mu = uniform_rng(-a, a);
real<lower = 0> tau = abs(uniform_rng(-a, a));
real y_rep[J];
real theta[J];
for (j in 1:J) {
theta[j] = normal_rng(mu, tau);
y_rep[j] = normal_rng(theta[j], sigma[j]);
}
}
Also, is there a better way to model tau given the truncation?
Thanks in advance!
All the best,
Tim