Error using stan_polr: "singular matrix 'a' in solve"

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.

Yeah in this case I don’t think there’s a bug, I think your diagnosis is probably correct. Unfortunately, unlike some of the other rstanarm functions like stan_glmer() and stan_gamm4(), the stan_polr() function doesn’t do hierarchical models yet. I think @bgoodri was planning on extending it at some point (it’s definitely possible), but I’m not sure of the status of that.

OK, thanks. If hierarchical models aren’t possible in the foreseeable future, I think an alternative for identifiability might be to lock one coefficient (e.g. coefficient for ID1=0), but I can’t find any examples of how to do that either. Is that possible?

Fixing a parameter to 0 isn’t really possible in rstanarm at the moment. It’s definitely possible in Stan (and maybe possible with brms?), but rstanarm really isn’t set up for that kind of flexibility. The issue really is that because all the models in rstanarm are pre-compiled there are fewer customization options (all the code needs to be written in advance and compiled instead of on the fly based on user input). So basically stan_polr() is a Bayesian version of MASS::polr() and doesn’t provide too much customization beyond that (other than specifying priors).