Skip to content

Commit

Permalink
use default type dictionary, so we can override when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 17, 2025
1 parent 212df20 commit e890354
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions R/get_marginaleffects_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
return(list(predict = predict, backtransform = FALSE, link_inverse = NULL))
}

# extract all valid types for model class
# extract all valid types and the default type for model class
valid_types <- .valid_marginaleffects_types(model)
default_type <- .default_marginaleffects_types(model)

# find link-types - we need link-type when user wants bias-correction
link_types <- c("link", "linear.predictor", "lp")
Expand Down Expand Up @@ -72,7 +73,7 @@
if (is.null(dots$type)) {
link_inverse <- .link_inverse(model, verbose = verbose, ...)
if (is.null(predict)) {
out <- valid_types[1]
out <- default_type
} else {
out <- predict
}
Expand Down Expand Up @@ -103,7 +104,7 @@
}


# return default "type" argument - this differs, depending on model class
# return all "type" arguments
.valid_marginaleffects_types <- function(model) {
model_class <- class(model)[1]
# for unrecognized model classes, return "response"
Expand All @@ -115,6 +116,20 @@
}


# return default type argument for model class, as defined in marginaleffecs
# we can overwrite the default, e.g. using "inverse_link" as an option when
# not provided by marginaleffects, in the ".default_type" data frame
.default_marginaleffects_types <- function(model) {
model_class <- class(model)[1]
# for unrecognized model classes, return "response"
if (!model_class %in% .default_type$class) {
return("response")
}
# extract all valid types for model class
.default_type$type[.default_type$class == model_class]
}


# all valid "type" arguments for each model class.
# Run "marginaleffects:::type_dictionary_build()" to update this list
.typedic <- data.frame(
Expand Down

0 comments on commit e890354

Please sign in to comment.