twosidedpval: Computation of Conditional Two-Sided p-Values

View source: R/twosidedpval.R

twosidedpvalR Documentation

Computation of Conditional Two-Sided p-Values

Description

Computes the conditional p-value P_C for a continuous or discrete test statistic, as defined in \insertCiteKulinskaya08;textualskedastic. This provides a method for computing a two-sided p-value from an asymmetric null distribution.

Usage

twosidedpval(
  q,
  CDF,
  continuous,
  method = c("doubled", "kulinskaya", "minlikelihood"),
  locpar,
  supportlim = c(-Inf, Inf),
  ...
)

Arguments

q

A double representing the quantile, i.e. the observed value of the test statistic for which a two-sided p-value is to be computed

CDF

A function representing the cumulative distribution function of the test statistic under the null hypothesis, i.e. \Pr(T≤ q|\mathrm{H}_0).

continuous

A logical indicating whether the test statistic is a continuous (TRUE) or discrete (FALSE) random variable. Defaults to TRUE.

method

A character specifying the method to use to calculate two-sided p-value; one of "doubled" (representing doubling of the one-sided p-value), "kulinskaya" (representing the method of \insertCiteKulinskaya08;textualskedastic), or "minlikelihood" (representing the sum of probabilities for values with probability less than or equal to that of the observed value. Partial matching is used. Note that the "minlikelihood" method is available only for discrete distributions.

locpar

a double representing a generic location parameter chosen to separate the tails of the distribution. Note that if locpar corresponds to the median of CDF, there is no difference between the two methods, in the continuous case. If locpar is not specified, the function attempts to compute the expectation of CDF using numerical integration and, if successful, uses this as locpar. However, this may yield unexpected results, especially if CDF is not one of the cumulative distribution functions of well-known distributions included in the stats package.

supportlim

A numeric vector of length 2, giving the minimum and maximum values in the support of the distribution whose cumulative distribution function is CDF. This argument is only used if the distribution is discrete (i.e. if continuous is FALSE) and if method is "minlikelihood" or locpar is not specified. If supportlim is not supplied, the function assumes that the support is -1e6:1e6. Values of -Inf and Inf may be supplied, but if so, the support is truncated at -1e6 and 1e6 respectively.

...

Optional arguments to pass to CDF.

Details

Let T be a statistic that, under the null hypothesis, has cumulative distribution function F and probability density or mass function f. Denote by A a generic location parameter chosen to separate the two tails of the distribution. Particular examples include the mean E(T|\mathrm{H}_0), the mode \arg \sup_{t} f(t), or the median F^{-1}≤ft(\frac{1}{2}\right). Let q be the observed value of T.

In the continuous case, the conditional two-sided p-value centered at A is defined as

P_C^A(q)=\frac{F(q)}{F(A)}1_{q ≤ A} + \frac{1-F(q)}{1-F(A)}1_{q > A}

where 1_{\cdot} is the indicator function. In the discrete case, P_C^A depends on whether A is an attainable value within the support of T. If A is not attainable, the conditional two-sided p-value centred at A is defined as

P_C^{A}(q)=\frac{\Pr(T≤ q)}{\Pr(T<A)}1_{q<A} + \frac{\Pr(T≥ q)}{\Pr(T>A)}1_{q>A}

If A is attainable, the conditional two-sided p-value centred at A is defined as

P_C^{A}(q)=\frac{\Pr(T≤ q)}{\Pr(T≤ A)/≤ft(1+\Pr(T=A)\right)} 1_{q<A} + 1_{q=A}+\frac{\Pr(T≥ q)}{\Pr(T ≥ A)/≤ft(1+\Pr(T=A)\right)} 1_{q>A}

Value

A double.

References

\insertAllCited

Examples

# Computation of two-sided p-value for F test for equality of variances
n1 <- 10
n2 <- 20
set.seed(1234)
x1 <- stats::rnorm(n1, mean = 0, sd = 1)
x2 <- stats::rnorm(n2, mean = 0, sd = 3)
# 'Conventional' two-sided p-value obtained by doubling one-sided p-value:
stats::var.test(x1, x2, alternative = "two.sided")$p.value
# This is replicated in `twosidedpval` by setting `method` argument to `"doubled"`
twosidedpval(q = var(x1) / var(x2), CDF = stats::pf, continuous = TRUE,
 method = "doubled", locpar = 1, df1 = n1 - 1, df2 = n2 - 1)
# Conditional two-sided p-value centered at df (mean of chi-squared r.v.):
twosidedpval(q = var(x1) / var(x2), CDF = stats::pf, continuous = TRUE,
 method = "kulinskaya", locpar = 1, df1 = n1 - 1, df2 = n2 - 1)

skedastic documentation built on Nov. 10, 2022, 5:43 p.m.