简体   繁体   English

为什么 tab_model (sjPlot) 用 rstanarm 模型重新运行 MCMC?

[英]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()
  • the insight::get_variance.stanreg() method calls insight:::.compute_variances() insight::get_variance.stanreg()方法调用了insight::get_variance.stanreg() insight:::.compute_variances()
  • ... which calls insight:::.compute_variance_distribution() ...调用insight:::.compute_variance_distribution()
  • ... which (for a log-link count distribution) calls insight:::.variance_distributional() ...其中(对于日志链接计数分布)调用insight:::.variance_distributional()
  • ... which calls null_model ... 调用null_model
  • ... which calls .null_model_mixed() ... 调用.null_model_mixed()
  • ... which calls stats::update() ... 调用stats::update()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将自定义列添加到回归表(tab_model、sjplot)? - Adding custom column to regression table (tab_model, sjplot)? 无法在tab_model(sjPlot)中获得“ kr” p值计算才能正常工作 - Can't get “kr” p-value computation in tab_model (sjPlot) to work R:使用小鼠 mipo/data.frame object 和 sjPlot tab_model - R: use mice mipo/data.frame object with sjPlot tab_model 将 sjPlot::tab_model() 或其他 html 表中的 output 编织到 PDF 文档中 - Knitting output from sjPlot::tab_model() or other html tables into PDF document 预测变量在 sjPlot 中使用 tab_model (r) 以随机顺序排列(现在具有可重现的代码) - Predictors are in random order in sjPlot using tab_model (r) (with reproducible code now) R如何使用sjPlot :: tab_model()将lmer,glmer和gamlss模型放入表中 - R how to use sjPlot::tab_model() to put lmer, glmer, and gamlss models into a table 将 sjPlot::tab_model 表 ta 的列表保存在 word 文件或 RMarkdown 文件中 - Save a list of sjPlot::tab_model tables ta on a word file or a RMarkdown file 如何使 sjPlot::tab_model() html 表在 bookdown 文档中编号 - How to make sjPlot::tab_model() html table to be numbered in a bookdown document tab_model() 和 tidy() 的不同系数 - Different coefficients with tab_model() and tidy() 在 R 中:tab_model(隐藏多项式) - In R: tab_model (hide polynomials)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM