Those didn't look like at all the same models in Stan and JAGS
given that you give beta a direct multinormal prior in the
JAGS approach.
For speed (and robustness) in Stan, you're better off using
y ~ bernoulli_logit(beta[rc[r]]*xi[id[r]] - alpha[rc[r]] + zg[r]);
That assumes the parameter's on the logit scale. It usually doesn't make
much difference in modeling other than scale of coefficients.
I didn't trace through the values for your mu_* and sigma_* constants
or the form of your predictors, but you have to be very careful about
identifiability with these models with independent additive factors.
If the predictors are not standardized, doing that could help. But
the problem in these models is usually the non-identifiability.
Whatever you do, it would help to generate fake data based on your model
and see if the program can fit it. That'll test that everything is OK before
moving to real data.
More below.
> On Jun 8, 2015, at 10:11 PM, Jake Johnson <
jak...@gmail.com> wrote:
>
> Greetings Stan users,
>
> I recently began experimenting with Stan as a tool to simulate two parameter IRT models (probit link) with congressional voting data. Originally I started with the pscl package in R and then moved on to JAGS via rjags. The current model I am interested in adds additional covariates to the standard model as in:
>
> P(y_ij = 1) = Phi( beta_j * x_i - alpha_j + gamma * z_ij)
>
> where z_ij represents data (legislator and constituent characteristics). I have written the code for this model (attached) but after running it a number of times the model doesn't mix well. It moves to the prior means for the x_i and stays there while all the other parameters remain at their initial values (at least up to 500 iterations which took around 3 hours).
>
> I am certain the code works since I have run it with z_ij equal to all zeros and the output is comparable to using ideal() in pscl which is the exact same model. I was also successful with a canned example I made for this post (see attached). So I am thinking this is related to my data. I have had success using JAGS with this data (code attached) and it does return sensible results. However it is very slow and so I would really like to get this working in Stan to compare. I am hoping someone might be able to provide some advice or tips to get things moving. Better starting values? Rescaling the data?
>
> As an aside, can someone provide some intuition for the "vanishing density" error?
It's triggered when the density is zero (log density negative infinity).
This usually results from a constraint being violated. A culprit might
be Phi_approx underflowing to 0 or overflowing to 1 with mismatched
data.
> Either of the following triggers it:
> - Passing initial values for alpha and beta using the coefficients from probit regressions of y_j on the initial x_i and an intercept (one regression per j). This is a default in ideal().
> - Passing initial values for gamma using the coefficients from a probit regression of y on z (no intercept) with all other initial values at zero
You can use print statements to track down where the
density goes to zero. You can use the constant lp__ (not in the
doc and soon to be deprecated and replaced with a function) to inspect
the current value at any point using:
print("lp==", lp__);
- Bob