Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 12, 2024
1 parent aeba253 commit 7c538ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions R/compute_variances.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

# we also need necessary model information, like fixed and random effects,
# variance-covariance matrix etc. for the null model
model_null <- null_model(x, verbose = FALSE)
model_null <- .safe(null_model(x, verbose = FALSE))
vals_null <- .get_variance_information(
model_null,
faminfo = faminfo,
Expand Down Expand Up @@ -101,7 +101,7 @@
}

# Variance of random effects for NULL model
if (!performance::check_singularity(model_null, tolerance = tolerance)) {
if (!performance::check_singularity(model_null, tolerance = tolerance) && !is.null(vals_null)) {
# Separate observation variance from variance of random effects
nr <- vapply(vals_null$re, nrow, numeric(1))
not.obs.terms_null <- names(nr[nr != n_obs(model_null)])
Expand Down Expand Up @@ -206,6 +206,11 @@
name_fun = "get_variances",
verbose = TRUE,
model_component = "conditional") {
# sanity check
if (is.null(x)) {
return(NULL)
}

# installed?
check_if_installed("lme4", reason = "to compute variances for mixed models")

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-lme.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ m1 <- nlme::lme(Reaction ~ Days,
m2 <- nlme::lme(distance ~ age + Sex, data = Orthodont, random = ~1)

set.seed(123)
sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE)
sleepstudy$mygrp <- sample.int(5, size = 180, replace = TRUE)
sleepstudy$mysubgrp <- NA
for (i in 1:5) {
filter_group <- sleepstudy$mygrp == i
sleepstudy$mysubgrp[filter_group] <-
sample(1:30, size = sum(filter_group), replace = TRUE)
sample.int(30, size = sum(filter_group), replace = TRUE)
}

m3 <- nlme::lme(Reaction ~ Days,
Expand Down

0 comments on commit 7c538ae

Please sign in to comment.