I’m struggling with stan_polr
, and unlike previous issues (Loo with k_threshold error for stan_polr()), I think this time it’s all me. So I’m starting a new thread.
Running this code:
require(rstan)
require(rstanarm)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
DF<-read.csv("reducedDF.csv")
DF$Ans<-ordered(df$Inno_art,levels=1:5,labels=LETTERS[1:5])
DF$ID<-as.character(df$ID)
moddef="Ans ~ ID + Q + Lan"
fit<-stan_polr(as.formula(moddef) , data = DF, method = "logistic",
prior = R2(0.5,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
on the attached datareducedDF.csv (52.7 KB) I get the error message Error in qr.solve(decomposition, Q) : singular matrix 'a' in solve
. I am fairly sure this is because ID (respondents) are nested within Lan (Counties) such that e.g. respondent with ID 1 always is in Lan “Ostergotland”. Had I coded the model from scratch, I would have included some hierarchical structure such that the ID effects are e.g. normally distributed around 0 with some unknown standard deviation that’s estimated in the analysis. I think there is likely some way to do this with stan_polr
, but I haven’t been able to find any hierarchical model examples for stan_polr
. I’m using this problem as an excuse to learn rstanarm, and I’d be grateful for any suggestions.