[英]Why does tab_model (sjPlot) re-run MCMC with rstanarm model?
I am creating a table with tab_model
from the package sjPlot
( https://cran.r-project.org/web/packages/sjPlot/vignettes/tab_model_estimates.html ).我正在使用包
sjPlot
( https://cran.r-project.org/web/packages/sjPlot/vignettes/tab_model_estimates.html ) 中的tab_model
创建一个表。
However, when I use a negative binomial rstanarm
model object, tab_model
re-runs MCMC chains.但是,当我使用负二项式
rstanarm
模型对象时, tab_model
重新运行 MCMC 链。 My actual model takes many hours to run, so this is not ideal for tab_model
to be doing this, but it doesn't seem to do it for other models (such as with glmer
in lme4
).我的实际模型需要很多小时才能运行,所以这对于
tab_model
来说并不理想,但它似乎不适用于其他模型(例如glmer
中的lme4
)。
library(rstanarm)
library(lme4)
dat.nb<-data.frame(x=rnorm(200),z=rep(c("A","B","C","D"),50),
y=rnbinom(200,size=1,prob = .5))
mod1<-glmer.nb(y~x+(1|z),data=dat.nb)
options(mc.cores = parallel::detectCores())
mod2<-stan_glmer.nb(y~x+(1|z),data=dat.nb)
Now to create the model tables:现在创建模型表:
library(sjPlot)
tab_model(mod1)
The output is quick, and as expected (although the original model also ran quick, so it is possible that tab_model
is re-running the model here too).输出很快,正如预期的那样(虽然原始模型也运行得很快,所以
tab_model
也有可能在这里重新运行模型)。
Now when I try现在当我尝试
tab_model(mod2)
It begins re-running MCMC.它开始重新运行 MCMC。 Is this normal behavior, and if so, is anyone familiar with a way to turn this off, and just use the model object already created, rather than re-running the model?
这是正常行为吗,如果是,是否有人熟悉关闭它的方法,只使用已经创建的模型对象,而不是重新运行模型?
tl;dr I think this is going to be hard to avoid without hacking both the insight
package and this one, or asking the package maintainer for an edit, unless you want to forgo printing the ICC, R^2, and the random-effects variance. tl;dr我认为如果不同时破解
insight
包和这个包,或者不要求包维护者进行编辑,这将很难避免,除非您想放弃打印 ICC、R^2和随机效应方差。 Here , tab_model()
calls insight::get_variance()
, which tries to compute variances for the null model so it can compute the ICC and R^2. 在这里,
tab_model()
调用insight::get_variance()
,它尝试计算空模型的方差,以便它可以计算ICC 和R^2。 Computing these variances requires re-running the model.计算这些差异需要重新运行模型。 (When it does it for the
glmer.nb
, it goes via lme4:::update.merMod()
and is quick enough that you don't notice the computation time.) (当它为
glmer.nb
执行它时,它通过lme4:::update.merMod()
并且足够快,您不会注意到计算时间。)
So所以
tab_model(mod2,show.r2=FALSE,show.icc=FALSE,show.re.var=FALSE)
doesn't recompute anything.不重新计算任何东西。 In theory I think it should be possible to skip the resampling/recomputation step with just
show.r2=FALSE, show.icc=FALSE
(ie it shouldn't be necessary to get the RE var), but this would take some hacking/participation by the maintainer.从理论上讲,我认为应该可以跳过重采样/重新计算步骤,只需要
show.r2=FALSE, show.icc=FALSE
(即不需要获取 RE var),但这需要一些黑客攻击/维护者的参与。
Digging in (by using debug(rstan::sampling)
to stop inside the Stan sampling function, then where
to see the call stack ... debug(rstan::sampling)
挖掘(通过使用debug(rstan::sampling)
在 Stan 采样函数内部停止,然后where
查看调用堆栈...
tab_model()
calls insight::get_variance()
here tab_model()
insight::get_variance()
在这里调用了insight::get_variance()
insight::get_variance.stanreg()
method calls insight:::.compute_variances()
insight::get_variance.stanreg()
方法调用了insight::get_variance.stanreg()
insight:::.compute_variances()
insight:::.compute_variance_distribution()
insight:::.compute_variance_distribution()
insight:::.variance_distributional()
insight:::.variance_distributional()
null_model
null_model
.null_model_mixed()
.null_model_mixed()
stats::update()
stats::update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.