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.frame(
        rowid = 1:nrow(newdata),
        estimate = out)

    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.")
    }
    aod::vcov(model)
}


#' @rdname sanitize_model_specific
sanitize_model_specific.glimML <- function(model, ...) {
    mdat <- get_modeldata(model, additional_variables = FALSE)
    if (isTRUE("character" %in% attr(mdat, "marginaleffects_variable_class"))) {
        insight::format_error("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 Oct. 20, 2023, 1:07 a.m.