Skip to content

Commit 3f0cf6f

Browse files
committed
sup-t option for p_adjust
1 parent b9db7ae commit 3f0cf6f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

R/format_p_adjust.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ format_p_adjust <- function(method) {
3636
## TODO add "mvt" method from emmeans
3737

3838
# prepare arguments
39-
all_methods <- c(stats::p.adjust.methods, "tukey", "scheffe", "sidak")
39+
all_methods <- c(stats::p.adjust.methods, "tukey", "scheffe", "sidak", "sup-t")
4040

4141
# for interaction terms, e.g. for "by" argument in emmeans
4242
# pairwise comparison, we have to adjust the rank resp. the
@@ -107,6 +107,16 @@ format_p_adjust <- function(method) {
107107
} else if (tolower(p_adjust) == "sidak") {
108108
# sidak adjustment
109109
params$p <- 1 - (1 - params$p)^(nrow(params) / rank_adjust)
110+
} else if (tolower(p_adjust) == "sup-t") {
111+
insight::check_if_installed("mvtnorm")
112+
vc <- .safe(cov2cor(insight::get_vcov(model)))
113+
if (is.null(vc)) {
114+
insight::format_warning("Could not calculate covariance matrix for `sup-t` adjustment.")
115+
return(params)
116+
}
117+
ci_level <- mvtnorm::qmvt(0.95, df = params$df, tail = "both.tails", corr = vc)$quantile
118+
crit <- 1 - 2 * pt(-abs(ci_level), df = params$df)
119+
params$p <- .p_value_dof()
110120
}
111121

112122
if (isTRUE(all(old_p_vals == params$p)) && !identical(p_adjust, "none") && verbose) {

0 commit comments

Comments
 (0)