Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data {
- int<lower=0> I;
- int<lower=0> n[I];
- int<lower=0> x[I];
- real<lower=0> a;
- real<lower=0> b;
- real m;
- real<lower=0> p;
- }
- parameters {
- real<lower=0> lambda;
- real mu;
- real<lower=0, upper=1> theta[I];
- }
- transformed parameters {
- real gam[I];
- for( j in 1:I)
- gam[j] = log(theta[j] / (1-theta[j])) ;
- }
- model {
- target += gamma_lpdf( lambda | a, b);
- target += normal_lpdf( mu | m , 1/sqrt(p));
- target += normal_lpdf( gam | mu, 1/sqrt(lambda));
- target += binomial_lpmf( x | n , theta);
- }
- library(rstan)
- fit <- stan(
- file = "hospital.stan" ,
- data = dat ,
- iter = 20000,
- warmup = 2000,
- chains = 1
- )
- structure(
- list(
- I = 12L,
- n = c(47, 211, 810, 148, 196, 360, 119, 207, 97, 256, 148, 215),
- x = c(0, 8, 46, 9, 13, 24, 8, 14, 8, 29, 18, 31),
- a = 2,
- b = 2,
- m = 0,
- p = 0.01),
- .Names = c("I", "n", "x", "a", "b", "m", "p")
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement