# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .r
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: R
#     language: R
#     name: ir
# ---

# This notebook has been **launched just for you**. It provides an easy way to try out Stan.
#
# <div class="alert alert-warning" role="alert" style="margin: 10px">
# <p>**WARNING**</p>
#
# <p>Don't rely on this server for anything you want to last - your notebook will be *deleted after 10 minutes of inactivity*.</p>
# </div>

library(rstan)

# +
schools_code <- "
data {
  int<lower=0> J; // number of schools 
  real y[J]; // estimated treatment effects
  real<lower=0> sigma[J]; // s.e. of effect estimates 
}
parameters {
  real mu; 
  real<lower=0> tau;
  real eta[J];
}
transformed parameters {
  real theta[J];
  for (j in 1:J)
    theta[j] <- mu + tau * eta[j];
}
model {
  eta ~ normal(0, 1);
  y ~ normal(theta, sigma);
}
"
schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))

fit <- stan(model_code=schools_code, data = schools_dat, 
            iter = 1000, chains = 4)
# -

print(fit)

plot(fit)



StarcoderdataJupyterScriptsDedupFiltered