Thanks Daniel, the model is now somehow complete to me, and the computation time is acceptable.
Bob, I have now fixed the first cut point as 0 for the identificability issue with the intercept. The factorial predictor issue was handled by simply ignoring the reference group. Could you please take a look at the model below before my serious run. The model in Stan is also attached if it is more convenient to you.
---
data {
int<lower=1> N; // Sample number
int<lower=1> K; // AD categories
int<lower=1> L; // Family number
int<lower=1,upper=K> Ad[N]; // AD status
int<lower=1,upper=L> Family[N]; // Family index
int<lower=1,upper=2> Sex[N]; // M:F
int<lower=1,upper=5> Apoe[N]; // 33:22:23:24:34
vector[N] Age;
}
transformed data {
vector[N] sexF; // Relative to M
vector[N] apoe22; // Relative to 33
vector[N] apoe23;
vector[N] apoe24;
vector[N] apoe34;
for (i in 1:N) {
sexF[i] <- Sex[i] == 2;
apoe22[i] <- Apoe[i] == 2;
apoe23[i] <- Apoe[i] == 3;
apoe24[i] <- Apoe[i] == 4;
apoe34[i] <- Apoe[i] == 5;
}
}
parameters {
vector[L] alpha; // intercept
real muAlpha; // mu for intercept
real<lower=0> sigmaAlpha; // sigma for intercept
real betaAge; // Age
real betaSex; // Female
real betaApoe22; // Relative to 33
real betaApoe23;
real betaApoe24;
real betaApoe34;
ordered[K-1] cu; // cut points
}
transformed parameters {
vector[K-1] c; // cut points
vector[N] yHat;
for (k in 1:(K-1))
c[k] <- cu[k] - cu[1];
yHat[n] <- alpha[Family[n]] + Age[n] * betaAge +
Sex[n] * betaSex +
apoe22[n] * betaApoe22 +
apoe23[n] * betaApoe23 +
apoe24[n] * betaApoe24 +
apoe34[n] * betaApoe34;
}
model {
muAlpha ~ normal(0, 5);
betaAge ~ normal(0, 5);
betaSex ~ normal(0, 5);
betaApoe22 ~ normal(0, 5);
betaApoe23 ~ normal(0, 5);
betaApoe24 ~ normal(0, 5);
betaApoe34 ~ normal(0, 5);
alpha ~ normal(muAlpha, sigmaAlpha); // intercept
for (n in 1:N)
Ad[n] ~ ordered_logistic(yHat[n], c);
}
generated quantities {
vector[N] logLik;
logLik[n] <- ordered_logistic_log(Ad[n], yHat[n], c);