Skip to content

Commit ac929b3

Browse files
committed
fix
1 parent d11ecd5 commit ac929b3

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

R/compare_parameters.R

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ compare_parameters <- function(...,
169169
dat <- model
170170
} else {
171171
# set default-ci_type for Bayesian models
172-
if (.is_bayesian_model(model, exclude = c("bmerMod", "bayesx", "blmerMod", "bglmerMod")) && !ci_method %in% c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai")) { # nolint
172+
if (insight::is_bayesian_model(model, exclude = c("bmerMod", "bayesx", "blmerMod", "bglmerMod")) && !ci_method %in% c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai")) { # nolint
173173
ci_method_tmp <- "eti"
174174
} else {
175175
ci_method_tmp <- ci_method
@@ -305,19 +305,3 @@ compare_models <- compare_parameters
305305
}
306306
x
307307
}
308-
309-
310-
.is_bayesian_model <- function(x, exclude = NULL) {
311-
bayes_classes <- c(
312-
"brmsfit", "stanfit", "MCMCglmm", "stanreg",
313-
"stanmvreg", "bmerMod", "BFBayesFactor", "bamlss",
314-
"bayesx", "mcmc", "bcplm", "bayesQR", "BGGM",
315-
"meta_random", "meta_fixed", "meta_bma", "blavaan",
316-
"blrm", "blmerMod"
317-
)
318-
# if exclude is not NULL, remove elements in exclude from bayes_class
319-
if (!is.null(exclude)) {
320-
bayes_classes <- bayes_classes[!bayes_classes %in% exclude]
321-
}
322-
inherits(x, bayes_classes)
323-
}

R/extract_random_variances.R

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -689,31 +689,8 @@ as.data.frame.VarCorr.lme <- function(x, row.names = NULL, optional = FALSE, ...
689689
# store essential information about variance components...
690690
# basically, this function should return lme4::VarCorr(x)
691691
.get_variance_information <- function(model, model_component = "conditional") {
692-
# reason to be installed
693-
reason <- "to compute random effect variances for mixed models"
694-
695-
# installed?
696-
insight::check_if_installed("lme4", reason = reason)
697-
698-
if (inherits(model, "lme")) {
699-
insight::check_if_installed("nlme", reason = reason)
700-
}
701-
702-
if (inherits(model, "clmm")) {
703-
insight::check_if_installed("ordinal", reason = reason)
704-
}
705-
706-
if (inherits(model, "brmsfit")) {
707-
insight::check_if_installed("brms", reason = reason)
708-
}
709-
710-
if (inherits(model, "cpglmm")) {
711-
insight::check_if_installed("cplm", reason = reason)
712-
}
713-
714-
if (inherits(model, "rstanarm")) {
715-
insight::check_if_installed("rstanarm", reason = reason)
716-
}
692+
# check if packages are available
693+
.check_mixedmodels_namespace(model)
717694

718695
# stanreg
719696
# ---------------------------
@@ -835,6 +812,39 @@ as.data.frame.VarCorr.lme <- function(x, row.names = NULL, optional = FALSE, ...
835812
}
836813

837814

815+
.check_mixedmodels_namespace <- function(model) {
816+
# reason to be installed
817+
reason <- "to compute random effect variances for mixed models"
818+
819+
# installed?
820+
insight::check_if_installed("lme4", reason = reason)
821+
822+
if (inherits(model, "lme")) {
823+
insight::check_if_installed("nlme", reason = reason)
824+
}
825+
826+
if (inherits(model, "glmmTMB")) {
827+
insight::check_if_installed("glmmTMB", reason = reason)
828+
}
829+
830+
if (inherits(model, "clmm")) {
831+
insight::check_if_installed("ordinal", reason = reason)
832+
}
833+
834+
if (inherits(model, "brmsfit")) {
835+
insight::check_if_installed("brms", reason = reason)
836+
}
837+
838+
if (inherits(model, "cpglmm")) {
839+
insight::check_if_installed("cplm", reason = reason)
840+
}
841+
842+
if (inherits(model, "rstanarm")) {
843+
insight::check_if_installed("rstanarm", reason = reason)
844+
}
845+
}
846+
847+
838848
# glmmTMB returns a list of model information, one for conditional
839849
# and one for zero-inflation part, so here we "unlist" it, returning
840850
# only the conditional part.

0 commit comments

Comments
 (0)