File: methods_aod.R

package info (click to toggle)
r-cran-marginaleffects 0.32.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,784 kB
  • sloc: sh: 13; makefile: 8
file content (49 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#' @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)
}