/
calibrate.R
51 lines (51 loc) · 1.51 KB
/
calibrate.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
#' Calibrate critical value and p-value
#'
#' Calibrate critical value and p-value in [elt()].
#'
#' @param alpha A single numeric.
#' @param statistic A single numeric.
#' @param calibrate A single character.
#' @param p A single integer.
#' @param par A numeric vector.
#' @param object An object that inherits from class \linkS4class{EL}.
#' @param control An object of class of \linkS4class{ControlEL}.
#' @return A numeric vector of length two for the critical value and the
#' p-value.
#' @noRd
calibrate <- function(calibrate, alpha, statistic, p, par, object, control) {
switch(calibrate,
"ael" = {
c(
cv = qchisq(1 - alpha, df = p),
pval = pchisq(statistic, df = p, lower.tail = FALSE)
)
},
"boot" = {
seed <- if (is.null(control@seed)) {
sample.int(.Machine$integer.max, 1L)
} else {
control@seed
}
compute_bootstrap_calibration(
alpha, statistic, control@b, seed, control@nthreads,
getMethodEL(object), getData(object), par, coef(object),
control@maxit_l, control@tol_l, control@th, getWeights(object)
)
},
"chisq" = {
c(
cv = qchisq(1 - alpha, df = p),
pval = pchisq(statistic, df = p, lower.tail = FALSE)
)
},
"f" = {
n <- nrow(getData(object))
c(
cv = qf(1 - alpha, df1 = p, df2 = n - p) * (p * (n - 1)) / (n - p),
pval = pf(statistic * (n - p) / (p * (n - 1)),
df1 = p, df2 = n - p, lower.tail = FALSE
)
)
}
)
}