binom_test_pv {DiscreteTests} | R Documentation |
Binomial Tests
Description
binom_test_pv()
performs an exact or approximate binomial test about the
probability of success in a Bernoulli experiment. In contrast to
stats::binom.test()
, it is vectorised, only calculates p-values and
offers a normal approximation of their computation. Furthermore, it is
capable of returning the discrete p-value supports, i.e. all observable
p-values under a null hypothesis. Multiple tests can be evaluated
simultaneously. In two-sided tests, several procedures of obtaining the
respective p-values are implemented.
Note: Please use binom_test_pv()
! The older binom.test.pv()
is
deprecated in order to migrate to snake case. It will be removed in a future
version.
Usage
binom_test_pv(
x,
n,
p = 0.5,
alternative = "two.sided",
ts_method = "minlike",
exact = TRUE,
correct = TRUE,
simple_output = FALSE
)
binom.test.pv(
x,
n,
p = 0.5,
alternative = "two.sided",
ts.method = "minlike",
exact = TRUE,
correct = TRUE,
simple.output = FALSE
)
Arguments
x |
integer vector giving the number of successes. |
n |
integer vector giving the number of trials. |
p |
numerical vector of hypothesised probabilities of success. |
alternative |
character vector that indicates the alternative hypotheses; each value must be one of |
ts_method , ts.method |
single character string that indicates the two-sided p-value computation method (if any value in |
exact |
logical value that indicates whether p-values are to be calculated by exact computation ( |
correct |
logical value that indicates if a continuity correction is to be applied ( |
simple_output , simple.output |
logical value that indicates whether an R6 class object, including the tests' parameters and support sets, i.e. all observable p-values under each null hypothesis, is to be returned (see below). |
Details
The parameters x
, n
, p
and alternative
are vectorised. They are
replicated automatically to have the same lengths. This allows multiple
hypotheses to be tested simultaneously.
If p = NULL
, it is tested if the probability of success is 0.5 with
the alternative being specified by alternative
.
For exact computation, various procedures of determining two-sided p-values are implemented.
"minlike"
The standard approach in
stats::fisher.test()
andstats::binom.test()
. The probabilities of the likelihoods that are equal or less than the observed one are summed up. In Hirji (2006), it is referred to as the Probability-based approach."blaker"
The minima of the observations' lower and upper tail probabilities are combined with the opposite tail not greater than these minima. More details can be found in Blaker (2000) or Hirji (2006), where it is referred to as the Combined Tails method.
"absdist"
The probabilities of the absolute distances from the expected value that are greater than or equal to the observed one are summed up. In Hirji (2006), it is referred to as the Distance from Center approach.
"central"
The smaller values of the observations' simply doubles the minimum of lower and upper tail probabilities. In Hirji (2006), it is referred to as the Twice the Smaller Tail method.
For non-exact (i.e. continuous approximation) approaches, ts_method
is
ignored, since all its methods would yield the same p-values. More
specifically, they all converge to the doubling approach as in
ts_mthod = "central"
.
Value
If simple.output = TRUE
, a vector of computed p-values is returned.
Otherwise, the output is a DiscreteTestResults
R6 class object, which
also includes the p-value supports and testing parameters. These have to be
accessed by public methods, e.g. $get_pvalues()
.
References
Agresti, A. (2002). Categorical data analysis (2nd ed.). New York: John Wiley & Sons. pp. 14-15. doi:10.1002/0471249688
Blaker, H. (2000) Confidence curves and improved exact confidence intervals for discrete distributions. Canadian Journal of Statistics, 28(4), pp. 783-798. doi:10.2307/3315916
Hirji, K. F. (2006). Exact analysis of discrete data. New York: Chapman and Hall/CRC. pp. 55-83. doi:10.1201/9781420036190
See Also
Examples
# Constructing
k <- c(4, 2, 2, 14, 6, 9, 4, 0, 1)
n <- c(18, 12, 10)
p <- c(0.5, 0.2, 0.3)
# Computation of exact two-sided p-values ("blaker") and their supports
results_ex <- binom_test_pv(k, n, p, ts_method = "blaker")
raw_pvalues <- results_ex$get_pvalues()
pCDFlist <- results_ex$get_pvalue_supports()
# Computation of normal-approximated one-sided p-values ("less") and their supports
results_ap <- binom_test_pv(k, n, p, "less", exact = FALSE)
raw_pvalues <- results_ap$get_pvalues()
pCDFlist <- results_ap$get_pvalue_supports()