I am trying to create a table for stan_glmer.nb
(rstanarm
) output, but model_parameters
from the package parameters
throws an odd error, that I am unsure how to solve. Perhaps this is a bug.
Shortened sessionInfo()
output for version info:
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
parameters_0.8.2
rstanarm_2.21.1
A reproducible example:
library(rstanarm)
library(parameters)
x<-rnorm(500)
dat<-data.frame(x=x,z=rep(c("A","B","C","D","E"),100), y=.2+x*.7)
mod1<-stan_glmer(y~x+(x|z),data=dat)
model_parameters(mod1, effects="all")
I will spare you the output here, because it isn't important, but the function works. Now the negative binomial model:
dat.nb<-data.frame(x=rnorm(500),z=rep(c("A","B","C","D","E"),100),
y=rnbinom(500,size=1,prob = .5))
mod2<-stan_glmer.nb(y~x+(x|z),data=dat.nb)
model_parameters(mod2, effects="all")
Now an error message:
Error in `$<-.data.frame`(`*tmp*`, "parameter", value = c("(Intercept)", :
replacement has 3 rows, data has 1
Although with parameters
version 0.10.1, @BenBolker gets a blank output, instead of the error (see comments). Either way, it seems like this function isn't working for rstanarm
discrete distributions (see comments). As far as I can see in the help documentation, there is nothing indicating the need to specify a negative binomial model. Furthermore, the function works fine for lme4
models:
library(lme4)
mod1<-lmer(y~x+(x|z),data=dat)
model_parameters(mod1, effects="all")
mod2<-glmer.nb(y~x+(x|z),data=dat.nb)
model_parameters(mod2, effects="all")
There are some model convergence issues, etc. with this simulated data, but model_parameters
works for the glmer.nb
model, but not the stan_glmer.nb
model. Any idea what is going on here?
I have run into the same issue with a completely different dataset, and still can not figure out why "replacement" has 2 rows more than "data" in parameters::model_parameters
(see error above). One additional row might be the reciprocal_dispersion
parameter that the function isn't expecting, but not sure why the function would have a bug for the negative binomial glmms, which are quite common.
As a note, the tidy_stan
function from sjPlot
package still works for these models, but gives the warning:
Warning message:
'tidy_stan' is deprecated.
Use 'parameters::model_parameters()' instead.
See help("Deprecated")
Yet, parameters::model_parameters()
, as noted above, does not yet work.
Though it was quite a challenge, I finally figured out the bug (and has an easy fix, go to the end of the post if too long to read). I pooled the thread by finding the instruction that cause the error. Starting with:
Which fails at:
Which fails at:
which fails at:
which fails at:
which fails at:
To find at what stage it failed from here on, I copied the source code of this function (now defined as GET_priors) and placed some strategic prints:
For some odd reason, its trying to add column of 3 rows to a data.frame with 2 rows (hence the error). However, the module that fails is related to the priors. We can obtain results by simply setting prior equal to F, avoiding all that branch in the code as in:
Indeed, it is a bug and should be reported (only that the bug is in a dependency of a dependency; e.g. R-package "insight").