Our notation's super confusing (even to me; we're changing it,
by the way).
This:
> log_lik[n] <- neg_binomial_2_log(y[n], X[n]*betas, phi);
needs to be neg_binomial_2_log_log(...).
The first log is to say that the location parameter X[n] * betas
is on the log scale and the second to indicate that this is
a function.
NOTE about the future of Stan:
We're going to change this so that in the future it'll be possible
to write neg_binomial_2_log_lpdf(...) --- so the _lpdf indicates
it's a log pdf, whereas the _log will indicate the scale of the parameters.
- Bob
> On Feb 29, 2016, at 12:43 PM, Chris <
wel...@gmail.com> wrote:
>
> if I change the model to
>
> stan_code <- "
> data {
> int<lower=0> N; // observations
> int<lower=0> K; // number of columns
> matrix[N,K] X; // predictor matrix
> int<lower=0> y[N]; // response
> }
> parameters {
> vector[K] betas;
> real<lower=0.00001, upper=50> phi;
> }
> model {
> phi ~ cauchy(0,2.5);
> for(k in 1:K)
> betas[k] ~ normal(0,100);
> y ~ neg_binomial_2_log(X*betas, phi);
> }
> generated quantities {
> real log_lik[N];
> for (n in 1:N)
> log_lik[n] <- neg_binomial_2_log_(y[n], X[n]*betas, phi);