In this example, we will generate 1,000 Gaussian deviates with a mean equal to five and a standard deviation equal to three. We will assign a Gaussian prior to the mean parameter, and a gamma distribution to the standard deviation. The objective will be to characterize the marginal posterior densities for mu and sigma (mean and standard deviation of a Gaussian distribution):
- We declare our STAN model, and we will store it into a string as follows:
library(rstan)values = list(y = rnorm(1000,5,3))model ="data {real y[1000];}parameters {real mu;real sigma;}model {mu ~ normal(0,10);sigma ~ normal(0,10);y ~ normal(mu,sigma);}"
- We call the stan function, which fits the model. The first parameter, model_code=, obviously specifies ...