Last active
September 25, 2016 20:19
-
-
Save mages/5bab54c35621055fb0172aa3508333f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
functions { | |
// Define log probability density function | |
real myNormal_lpdf(real y, real mu, real sigma) { | |
return -log(2 * pi()) / 2 - log(sigma) | |
- square(mu - y) / (2 * sigma^2); | |
} | |
} | |
data { | |
int N; | |
real y[N]; | |
} | |
parameters { | |
real mu; | |
real<lower = 0> sigma; | |
} | |
model { | |
// Priors | |
mu ~ normal(0, 10); | |
sigma ~ cauchy(0,10); | |
// Likelihood | |
for(n in 1:N){ | |
target += myNormal_lpdf(y[n] | mu, sigma); | |
} | |
} | |
generated quantities{ | |
real y_ppc; | |
{ | |
real x; | |
x = uniform_rng(0, 1); | |
// Phi is the probit function in Stan, the CDF of the standardised Normal N(0,1) | |
// inv_Phi is the quantile function of the standardised Normal N(0,1) | |
y_ppc = mu + sigma * inv_Phi(x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment