IQSS / clarify

clarify: Simulation-Based Inference for Regression Models

Home Page:https://iqss.github.io/clarify/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of dist="t(df)" when df.residual(fit) is not NULL

wviechtb opened this issue · comments

Thanks for writing this package!

I tried this out in combination with the metafor package. Given that df.residual(res) is not NULL, according to the docs I would have expected sim() to simulate using dist="t(df)" but that is not what is happening. Am I misunderstanding something or is this a bug?

A reproducible example:

library(metafor)
library(clarify)

### calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)

### random-effects model
res <- rma(yi, vi, data=dat)
res

### average risk ratio with 95% CI
predict(res, transf=exp)

### use clarify
set.seed(1234)
sims <- sim(res)
sims # sampled from MVN
sav <- sim_apply(sims, function(coefs) c(RR = mean(exp(coefs))), verbose=FALSE)
summary(sav, null=c(`RR`=1))

# but according to the docs, it should use dist="t(df)" when df.residual(res) is not NULL
df.residual(res)

Thank you for the comment and sorry about this confusion! The documentation is outdated and needs to be fixed. We no longer rely on df.residual() but rather on functions in insight that attempt to extract the right degrees of freedom, in particular insight::get_df(). insight has detected that the distribution of the model coefficients is normal, so that makes its way to clarify as well. Of course, you can supply your own df, and in practice, this will not make much of a difference. But I will definitely fix that documentation issue.