Dear users,
I am trying to learn Stan’s optimizing() function and its output. As an example I am using the following Bernoulli example.
data {
int<lower=0> N; // number of trials
int<lower=0, upper=1> y[N]; // success on trial n
}
parameters {
real<lower=0, upper=1> theta; // chance of success
}
model {
// theta ~ uniform(0, 1); // prior (optimised value is 0.4)
theta ~ normal(0.5, 0.5); //(optimised value is 0.42)
y ~ bernoulli(theta); // likelihood
}
With R code
N <- 5;
y <- c(0,1,1,0,0);
model <- stan_model("bernoulli.stan");
mle <- optimizing(model, data=list(N = N, y = y));
print(mle, digits = 2)
My questions are:
-
How do I know that the optimized values produced from the optimizing() function are unique and global maximum. Reading through Stan’s reference 2.17.0 (page 385) , it seems there can more than one posterior mode and the algorithm may return a local maximum.
-
On page 422 of the Reference guide, it says that if parameters are constrained it is best to code them as unconstrained for better efficiency. How would the above Stan code be changed so that this can be achieved?
Thanks