File: multcomp.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 (42 lines) | stat: -rw-r--r-- 957 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
multcomp_test <- function(
    object,
    multcomp = FALSE,
    conf_level = 0.95,
    df = Inf
) {
    valid <- c(
        "holm",
        "hochberg",
        "hommel",
        "bonferroni",
        "BH",
        "BY",
        "fdr",
        "single-step",
        "Shaffer",
        "Westfall",
        "free"
    )
    checkmate::assert(
        checkmate::check_choice(multcomp, choices = valid),
        checkmate::check_flag(multcomp)
    )

    if (isFALSE(multcomp)) {
        return(object)
    }

    if (isTRUE(multcomp)) multcomp <- "holm"

    insight::check_if_installed("multcomp")

    k <- multcomp::glht(object, df = df)
    k <- summary(k, test = multcomp::adjusted(type = multcomp))
    k <- stats::confint(k, level = conf_level)
    object$p.value <- k$test$pvalues
    object$conf.low <- k$confint[, 2, drop = TRUE]
    object$conf.high <- k$confint[, 3, drop = TRUE]
    object$s.value <- -log2(object$p.value)

    return(object)
}