Skip to content

Commit

Permalink
Memory issue with ggpredict/predict_response of fixest object
Browse files Browse the repository at this point in the history
Fixes #604
  • Loading branch information
strengejacke committed Nov 13, 2024
1 parent d3abe0f commit 29a948b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions R/utils_get_data_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@
} else {
# adjust constant values, use all factor levels
re.grp <- insight::find_random(model, split_nested = TRUE, flatten = TRUE)
# add fixest cluster Variables
if (inherits(model, "fixest")) {
re.grp <- c(re.grp, insight::find_variables(model)$cluster)
}
# if factors should not be held constant (needed when computing
# std.error for merMod objects), we need all factor levels,
# and not just the typical value
Expand Down
4 changes: 2 additions & 2 deletions R/vcov.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ vcov.ggeffects <- function(object,
# in this case, remove those factors from model formula and vcov

re.terms <- insight::find_random(model, split_nested = TRUE, flatten = TRUE)

nlevels_terms <- vapply(
colnames(newdata),
function(.x) !(.x %in% re.terms) && is.factor(newdata[[.x]]) && nlevels(newdata[[.x]]) == 1,
Expand All @@ -204,7 +203,8 @@ vcov.ggeffects <- function(object,
colnames(newdata)[nlevels_terms]
)
model_terms <- stats::reformulate(all_terms, response = insight::find_response(model))
vcm <- vcm[!nlevels_terms, !nlevels_terms, drop = FALSE]
keep_vcov_cols <- attr(stats::terms(model_terms), "term.labels")
vcm <- vcm[keep_vcov_cols, keep_vcov_cols, drop = FALSE]
}

# sanity check - if "scale()" was used in formula, and that variable is
Expand Down

0 comments on commit 29a948b

Please sign in to comment.