-
Notifications
You must be signed in to change notification settings - Fork 5
/
MET.R
152 lines (138 loc) · 3.71 KB
/
MET.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#' Bootstrap minimum effect tests (METs)
#'
#' @param bmbstats_object Object of class \code{bmbstats}
#' @param estimator Name of the estimator from the \code{bmbstats_object}
#' @inheritParams basic_arguments
#' @return \code{bmbstats_MET} object
#' @export
#' @examples
#' mean_MET <- bootstrap_MET(
#' describe_data(rnorm(10, 100, 20)),
#' estimator = "mean",
#' SESOI_lower = 95,
#' SESOI_upper = 105,
#' alpha = 0.05
#' )
#' mean_MET
#' plot(mean_MET)
bootstrap_MET <- function(bmbstats_object,
estimator,
SESOI_lower = 0,
SESOI_upper = 0,
alpha = 0.05) {
if (class(bmbstats_object) != "bmbstats") {
stop("Please provide bmbstats object!", call. = FALSE)
}
if (SESOI_lower == SESOI_upper) {
warning("SESOI thresholds are equal.", immediate. = TRUE, call. = FALSE)
}
# TOST / Equivalence test
equivalence_lower_test <- bootstrap_NHST(
bmbstats_object, estimator,
SESOI_lower,
test = "greater"
)
equivalence_upper_test <- bootstrap_NHST(
bmbstats_object,
estimator,
SESOI_upper,
test = "less"
)
# This will be used later for plotting (assumed null distributions)
SESOI_lower_distribution <- equivalence_lower_test$distribution$null_distribution
SESOI_upper_distribution <- equivalence_upper_test$distribution$null_distribution
# Extract estimator info from equivalence_lower_test
# This is because those values are returned and are the same
# across all METs
estimator_value <- equivalence_lower_test$estimator$value
estimator_lower <- equivalence_lower_test$estimator$lower
estimator_upper <- equivalence_lower_test$estimator$upper
confidence <- equivalence_lower_test$estimator$confidence
# Only keep p_values
equivalence_lower <- equivalence_lower_test$result$p_value
equivalence_upper <- equivalence_upper_test$result$p_value
# Get higher p_value of the two
equivalence <- max(
equivalence_lower,
equivalence_upper
)
# METs
inferiority <- bootstrap_NHST(
bmbstats_object,
estimator,
SESOI_lower,
test = "less"
)$result$p_value
non_superiority <- bootstrap_NHST(
bmbstats_object,
estimator,
SESOI_upper,
test = "less"
)$result$p_value
non_inferiority <- bootstrap_NHST(
bmbstats_object,
estimator,
SESOI_lower,
test = "greater"
)$result$p_value
superiority <- bootstrap_NHST(
bmbstats_object,
estimator,
SESOI_upper,
test = "greater"
)$result$p_value
# Final Inference
final_inference <- ifelse(equivalence < alpha,
"Equivalent",
ifelse(superiority < alpha,
"Higher",
ifelse(inferiority < alpha,
"Lower",
ifelse(non_superiority < alpha,
"Not-Higher",
ifelse(non_inferiority < alpha,
"Not-Lower",
"Equivocal"
)
)
)
)
)
# Create return object
new_bootstrap_MET(
estimator = list(
name = estimator,
value = estimator_value,
lower = estimator_lower,
upper = estimator_upper,
confidence = confidence
),
test = list(
name = "MET",
test = c(
"inferiority",
"non-superiority",
"equivalence",
"non-inferiority",
"superiority"
),
SESOI_lower = SESOI_lower,
SESOI_upper = SESOI_upper,
alpha = alpha
),
result = list(
p_value = c(
inferiority,
non_superiority,
equivalence,
non_inferiority,
superiority
),
inference = final_inference
),
distribution = list(
SESOI_lower_distribution = SESOI_lower_distribution,
SESOI_upper_distribution = SESOI_upper_distribution
)
)
}