-
Notifications
You must be signed in to change notification settings - Fork 0
/
thresholdIntrinsic.R
52 lines (47 loc) · 1.74 KB
/
thresholdIntrinsic.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
#' Computes the p-value threshold for intrinsic credibility
#'
#' @param alpha Numeric vector of intrinsic credibility levels.
#' @param alternative Either "two.sided" (default) or "one.sided".
#' Specifies if the threshold is for one-sided or two-sided p-values.
#' @param type Either "Held" (default) or "Matthews".
#' Type of intrinsic p-value threshold, see Held (2019) and Matthews (2018)
#' for more information.
#' @return The threshold for intrinsic credibility.
#' @references
#' Matthews, R. A. J. (2018). Beyond 'significance': principles and
#' practice of the analysis of credibility. \emph{Royal Society Open
#' Science}, \bold{5}, 171047. \doi{10.1098/rsos.171047}
#'
#' Held, L. (2019). The assessment of intrinsic credibility and a new argument
#' for \emph{p < 0.005}. \emph{Royal Society Open Science}, \bold{6}, 181534.
#' \doi{10.1098/rsos.181534}
#' @author Leonhard Held
#' @examples
#' thresholdIntrinsic(alpha = c(0.005, 0.01, 0.05))
#' thresholdIntrinsic(alpha = c(0.005, 0.01, 0.05), alternative = "one.sided")
#' @export
thresholdIntrinsic <- function(
alpha,
alternative = c("two.sided", "one.sided"),
type = c("Held", "Matthews")
) {
stopifnot(is.numeric(alpha),
length(alpha) > 0,
is.finite(alpha),
0 < alpha, alpha <= 1,
!is.null(alternative))
alternative <- match.arg(alternative)
stopifnot(!is.null(type))
type <- match.arg(type)
z <- p2z(p = alpha, alternative = alternative)
if (type == "Held") {
result <- z2p(z = sqrt(2) * z, alternative = alternative)
} else {
## type is "Matthews"
result <- z2p(
z = sqrt(2) * z / sqrt(sqrt(5) - 1),
alternative = alternative
)
}
return(result)
}