Hi everyone
I have a hierarchical IRT model that runs ok. There are just two spots where I have made horrible hacks to accomplish my goals. I'm wondering if anyone could help me clean these up.
The full model code is below, but I'll just highlight the hacks first.
Hack 1: I am measuring ability (what I call transparency and denote alpha) for J countries for T years. For all years T > 1, the alpha Tn - 1 forms the prior for year T. I want to recenter the ability for T = 1 by subtracting the mean ability and dividing by the standard deviation.
I do this in the transformed parameters block:
transformed parameters {// recenters transparency for t = 1vector[J] recentered_alpha1;real mean_alpha1;real<lower=0> sd_alpha1;mean_alpha1 <- mean(alpha1);sd_alpha1 <- sd(alpha1);for (j in 1:J)recentered_alpha1[j] <- ( alpha1[j] - mean_alpha1 ) / sd_alpha1;}
The problem is that I want to put recentered_alpha[j] into an alpha matrix at alpha[j,1]. I can't seem to do this in the transformed parameters block so do the horrible hack:
alpha[j,1] ~ normal(recentered_alpha1[j], 0.001);
in the model block.
Hack 2: I would like to have a half-Cauchy prior for each country but I am having trouble vectorising this. I think STAN doesn't support truncation with Cauchy distributions and I can't seem to set the lower bound in all items of a J length list. My solution so far basically kills a lot of the benefits of vectorisation:
for (j in 1:J) {alpha[j,1] ~ normal(recentered_alpha1[j], 0.001);sigma_alpha ~ cauchy(0,0.25);for (t in 2:T)alpha[j,t] ~ normal(alpha[j,t-1], sigma_alpha);}
Any help would be much appreciated!
The full model:
data {int<lower=1> J; // number of countriesint<lower=1> T; // number of yearsint<lower=1> K; // number of itemsint<lower=1> N; // number of observationsint<lower=1> jj[N]; // country for observation nint<lower=1> tt[N]; // time for observation nint<lower=1,upper=K> kk[N]; // item for observation nint<lower=0,upper=1> y[N]; // response for observation n}parameters {real delta; // mean transparencyvector[J] alpha1; // initial alpha for t = 1 before recenteringmatrix[J,T] alpha; // transparency for j,t - meanvector[K] beta; // difficulty of item kvector[K] log_gamma; // discrimination of k// all scale parameters have an implicit half Cauchy priorreal<lower=0> sigma_alpha; // scale of abilitiesreal<lower=0> sigma_beta; // scale of difficultiesreal<lower=0> sigma_gamma; // scale of log discrimination}transformed parameters {// recenters transparency for t = 1vector[J] recentered_alpha1;real mean_alpha1;real<lower=0> sd_alpha1;mean_alpha1 <- mean(alpha1);sd_alpha1 <- sd(alpha1);for (j in 1:J)recentered_alpha1[j] <- ( alpha1[j] - mean_alpha1 ) / sd_alpha1;}model {alpha1 ~ normal(0,100); // diffuse priorfor (j in 1:J) {alpha[j,1] ~ normal(recentered_alpha1[j], 0.001); // horrible hacksigma_alpha ~ cauchy(0,0.25);for (t in 2:T)alpha[j,t] ~ normal(alpha[j,t-1], sigma_alpha);}beta ~ normal(0,sigma_beta);log_gamma ~ normal(0,sigma_gamma);delta ~ cauchy(0,0.25);sigma_beta ~ cauchy(0,0.25);sigma_gamma ~ cauchy(0,0.25);for (n in 1:N)y[n] ~ bernoulli_logit(exp(log_gamma[kk[n]])* (alpha[jj[n],tt[n]] - beta[kk[n]] + delta) );}
Hi everyone
I have a hierarchical IRT model that runs ok. There are just two spots where I have made horrible hacks to accomplish my goals. I'm wondering if anyone could help me clean these up.
The full model code is below, but I'll just highlight the hacks first.
Hack 1: I am measuring ability (what I call transparency and denote
alpha) forJcountries forTyears. For all years T > 1, thealphaTn - 1 forms the prior for year T. I want to recenter the ability for T = 1 by subtracting the mean ability and dividing by the standard deviation.I do this in the transformed parameters block:
transformed parameters {// recenters transparency for t = 1vector[J] recentered_alpha1;real mean_alpha1;real<lower=0> sd_alpha1;mean_alpha1 <- mean(alpha1);sd_alpha1 <- sd(alpha1);for (j in 1:J)recentered_alpha1[j] <- ( alpha1[j] - mean_alpha1 ) / sd_alpha1;}The problem is that I want to put
recentered_alpha[j]into analphamatrix at alpha[j,1]. I can't seem to do this in the transformed parameters block so do the horrible hack:alpha[j,1] ~ normal(recentered_alpha1[j], 0.001);in the model block.
Hack 2: I would like to have a half-Cauchy prior for each country but I am having trouble vectorising this. I think STAN doesn't support truncation with Cauchy distributions and I can't seem to set the lower bound in all items of a J length list. My solution so far basically kills a lot of the benefits of vectorisation:
for (j in 1:J) {alpha[j,1] ~ normal(recentered_alpha1[j], 0.001);sigma_alpha ~ cauchy(0,0.25);for (t in 2:T)alpha[j,t] ~ normal(alpha[j,t-1], sigma_alpha);}Any help would be much appreciated!
--
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.
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/77LB7iW_5fc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Hi MarcusThanks for the insight.I actually do want to create a country (j) specific sigma_alpha. So sigma_alpha should be the same for all all alpha[t+1] for each j. This is for a couple of reasons, the simple on being that not doing so seems to lead the alpha parameters to grow dramatically.I would like to vectorize this though so that I only need to call sigma_alpha ~ cauchy(0,0.25) and it will have J values.
Thanks for the block suggestion. Any chance you could point me to an example?
Thanks for these comments. They are really helpful.
I guess the last thing (and the thing I’m most concerned about substantively) is how to enter my recentered alphas for time 1 into the main alpha matrix.
Currently I create a vector[J] of recentered alpha in the transformed parameters block. I basically want these to be put into alpha[j,1].
At the moment I do this with a horrible hack in the model block like this:
for (j in 1:J)
alpha[j,1] ~ normal(recentered_alpha1[j], 0.001);
But I clearly want to do something like:
for (j in 1:J)
alpha[j,1] <- recentered_alpha1[j];
Any thoughts?