R/methods_aod.R

Defines functions sanitize_model_specific.glimML get_vcov.glimML set_coef.glimML get_predict.glimML

Documented in get_predict.glimML get_vcov.glimML sanitize_model_specific.glimML set_coef.glimML

#' @rdname get_predict
#' @export
get_predict.glimML <- function(
    model,
    newdata = insight::get_data(model),
    type = "response",
    ...) {
    insight::check_if_installed("aod")

    out <- aod::predict(model, newdata = newdata, type = type, ...)
    out <- data.table(estimate = out)
    out <- add_rowid(out, newdata)

    return(out)
}


#' @rdname set_coef
#' @export
set_coef.glimML <- function(model, coefs, ...) {
    # in basic model classes coefficients are named vector
    model@fixed.param[names(coefs)] <- coefs
    model
}


#' @rdname get_vcov
#' @export
get_vcov.glimML <- function(model, vcov = NULL, ...) {
    insight::check_if_installed("aod")
    if (!is.null(vcov) && !is.logical(vcov)) {
        stop("The `vcov` argument is not supported for this kind of model.")
    }
    vcov <- sanitize_vcov(model, vcov)
    aod::vcov(model)
}


#' @rdname sanitize_model_specific
sanitize_model_specific.glimML <- function(model, ...) {
    mdat <- get_modeldata(model)
    cl <- detect_variable_class(mdat, model = model)
    if (isTRUE("character" %in% cl)) {
        stop_sprintf(
            "This function does not support character predictors. Please convert them to factors before fitting the model."
        )
    }
    return(model)
}

Try the marginaleffects package in your browser

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

marginaleffects documentation built on Sept. 13, 2025, 5:07 p.m.