-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
methods_multcomp.R
119 lines (108 loc) · 2.78 KB
/
methods_multcomp.R
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#' Parameters from Hypothesis Testing
#'
#' Parameters from Hypothesis Testing.
#'
#' @param model Object of class [multcomp::glht()] (**multcomp**)
#' or of class `PMCMR`, `trendPMCMR` or `osrt` (**PMCMRplus**).
#' @inheritParams model_parameters.default
#'
#' @return A data frame of indices related to the model's parameters.
#'
#' @examples
#' \donttest{
#' if (require("multcomp", quietly = TRUE)) {
#' # multiple linear model, swiss data
#' lmod <- lm(Fertility ~ ., data = swiss)
#' mod <- glht(
#' model = lmod,
#' linfct = c(
#' "Agriculture = 0",
#' "Examination = 0",
#' "Education = 0",
#' "Catholic = 0",
#' "Infant.Mortality = 0"
#' )
#' )
#' model_parameters(mod)
#' }
#' if (require("PMCMRplus", quietly = TRUE)) {
#' model <- suppressWarnings(
#' kwAllPairsConoverTest(count ~ spray, data = InsectSprays)
#' )
#' model_parameters(model)
#' }
#' }
#' @export
model_parameters.glht <- function(model,
ci = 0.95,
exponentiate = FALSE,
keep = NULL,
drop = NULL,
verbose = TRUE,
...) {
# p-adjustment method
s <- summary(model)
p_adjust <- s$test$type
out <- .model_parameters_generic(
model = model,
ci = ci,
bootstrap = FALSE,
iterations = 10,
merge_by = "Parameter",
standardize = NULL,
exponentiate = exponentiate,
p_adjust = NULL,
keep_parameters = keep,
drop_parameters = drop,
verbose = verbose,
...
)
attr(out, "p_adjust") <- p_adjust
attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
out
}
#' @export
ci.glht <- function(x, ci = 0.95, ...) {
# backward compatibility with `robust` argument
dots <- list(...)
if ("robust" %in% names(dots) && !"vcov" %in% names(dots)) {
robust <- dots[["robust"]]
} else if (any(c("vcov", "vcov_args") %in% names(dots))) {
robust <- TRUE
} else {
robust <- FALSE
}
s <- summary(x)
if (robust) {
adjusted_ci <- 2 * stats::pnorm(s$test$qfunction(ci)) - 1
dof <- Inf
} else {
adjusted_ci <- ci
dof <- x$df
}
out <- .ci_generic(model = x, ci = adjusted_ci, dof = dof, ...)
if (robust) {
out$CI <- ci
}
out
}
#' @export
standard_error.glht <- function(model, ...) {
s <- summary(model)
.data_frame(
Parameter = insight::find_parameters(model, flatten = TRUE),
SE = unname(s$test$sigma)
)
}
#' @export
degrees_of_freedom.glht <- function(model, ...) {
model$df
}
#' @export
p_value.glht <- function(model, ...) {
s <- summary(model)
.data_frame(
Parameter = insight::find_parameters(model, flatten = TRUE),
p = unname(s$test$pvalues)
)
}