Here, I would like to sample from a univariate normal distribution with mean mu and std sigma:
I know that it is simple to sample by simply using y ~ normal(mu,sigma).
But, as an exercise, I only want to use the proportional part of the Guassian distribution (kernel), and check whether stan works or not.
I made code as bellow, but it does not work…
Can I anyone help me to fix this???
functions {
real gaussian(real x, real mu, real sigma) {
return (1 / sigma) * exp( - (((x - mu)/sigma)^2) / 2 );
}
}
data {
real mu;
real<lower=0> sigma;
real x;
}
parameters {
real y;
}
model {
// Option 1
// y ~ normal(mu, sigma);
// Option 2
target += gaussian(x, mu, sigma);
}
EDIT: @maxbiostat edited this post for syntax highlighting.