Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 7, 2024
1 parent 90906be commit 98c30d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions R/compute_variances.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,17 @@
attr(vc2, "correlation") <- stats::cov2cor(model$D[vc_zi, vc_zi, drop = FALSE])
}

model_deviance <- get_deviance(model, verbose = FALSE)
residual_df <- get_df(model, type = "residual", verbose = FALSE)

vc1 <- list(vc1)
names(vc1) <- re_names[[1]]
attr(vc1, "sc") <- sqrt(get_deviance(model, verbose = FALSE) / get_df(model, type = "residual", verbose = FALSE))
attr(vc1, "sc") <- sqrt(abs(model_deviance) / residual_df)

if (!is.null(vc2)) {
vc2 <- list(vc2)
names(vc2) <- re_names[[2]]
attr(vc2, "sc") <- sqrt(get_deviance(model, verbose = FALSE) / get_df(model, type = "residual", verbose = FALSE))
attr(vc2, "sc") <- sqrt(abs(model_deviance) / residual_df)
}

vcorr <- compact_list(list(vc1, vc2))
Expand Down
8 changes: 5 additions & 3 deletions R/get_sigma.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ get_sigma <- function(x, ci = NULL, verbose = TRUE) {
}

if (is_empty_object(s)) {
s <- .safe(
sqrt(get_deviance(x, verbose = verbose) / get_df(x, type = "residual", verbose = verbose))
)
s <- .safe({
model_deviance <- get_deviance(x, verbose = verbose)
residual_df <- get_df(x, type = "residual", verbose = verbose)
sqrt(abs(model_deviance) / residual_df)
})
}

if (is_empty_object(s)) {
Expand Down
2 changes: 2 additions & 0 deletions R/null_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ null_model <- function(model, verbose = TRUE, ...) {
if (inherits(model, "MixMod")) {
nullform <- stats::as.formula(paste(find_response(model), "~ 1"))
null.model <- suppressWarnings(stats::update(model, fixed = nullform))
# fix fixed effects formula
null.model$call$fixed <- nullform
} else if (inherits(model, "cpglmm")) {
nullform <- find_formula(model, verbose = FALSE)[["random"]]
null.model <- suppressWarnings(stats::update(model, nullform))
Expand Down

0 comments on commit 98c30d7

Please sign in to comment.