I have a question that I think has a simple answer, but I can't seem to see it.
Set up: I'm building an item-response model based directly on the multilevel 2PL example from the docs. My data is in country-year format with binary variables for whether or not country j reported a given data point to the World Bank in year t. I'm primarily interested in estimating each country's 'transparency' for each year. This is equivalent to 'student's ability' in the Stan IRT example.
In the model the transparency variables are denoted with alpha.
Problem: I can easily run the model for just one year. You can fully reproduce this with rstan using code at:
https://raw.githubusercontent.com/FGCH/FRTIndex/stanTest/source/FRT_Stan.R
What I'm stuck on is how to estimate alpha for each country year j,t (I guess this would be equivalent to having 'student' and 'number times the student took the test').
This is what I have so far:
data {
int<lower=1> J; // number of countries
int<lower=1> T; // number of years
int<lower=1> K; // number of items
int<lower=1> N; // number of observations
int<lower=1> jj[N]; // country for observation n
int<lower=1> tt[N]; // time for observation n
int<lower=1,upper=K> kk[N]; // question for observation n
int<lower=0,upper=1> y[N]; // correctness for observation n
}
parameters {
real delta; // mean transparency
real alpha[J,T]; // transparency for j,t - mean
real beta[K]; // difficulty of item k
real log_gamma[K]; // discrimination of k
real<lower=0> sigma_alpha; // scale of abilities
real<lower=0> sigma_beta; // scale of difficulties
real<lower=0> sigma_gamma; // scale of log discrimiation
}
model {
alpha ~ normal(0,sigma_alpha);
beta ~ normal(0,sigma_beta);
log_gamma ~ normal(0,sigma_gamma);
delta ~ cauchy(0,5);
sigma_alpha ~ cauchy(0,5);
sigma_beta ~ cauchy(0,5);
sigma_gamma ~ cauchy(0,5);
for (n in 1:N)
y[n] ~ bernoulli_logit( exp(log_gamma[kk[n]])
* (alpha[jj[n],tt[n]] - beta[kk[n]] + delta) );
}
However, using this model in stan returns the error no matches for function name="normal_log". The full replication code is available at:
https://raw.githubusercontent.com/FGCH/FRTIndex/stanTest/source/FRT_Stan_v0_2.R
Any help with this would be much appreciated.
alpha ~ normal(0,sigma_alpha);
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sorry about that. Here is the full error message:
no matches for function name="normal_log"
arg 0 type=real[2]
arg 1 type=int
arg 2 type=real
available function signatures for normal_log:
0. normal_log(real, real, real) : real
1. normal_log(real, real, real[1]) : real
2. normal_log(real, real, vector) : real
3. normal_log(real, real, row vector) : real
4. normal_log(real, real[1], real) : real
5. normal_log(real, real[1], real[1]) : real
6. normal_log(real, real[1], vector) : real
7. normal_log(real, real[1], row vector) : real
8. normal_log(real, vector, real) : real
9. normal_log(real, vector, real[1]) : real
10. normal_log(real, vector, vector) : real
11. normal_log(real, vector, row vector) : real
12. normal_log(real, row vector, real) : real
13. normal_log(real, row vector, real[1]) : real
14. normal_log(real, row vector, vector) : real
15. normal_log(real, row vector, row vector) : reaalpha ~ normal(0,sigma_alpha);alpha ~ normal(0.0,sigma_alpha);may work? 0 is considered as an integer whereas 0.0 as considered as real.
no matches for function name="normal_log"
arg 0 type=real[2]
arg 1 type=int
arg 2 type=real
alpha ~ normal(0,sigma_alpha);
you have alpha defined as:
real alpha[J,T]; // transparency for j,t - mean
--
Thanks! This discussion has been really useful. It's really helping me convert my IRT models to Stan from Jags (so far I've definitely had the advertised convergence speed improvements).
This worked perfectly:
for (j in 1:J)
for (t in 1:T)
alpha[j,t] ~ normal(0, sigma_alpha);
FYI for anyone else that might be interested: I've updated the priors slightly such that at time 1 alpha[j,t] ~ normal(0, sigma_alpha), but then for all t_1+n the previous year's alpha informs the prior for the following year, i.e.
for (j in 1:J)
alpha[j,1] ~ normal(0, sigma_alpha);
for (j in 1:J)
for (t in 2:T)
alpha[j,t] ~ normal(alpha[j,t-1], sigma_alpha);
Any thoughts on further tweaks would be of course be welcome.
--
--
--
I wouldn't have expected that. Typically, almost all
of Stan's compute time is taken up computing derivatives
and matrix vs. 2D array doesn't change that.
There's a chapter in the manual that explains what's going on
with efficiency for arrays and vectors.
- Bob
On Jul 14, 2014, at 1:31 PM, Christopher Gandrud <christoph...@gmail.com> wrote:
> Just using:
>
> matrix[J,T] alpha;
>
> (with the corresponding change in the priors setup) rather than:
>
> real alpha[J,T];
>
> seems to have halved the computation time!
>
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.