为什么 tab_model (sjPlot) re-运行 MCMC with rstanarm 模型?
Why does tab_model (sjPlot) re-run MCMC with rstanarm model?
我正在用包 sjPlot
(https://cran.r-project.org/web/packages/sjPlot/vignettes/tab_model_estimates.html) 中的 tab_model
创建一个 table。
但是,当我使用负二项式 rstanarm
模型对象时,tab_model
重新 运行s MCMC 链。
我的实际模型需要很多小时才能 运行,所以这对于 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)
现在创建模型 tables:
library(sjPlot)
tab_model(mod1)
输出很快,正如预期的那样(尽管原始模型也 运行 很快,所以 tab_model
可能也在此处重新 运行 模型) .
现在当我尝试
tab_model(mod2)
它开始重新 运行 MCMC。这是正常行为吗?如果是的话,有没有人知道关闭它的方法,只使用已经创建的模型对象,而不是重新运行模型?
tl;dr 我认为如果不破解 insight
包和这个包,或者要求包维护者进行编辑,这将很难避免, 除非你想放弃打印 ICC, R^2, and the random-effects variance. Here、tab_model()
调用 insight::get_variance()
,它会尝试计算空模型的方差,以便计算 ICC 和 R^2。计算这些方差需要 re-running 模型。 (当它为 glmer.nb
执行时,它经过 lme4:::update.merMod()
并且速度足够快,您不会注意到计算时间。)
所以
tab_model(mod2,show.r2=FALSE,show.icc=FALSE,show.re.var=FALSE)
不重新计算任何东西。从理论上讲,我认为 应该 可以跳过 resampling/recomputation 步骤,只需要 show.r2=FALSE, show.icc=FALSE
(即不需要获取 RE var),但是这将需要维护者 hacking/participation。
深入挖掘(通过使用 debug(rstan::sampling)
在 Stan 采样函数内部停止,然后 where
查看调用堆栈 ...
tab_model()
呼叫 insight::get_variance()
here
insight::get_variance.stanreg()
方法调用 insight:::.compute_variances()
- ... 调用
insight:::.compute_variance_distribution()
- ...(对于 log-link 计数分布)调用
insight:::.variance_distributional()
- ... 调用
null_model
- ... 调用
.null_model_mixed()
- ... 调用
stats::update()
我正在用包 sjPlot
(https://cran.r-project.org/web/packages/sjPlot/vignettes/tab_model_estimates.html) 中的 tab_model
创建一个 table。
但是,当我使用负二项式 rstanarm
模型对象时,tab_model
重新 运行s MCMC 链。
我的实际模型需要很多小时才能 运行,所以这对于 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)
现在创建模型 tables:
library(sjPlot)
tab_model(mod1)
输出很快,正如预期的那样(尽管原始模型也 运行 很快,所以 tab_model
可能也在此处重新 运行 模型) .
现在当我尝试
tab_model(mod2)
它开始重新 运行 MCMC。这是正常行为吗?如果是的话,有没有人知道关闭它的方法,只使用已经创建的模型对象,而不是重新运行模型?
tl;dr 我认为如果不破解 insight
包和这个包,或者要求包维护者进行编辑,这将很难避免, 除非你想放弃打印 ICC, R^2, and the random-effects variance. Here、tab_model()
调用 insight::get_variance()
,它会尝试计算空模型的方差,以便计算 ICC 和 R^2。计算这些方差需要 re-running 模型。 (当它为 glmer.nb
执行时,它经过 lme4:::update.merMod()
并且速度足够快,您不会注意到计算时间。)
所以
tab_model(mod2,show.r2=FALSE,show.icc=FALSE,show.re.var=FALSE)
不重新计算任何东西。从理论上讲,我认为 应该 可以跳过 resampling/recomputation 步骤,只需要 show.r2=FALSE, show.icc=FALSE
(即不需要获取 RE var),但是这将需要维护者 hacking/participation。
深入挖掘(通过使用 debug(rstan::sampling)
在 Stan 采样函数内部停止,然后 where
查看调用堆栈 ...
tab_model()
呼叫insight::get_variance()
hereinsight::get_variance.stanreg()
方法调用insight:::.compute_variances()
- ... 调用
insight:::.compute_variance_distribution()
- ...(对于 log-link 计数分布)调用
insight:::.variance_distributional()
- ... 调用
null_model
- ... 调用
.null_model_mixed()
- ... 调用
stats::update()