What exactly is missing? If samplesize is
known, but count is missing, imputing the counts
won't add any information to the model, as they only
come into the model as end observations without
constraints:
for (i in 1:nobs)
count[i] ~ binomial_logit(samplesize[i], study_estimates[studyid[i]][disorderid[i]]);
More technically, if you include them as discrete variables,
then marginalize them out, the remaining inferences aren't
affected.
But you could generate estimates for the missing counts this way
if you knew their samplesize, studyid and disorderid:
count_missing[i]
<- binomial_rng(samplesize[i],
inv_logit(study_estimates[studyid[i]]
[disorderid[i]]));
I had to really strip your program's comments and parens down
to be able to read it:
data {
int<lower=1> nobs;
int<lower=1> nstudies;
int<lower=1> ndisorders;
int<lower=1,upper=nstudies> studyid[nobs];
int<lower=1> samplesize[nobs];
int<lower=0> count[nobs];
int<lower=1,upper=ndisorders> disorderid[nobs];
}
parameters {
vector[ndisorders] prevalence;
vector[ndisorders] zstudy_estimates[nstudies];
cholesky_factor_corr[ndisorders] L_Omega;
vector<lower=0, upper=pi()/2>[ndisorders] ucauchy_tau;
}
transformed parameters {
vector[ndisorders] study_estimates[nstudies];
vector<lower=0>[ndisorders] tau;
for (i in 1:ndisorders)
tau[i] <- .25 * tan(ucauchy_tau[i]);
for (i in 1:nstudies)
study_estimates[i] <- prevalence + tau .* (L_Omega * zstudy_estimates[i]);
}
model {
ucauchy_tau ~ uniform(0, pi()/2);
prevalence ~ normal(-3.5, 1.5);
for (i in 1:nstudies)
zstudy_estimates[i] ~ normal(0, 1);
for (i in 1:nobs)
count[i] ~ binomial_logit(samplesize[i], study_estimates[studyid[i]][disorderid[i]]);
}
You don't need the uniform on ucauchy_tau --- it's implicit
given the constraint, but it'd won't hurt anything.
I think you can also turn zstudy_estimates into a matrix and
vectorize the study_es4timates calculation. That'd then
make it easy to vectorize the zstudy_estimates variable
using
to_vector(zstudy_estimates) ~ normal(0, 1);
But all that's just for efficiency.
- Bob
> --
> 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.
> To post to this group, send email to
stan-...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.
> <mv_prevalence_model.stan>