Skip to content

Instantly share code, notes, and snippets.

@mages
Last active September 25, 2016 20:19
Show Gist options
  • Save mages/5bab54c35621055fb0172aa3508333f7 to your computer and use it in GitHub Desktop.
Save mages/5bab54c35621055fb0172aa3508333f7 to your computer and use it in GitHub Desktop.
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