R/hypothesis.R

Defines functions get_hypothesis

get_hypothesis <- function(
    x,
    hypothesis,
    by = NULL,
    newdata = NULL,
    draws = NULL) {
    deprecated <- c("pairwise", "revpairwise", "sequential", "revsequential", "reference", "meandev", "meanotherdev", "revreference")
    if (isTRUE(checkmate::check_choice(hypothesis, deprecated))) {
        msg <- "This string is deprecated for use in the `hypothesis` argument. Use the formula interface instead. Ex: `hypothesis=~reference`"
        stop(msg, call. = FALSE)
    }

    # otherwise setDT strips out the marginaleffects-specific classes
    x <- data.table::copy(x)

    vec <- isTRUE(checkmate::check_atomic_vector(hypothesis)) &&
        isTRUE(checkmate::check_numeric(hypothesis))
    mat <- isTRUE(checkmate::check_matrix(hypothesis))

    if (is.null(hypothesis)) {
        data.table::setDT(x)
        return(x)
    } else if (isTRUE(checkmate::check_formula(hypothesis))) {
        out <- hypothesis_formula(x, newdata = newdata, hypothesis = hypothesis, by = by)
        return(out)
    } else if (isTRUE(checkmate::check_function(hypothesis))) {
        out <- hypothesis_function(x, newdata = newdata, hypothesis = hypothesis, by = by)
        return(out)
    } else if (vec || mat) {
        out <- hypothesis_matrix(x, hypothesis = hypothesis)
        return(out)
    } else if (is.character(hypothesis)) {
        out <- hypothesis_string(x, hypothesis = hypothesis)
        return(out)
    }

    stop("`hypothesis` is broken. Please report this bug with a reproducible example: https://github.com/vincentarelbundock/marginaleffects/issues.", call. = FALSE)
}

Try the marginaleffects package in your browser

Any scripts or data that you put into this service are public.

marginaleffects documentation built on April 4, 2025, 4:36 a.m.