Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/complete_levels.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ complete_levels <- function(x, character_levels = NULL) {
# HACK: Some models use a character variable with many levels (e.g.,
# mixed-effects groups). This creates a massive padding dataset, and making
# predictions can become very expensive.
if (isTRUE(sum(sapply(vault, length)) > 100)) return(data.frame())
if (isTRUE(sum(lengths(vault)) > 100)) return(data.frame())

padding <- utils::head(x, 1)
data.table::setDT(padding)
Expand Down
2 changes: 1 addition & 1 deletion R/datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ datagrid_engine <- function(
out <- lapply(out, unique)

# warn on very large prediction grid
num <- as.numeric(sapply(out, length)) # avoid integer overflow
num <- as.numeric(lengths(out)) # avoid integer overflow
num <- Reduce(f = "*", num)
if (isTRUE(num > 1e9)) {
stop("You are trying to create a prediction grid with more than 1 billion rows, which is likely to exceed the memory and computational power available on your local machine. Presumably this is because you are considering many variables with many levels. All of the functions in the `marginaleffects` package include arguments to specify a restricted list of variables over which to create a prediction grid.", call. = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/get_se_delta.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ get_se_delta <- function(model,

# delta method does not work for these models
bad <- c("brmsfit", "stanreg", "bart")
if (any(bad %in% class(model))) {
if (any(inherits(model, bad))) {
return(NULL)
}

Expand Down
4 changes: 2 additions & 2 deletions R/get_term_labels.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
get_term_labels <- function(x, idx = NULL) {
if (is.data.frame(x)) {
if ("term" %in% names(x) && length(unique(x$term)) == nrow(x)) {
if ("term" %in% names(x) && anyDuplicated(x$term) == 0L) {
return(unique(x$term))
} else if (any(grepl("^contrast", names(x)))) {
tmp <- grep("^term$|^contrast", names(x))
Expand All @@ -23,4 +23,4 @@ get_term_labels <- function(x, idx = NULL) {
}
if (!is.null(idx)) out <- out[idx]
return(out)
}
}
2 changes: 1 addition & 1 deletion R/methods_aod.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ get_predict.glimML <- function(model,
type = type,
...)
out <- data.frame(
rowid = 1:nrow(newdata),
rowid = seq_len(nrow(newdata)),
estimate = out)

return(out)
Expand Down
2 changes: 1 addition & 1 deletion R/methods_brms.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ get_predict.brmsfit <- function(model,
} else if ("rowid" %in% colnames(newdata)) {
idx <- newdata[["rowid"]]
} else {
idx <- 1:nrow(newdata)
idx <- seq_len(nrow(newdata))
}

# resp_subset sometimes causes dimension mismatch
Expand Down
2 changes: 1 addition & 1 deletion R/methods_crch.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ get_predict.crch <- function(model,
sanity_predict_vector(pred = pred, model = model, newdata = newdata, type = type)
sanity_predict_numeric(pred = pred, model = model, newdata = newdata, type = type)
out <- data.frame(
rowid = 1:nrow(newdata),
rowid = seq_len(nrow(newdata)),
estimate = pred)
return(out)
}
Expand Down
2 changes: 1 addition & 1 deletion R/methods_gamlss.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ set_coef.gamlss <- function(model, coefs, ...){
len[is.null(len)] <- 1
data <- rbind(...)
} else {
len <- sapply(tmp, length)
len <- lengths(tmp)
data <- unlist(tmp)
}
namelist <- factor(rep(names, len), levels = names)
Expand Down
2 changes: 1 addition & 1 deletion R/methods_glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ get_predict.glmmTMB <- function(model,

np <- model$fit$par
if (!is.null(newparams)) {
np[1:length(newparams)] <- newparams
np[seq_along(newparams)] <- newparams
}

out <- get_predict.default(
Expand Down
2 changes: 1 addition & 1 deletion R/methods_nnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ get_predict.multinom <- function(model,
if (is_latent && is_mclogit) {
missing_level <- as.character(unique(insight::get_response(model)))
missing_level <- setdiff(missing_level, colnames(pred))
if (length(missing_level == 1)) {
if (length(missing_level) == 1) {
pred <- cbind(0, pred)
colnames(pred)[1] <- missing_level
pred <- pred - rowMeans(pred)
Expand Down
2 changes: 1 addition & 1 deletion R/methods_ordinal.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ get_predict.clm <- function(model,
if ("rowid" %in% colnames(newdata)) {
out$rowid <- rep(newdata$rowid, times = ncol(pred))
} else {
out$rowid <- rep(1:nrow(pred), times = ncol(pred))
out$rowid <- rep(seq_len(nrow(pred)), times = ncol(pred))
}

return(out)
Expand Down