This vignette describes nonparametric estimates of distribution summaries and quantiles, followed by rank and permutation tests for comparing two samples. It includes extensions for censored observations and the assumptions behind the estimates, confidence intervals, and tests.

Related vignettes:

enpar

Help topic: enpar.

Let x_=(x1,x2,…,xN)\underline{x} = (x_1, x_2, \ldots, x_N) denote a vector of NN observations from some distribution with mean μ\mu and standard deviation σ\sigma.

Estimation
Unbiased and consistent estimators of the mean and variance are:

μ̂=x‾=1n∑i=1nxi(1) \hat{\mu} = \bar{x} = \frac{1}{n} \sum_{i=1}^n x_i \;\;\;\; (1)

σ̂2=s2=1n−1∑i=1n(xi−x‾)2(2) \hat{\sigma}^2 = s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2 \;\;\;\; (2)

A consistent (but not unbiased) estimate of the standard deviation is given by the square root of the estimated variance above:

σ̂=s(3) \hat{\sigma} = s \;\;\;\; (3)

It can be shown that the variance of the sample mean is given by:

σμ̂2=σx‾2=σ2n(4) \sigma^2_{\hat{\mu}} = \sigma^2_{\bar{x}} = \frac{\sigma^2}{n} \;\;\;\; (4)

so the standard deviation of the sample mean (usually called the standard error) can be estimated by:

σ̂μ̂=σ̂x‾=sn(5) \hat{\sigma}_{\hat{\mu}} = \hat{\sigma}_{\bar{x}} = \frac{s}{\sqrt{n}} \;\;\;\; (5)

Confidence Intervals
This section explains how confidence intervals for the mean μ\mu are computed.

Normal Approximation (ci.method="normal.approx")
This method constructs approximate (1−α)100%(1-\alpha)100\% confidence intervals for μ\mu based on the assumption that the estimator of μ\mu, i.e., the sample mean, is approximately normally distributed. That is, a two-sided (1−α)100%(1-\alpha)100\% confidence interval for μ\mu is constructed as:

[μ̂−t1−α/2,m−1σ̂μ̂,μ̂+t1−α/2,m−1σ̂μ̂](6) [\hat{\mu} - t_{1-\alpha/2, m-1}\hat{\sigma}_{\hat{\mu}}, \; \hat{\mu} + t_{1-\alpha/2, m-1}\hat{\sigma}_{\hat{\mu}}] \;\;\;\; (6)

where μ̂\hat{\mu} denotes the estimate of μ\mu, σ̂μ̂\hat{\sigma}_{\hat{\mu}} denotes the estimated asymptotic standard deviation of the estimator of μ\mu, mm denotes the assumed sample size for the confidence interval, and tp,νt_{p,\nu} denotes the pp’th quantile of Student’s t-distribuiton with ν\nu degrees of freedom. One-sided confidence intervals are computed in a similar fashion.

When pivot.statistic="z", the pp’th quantile from the standard normal distribution is used in place of the pp’th quantile from Student’s t-distribution.

Bootstrap and Bias-Corrected Bootstrap Approximation (ci.method="bootstrap")
The bootstrap is a nonparametric method of estimating the distribution (and associated distribution parameters and quantiles) of a sample statistic, regardless of the distribution of the population from which the sample was drawn. The bootstrap was introduced by Efron (1979) and a general reference is Efron and Tibshirani (1993).

In the context of deriving an approximate (1−α)100%(1-\alpha)100\% confidence interval for the population mean μ\mu, the bootstrap can be broken down into the following steps:

  1. Create a bootstrap sample by taking a random sample of size NN from the observations in x_\underline{x}, where sampling is done with replacement. Note that because sampling is done with replacement, the same element of x_\underline{x} can appear more than once in the bootstrap sample. Thus, the bootstrap sample will usually not look exactly like the original sample.
  2. Estimate μ\mu based on the bootstrap sample created in Step 1, using the same method that was used to estimate μ\mu using the original observations in x_\underline{x}. Because the bootstrap sample usually does not match the original sample, the estimate of μ\mu based on the bootstrap sample will usually differ from the original estimate based on x_\underline{x}. For the bootstrap-t method (see below), this step also involves estimating the standard error of the estimate of the mean and computing the statistic T=(μ̂B−μ̂)/σ̂μ̂BT = (\hat{\mu}_B - \hat{\mu}) / \hat{\sigma}_{\hat{\mu}_B} where μ̂\hat{\mu} denotes the estimate of the mean based on the original sample, and μ̂B\hat{\mu}_B and σ̂μ̂B\hat{\sigma}_{\hat{\mu}_B} denote the estimate of the mean and estimate of the standard error of the estimate of the mean based on the bootstrap sample.
  3. Repeat Steps 1 and 2 BB times, where BB is some large number. For the function enpar, the number of bootstraps BB is determined by the argument n.bootstraps (see the arguments in the enpar help page). The default value of n.bootstraps is 1000.
  4. Use the BB estimated values of μ\mu to compute the empirical cumulative distribution function of the estimator of μ\mu or to compute the empirical cumulative distribution function of the statistic TT (see ecdfPlot), and then create a confidence interval for μ\mu based on this estimated cdf.

The two-sided percentile interval (Efron and Tibshirani, 1993, p.170) is computed as:

[Ĝ−1(α2),Ĝ−1(1−α2)](7) [\hat{G}^{-1}(\frac{\alpha}{2}), \; \hat{G}^{-1}(1-\frac{\alpha}{2})] \;\;\;\;\;\; (7)

where Ĝ(t)\hat{G}(t) denotes the empirical cdf of μ̂B\hat{\mu}_B evaluated at tt and thus Ĝ−1(p)\hat{G}^{-1}(p) denotes the pp’th empirical quantile of the distribution of μ̂B\hat{\mu}_B, that is, the pp’th quantile associated with the empirical cdf. Similarly, a one-sided lower confidence interval is computed as:

[Ĝ−1(α),∞](8) [\hat{G}^{-1}(\alpha), \; \infty] \;\;\;\;\;\; (8)

and a one-sided upper confidence interval is computed as:

[−∞,Ĝ−1(1−α)](9) [-\infty, \; \hat{G}^{-1}(1-\alpha)] \;\;\;\;\;\; (9)

The function enpar calls the R function quantile to compute the empirical quantiles used in Equations (7)-(9).

The percentile method bootstrap confidence interval is only first-order accurate (Efron and Tibshirani, 1993, pp.187-188), meaning that the probability that the confidence interval will contain the true value of μ\mu can be off by k/Nk/\sqrt{N}, where kk is some constant. Efron and Tibshirani (1993, pp.184–188) proposed a bias-corrected and accelerated interval that is second-order accurate, meaning that the probability that the confidence interval will contain the true value of μ\mu may be off by k/Nk/N instead of k/Nk/\sqrt{N}. The two-sided bias-corrected and accelerated confidence interval is computed as:

[Ĝ−1(α1),Ĝ−1(α2)](10) [\hat{G}^{-1}(\alpha_1), \; \hat{G}^{-1}(\alpha_2)] \;\;\;\;\;\; (10)

where

α1=Φ[ẑ0+ẑ0+zα/21−â(z0+zα/2)](11) \alpha_1 = \Phi[\hat{z}_0 + \frac{\hat{z}_0 + z_{\alpha/2}}{1 - \hat{a}(z_0 + z_{\alpha/2})}] \;\;\;\;\;\; (11)

α2=Φ[ẑ0+ẑ0+z1−α/21−â(z0+z1−α/2)](12) \alpha_2 = \Phi[\hat{z}_0 + \frac{\hat{z}_0 + z_{1-\alpha/2}}{1 - \hat{a}(z_0 + z_{1-\alpha/2})}] \;\;\;\;\;\; (12)

ẑ0=Φ−1[Ĝ(μ̂)](13) \hat{z}_0 = \Phi^{-1}[\hat{G}(\hat{\mu})] \;\;\;\;\;\; (13)

â=∑i=1N(μ̂(⋅)−μ̂(i))36[∑i=1N(μ̂(⋅)−μ̂(i))2]3/2(14) \hat{a} = \frac{\sum_{i=1}^N (\hat{\mu}_{(\cdot)} - \hat{\mu}_{(i)})^3}{6[\sum_{i=1}^N (\hat{\mu}_{(\cdot)} - \hat{\mu}_{(i)})^2]^{3/2}} \;\;\;\;\;\; (14)

where the quantity μ̂(i)\hat{\mu}_{(i)} denotes the estimate of μ\mu using all the values in x_\underline{x} except the ii’th one, and

μ̂(⋅)=1N∑i=1Nμ(i)̂(15) \hat{\mu}{(\cdot)} = \frac{1}{N} \sum_{i=1}^N \hat{\mu_{(i)}} \;\;\;\;\;\; (15)

A one-sided lower confidence interval is given by:

[Ĝ−1(α1),∞](16) [\hat{G}^{-1}(\alpha_1), \; \infty] \;\;\;\;\;\; (16)

and a one-sided upper confidence interval is given by:

[−∞,Ĝ−1(α2)](17) [-\infty, \; \hat{G}^{-1}(\alpha_2)] \;\;\;\;\;\; (17)

where α1\alpha_1 and α2\alpha_2 are computed as for a two-sided confidence interval, except α/2\alpha/2 is replaced with α\alpha in Equations (11) and (12).

The constant ẑ0\hat{z}_0 incorporates the bias correction, and the constant â\hat{a} is the acceleration constant. The term “acceleration” refers to the rate of change of the standard error of the estimate of μ\mu with respect to the true value of μ\mu (Efron and Tibshirani, 1993, p.186). For a normal (Gaussian) distribution, the standard error of the estimate of μ\mu does not depend on the value of μ\mu, hence the acceleration constant is not really necessary.

For the bootstrap-t method, the two-sided confidence interval (Efron and Tibshirani, 1993, p.160) is computed as:

[μ̂−t1−α/2σ̂μ̂,μ̂−tα/2σ̂μ̂](18) [\hat{\mu} - t_{1-\alpha/2}\hat{\sigma}_{\hat{\mu}}, \; \hat{\mu} - t_{\alpha/2}\hat{\sigma}_{\hat{\mu}}] \;\;\;\;\;\; (18)

where μ̂\hat{\mu} and σ̂μ̂\hat{\sigma}_{\hat{\mu}} denote the estimate of the mean and standard error of the estimate of the mean based on the original sample, and tpt_p denotes the pp’th empirical quantile of the bootstrap distribution of the statistic TT. Similarly, a one-sided lower confidence interval is computed as:

[μ̂−t1−ασ̂μ̂,∞](19) [\hat{\mu} - t_{1-\alpha}\hat{\sigma}_{\hat{\mu}}, \; \infty] \;\;\;\;\;\; (19)

and a one-sided upper confidence interval is computed as:

[−∞,μ̂−tασ̂μ̂](20) [-\infty, \; \hat{\mu} - t_{\alpha}\hat{\sigma}_{\hat{\mu}}] \;\;\;\;\;\; (20)

When ci.method="bootstrap", the function enpar computes the percentile method, bias-corrected and accelerated method, and bootstrap-t bootstrap confidence intervals. The percentile method is transformation respecting, but not second-order accurate. The bootstrap-t method is second-order accurate, but not transformation respecting. The bias-corrected and accelerated method is both transformation respecting and second-order accurate (Efron and Tibshirani, 1993, p.188).

enparCensored

Help topic: enparCensored.

Let x_=(x1,x2,…,xN)\underline{x} = (x_1, x_2, \ldots, x_N) denote a vector of NN observations from some positive-valued distribution with mean μ\mu and standard deviation σ\sigma. Assume nn (0<n<N0 < n < N) of these observations are known and cc (c=N−nc=N-n) of these observations are all censored below (left-censored) or all censored above (right-censored) at kk censoring levels

T1,T2,…,Tk;k≥1(1) T_1, T_2, \ldots, T_k; \; k \ge 1 \;\;\;\;\;\; (1)

Let y1,y2,…,yny_1, y_2, \ldots, y_n denote the nn ordered uncensored observations, and let r1,r2,…,rnr_1, r_2, \ldots, r_n denote the order of these uncensored observations within the context of all the observations (censored and uncensored). For example, if the left-censored data are {<10, 14, 14, <15, 20}, then y1=14,y2=14,y3=20y_1 = 14, y_2 = 14, y_3 = 20, and r1=2,r2=3,r3=5r_1 = 2, r_2 = 3, r_3 = 5.

Let y1′,y2′,…,yp′y_1', y_2', \ldots, y_p' denote the pp ordered distinct uncensored observations, let mjm_j denote the number of detects at yj′y_j' (j=1,2,…,pj = 1, 2, \ldots, p), and let rj′r_j' denote the number of xi≤yj′x_i \le y_j', i.e., the number of observations (censored and uncensored) less than or equal to yj′y_j' (j=1,2,…,pj = 1, 2, \ldots, p). For example, if the left-censored data are {<10, 14, 14, <15, 20}, then y1′=14,y2′=20y_1' = 14, y_2' = 20, m1=2,m2=1m_1 = 2, m_2 = 1, and r1′=3,r2′=5r_1' = 3, r_2' = 5.

Estimation
This section explains how the mean μ\mu, standard deviation σ\sigma, and standard error of the mean σ̂μ̂\hat{\sigma}_{\hat{\mu}} are estimated, as well as the restricted mean.

Estimating the Mean
It can be shown that the mean of a positive-valued distribution is equal to the area under the survival curve (Klein and Moeschberger, 2003, p.33):

$$ \mu = \int_0^\inftydt = \int_0^\infty S(t) dt \;\;\;\;\;\; (2) $$

where F(t)F(t) denotes the cumulative distribution function evaluated at tt and S(t)=1−F(t)S(t) = 1 - F(t) denotes the survival function evaluated at tt. When the Kaplan-Meier estimator is used to construct the survival function, you can use the area under this curve to estimate the mean of the distribution, and the estimator can be as efficient or more efficient than parametric estimators of the mean (Meier, 2004; Helsel, 2012; Lee and Wang, 2003). Let F̂(t)\hat{F}(t) denote the Kaplan-Meier estimator of the empirical cumulative distribution function (ecdf) evaluated at tt, and let Ŝ(t)=1−F̂(t)\hat{S}(t) = 1 - \hat{F}(t) denote the estimated survival function evaluated at tt. (See the help files for ecdfPlotCensored and qqPlotCensored for an explanation of how the Kaplan-Meier estimator of the ecdf is computed.)

The formula for the estimated mean is given by (Lee and Wang, 2003, p. 74):

μ̂=∑i=1nŜ(yi−1)(yi−yi−1)(3) \hat{\mu} = \sum_{i=1}^{n} \hat{S}(y_{i-1}) (y_{i} - y_{i-1}) \;\;\;\;\;\; (3)

where y0=0y_{0} = 0 and Ŝ(y0)=1\hat{S}(y_{0}) = 1 by definition. It can be shown that this formula is eqivalent to:

μ̂=∑i=1nyi[F̂(yi)−F̂(yi−1)](4) \hat{\mu} = \sum_{i=1}^n y_{i} [\hat{F}(y_{i}) - \hat{F}(y_{i-1})] \;\;\;\;\;\; (4)

where F̂(y0)=F̂(0)=0\hat{F}(y_{0}) = \hat{F}(0) = 0 by definition, and this is equivalent to:

μ̂=∑i=1pyi′[F̂(yi′)−F̂(yi−1′)](5) \hat{\mu} = \sum_{i=1}^p y_i' [\hat{F}(y_i') - \hat{F}(y_{i-1}')] \;\;\;\;\;\; (5)

(USEPA, 2009, pp. 15–7 to 15–12; Beal, 2010; USEPA, 2022, pp. 128–129).

Estimating the Standard Deviation
The formula for the estimated standard deviation is:

σ̂={∑i=1n(yi−μ̂)2[F̂(yi)−F̂(yi−1)]}1/2(6) \hat{\sigma} = \{\sum_{i=1}^n (y_{i} - \hat{\mu})^2 [\hat{F}(y_{i}) - \hat{F}(y_{i-1})]\}^{1/2} \;\;\;\;\; (6)

which is equivalent to:

σ̂={∑i=1p(yi′−μ̂)2[F̂(yi′)−F̂(yi−1′)]}1/2(7) \hat{\sigma} = \{\sum_{i=1}^p (y_i' - \hat{\mu})^2 [\hat{F}(y_i') - \hat{F}(y_{i-1}')]\}^{1/2} \;\;\;\;\; (7)

(USEPA, 2009, p. 15-10; Beal, 2010).

Estimating the Standard Error of the Mean
For left-censored data, the formula for the estimated standard error of the mean is:

σ̂μ̂=[∑i=jp−1Aj2mj+1rj+1′(rj+1′−mj+1)]1/2(8) \hat{\sigma}_{\hat{\mu}} = [\sum_{i=j}^{p-1} A_j^2 \frac{m_{j+1}}{r_{j+1}'(r_{j+1}' - m_{j+1})}]^{1/2} \;\;\;\;\;\; (8)

where

Aj=∑i=1j(yi+1′−yi′)F̂(yi′)(9) A_j = \sum_{i=1}^{j} (y_{i+1}' - y_i') \hat{F}(y_i') \;\;\;\;\;\; (9)

(Beal, 2010; USEPA, 2022, pp. 128–129).

For rigth-censored data, the formula for the estimated standard error of the mean is:

σ̂μ̂=[∑r=1n−1Ar2(N−r)(N−r+1)]1/2(10) \hat{\sigma}_{\hat{\mu}} = [\sum_{r=1}^{n-1} \frac{A_r^2}{(N-r)(N-r+1)}]^{1/2} \;\;\;\;\;\; (10)

where

Ar=∑i=rn−1(yi+1−yi)Ŝ(yi)(11) A_r = \sum_{i=r}^{n-1} (y_{i+1} - y_{i}) \hat{S}(y_{i}) \;\;\;\;\;\; (11)

(Lee and Wang, 2003, p. 74).

Kaplan and Meier suggest using a bias correction of n/(n−1)n/(n-1) for the estimated variance of the mean (Lee and Wang, 2003, p.75):

σ̂μ̂,BC=nn−1σ̂μ̂(12) \hat{\sigma}_{\hat{\mu}, BC} = \sqrt{\frac{n}{n-1}} \;\; \hat{\sigma}_{\hat{\mu}} \;\;\;\;\;\; (12)

When correct.se=TRUE (the default), Equation (12) is used. Beal (2010), ProUCL 5.2.0 (USEPA, 2022), and the kmms function in the STAND package (Frome and Frome, 2015) all compute the bias-corrected estimate of the standard error of the mean as well.

Estimating the Restricted Mean
If the smallest value for left-censored data is censored and less than or equal to the smallest uncensored value, then the estimated mean will be biased high, and if the largest value for right-censored data is censored and greater than or equal to the largest uncensored value, then the estimated mean will be biased low. One solution to this problem is to instead estimate what is called the restricted mean (Miller, 1981; Lee and Wang, 2003, p. 74; Meier, 2004; Barker, 2009).

To compute the restricted mean (restricted=TRUE), for left-censored data, the smallest censored observation(s) are treated as observed, and set to the smallest censoring level
(left.censored.min="Censoring Level") or some other value less than the smallest censoring level and greater than 0, and then applying the above formulas. To compute the restricted mean for right-censored data, the largest censored observation(s) are treated as observed and set to the censoring level (right.censored.max="Censoring Level") or some value greater than the largest censoring level.

ProUCL 5.2.0 (USEPA, 2022, pp. 128–129) and Beal (2010) do not compute the restricted mean in cases where it could be applied, whereas USEPA (2009, pp. 15–7 to 15–12) and the kmms function in Version 2.0 of the R package STAND (Frome and Frome, 2015) do compute the restricted mean and set the smallest censored observation(s) equal to the censoring level (i.e., what enparCensored does when restricted=TRUE and left.censored.min="Censoring Level").

To be consistent with ProUCL 5.2.0, by default the function enparCensored does not compute the restricted mean (i.e., restricted=FALSE). Note that there are instances where ProUCL 5.2.0 does not agree with enparCensored, and it is not clear why. It should be noted that when the restricted mean is computed, the number of uncensored observations increases because the smallest (left-censored) or largest (right-censored) censored observation(s) is/are set to a specified value and treated as uncensored. The kmms function in Version 2.0 of the STAND package (Frome and Frome, 2015) is inconsistent in how it treats the number of uncensored observations when computing estimates associated with the restricted mean. Although kmms sets the smallest censored observations to the observed censoring level and treats them as not censored, when it computes the bias correction factor for the standard error of the mean, it assumes those observations are still censored (see the examples in the enparCensored help page).

In the unusual case when a restricted mean will be estimated and setting the smallest censored value(s) to an uncensored value (left-censored data), or setting the largest censored value(s) to an uncensored value (right-censored data), results in no censored values in the data, the Kaplan-Meier estimate of the mean reduces to the sample mean, so the function enpar is called and, if warn=TRUE, a warning is returned.

Confidence Intervals
This section explains how confidence intervals for the mean μ\mu are computed.

Normal Approximation (ci.method="normal.approx")
This method constructs approximate (1−α)100%(1-\alpha)100\% confidence intervals for μ\mu based on the assumption that the estimator of μ\mu is approximately normally distributed. That is, a two-sided (1−α)100%(1-\alpha)100\% confidence interval for μ\mu is constructed as:

[μ̂−t1−α/2,v−1σ̂μ̂,μ̂+t1−α/2,v−1σ̂μ̂](13) [\hat{\mu} - t_{1-\alpha/2, v-1}\hat{\sigma}_{\hat{\mu}}, \; \hat{\mu} + t_{1-\alpha/2, v-1}\hat{\sigma}_{\hat{\mu}}] \;\;\;\; (13)

where μ̂\hat{\mu} denotes the estimate of μ\mu, σ̂μ̂\hat{\sigma}_{\hat{\mu}} denotes the estimated asymptotic standard deviation of the estimator of μ\mu, vv denotes the assumed sample size for the confidence interval, and tp,νt_{p,\nu} denotes the pp’th quantile of Student’s t-distribuiton with ν\nu degrees of freedom. One-sided confidence intervals are computed in a similar fashion.

The argument ci.sample.size determines the value of vv. The possible values are the total number of observations, NN (ci.sample.size="Total"), or the number of uncensored observations, nn (ci.sample.size="Uncensored"). To be consistent with ProUCL 5.2.0, in enparCensored the default value is the total number of observations. The kmms function in the STAND package, on the other hand, uses the number of uncensored observations.

When pivot.statistic="z", the pp’th quantile from the standard normal distribution is used in place of the pp’th quantile from Student’s t-distribution.

Bootstrap and Bias-Corrected Bootstrap Approximation (ci.method="bootstrap")
The bootstrap is a nonparametric method of estimating the distribution (and associated distribution parameters and quantiles) of a sample statistic, regardless of the distribution of the population from which the sample was drawn. The bootstrap was introduced by Efron (1979) and a general reference is Efron and Tibshirani (1993).

In the context of deriving an approximate (1−α)100%(1-\alpha)100\% confidence interval for the population mean μ\mu, the bootstrap can be broken down into the following steps:

  1. Create a bootstrap sample by taking a random sample of size NN from the observations in x_\underline{x}, where sampling is done with replacement. Note that because sampling is done with replacement, the same element of x_\underline{x} can appear more than once in the bootstrap sample. Thus, the bootstrap sample will usually not look exactly like the original sample (e.g., the number of censored observations in the bootstrap sample will often differ from the number of censored observations in the original sample).
  2. Estimate μ\mu based on the bootstrap sample created in Step 1, using the same method that was used to estimate μ\mu using the original observations in x_\underline{x}. Because the bootstrap sample usually does not match the original sample, the estimate of μ\mu based on the bootstrap sample will usually differ from the original estimate based on x_\underline{x}. For the bootstrap-t method (see below), this step also involves estimating the standard error of the estimate of the mean and computing the statistic T=(μ̂B−μ̂)/σ̂μ̂BT = (\hat{\mu}_B - \hat{\mu}) / \hat{\sigma}_{\hat{\mu}_B} where μ̂\hat{\mu} denotes the estimate of the mean based on the original sample, and μ̂B\hat{\mu}_B and σ̂μ̂B\hat{\sigma}_{\hat{\mu}_B} denote the estimate of the mean and estimate of the standard error of the estimate of the mean based on the bootstrap sample.
  3. Repeat Steps 1 and 2 BB times, where BB is some large number. For the function enparCensored, the number of bootstraps BB is determined by the argument n.bootstraps (see the arguments in the enparCensored help page). The default value of n.bootstraps is 1000.
  4. Use the BB estimated values of μ\mu to compute the empirical cumulative distribution function of the estimator of μ\mu or to compute the empirical cumulative distribution function of the statistic TT (see ecdfPlot), and then create a confidence interval for μ\mu based on this estimated cdf.

The two-sided percentile interval (Efron and Tibshirani, 1993, p.170) is computed as:

[Ĝ−1(α2),Ĝ−1(1−α2)](14) [\hat{G}^{-1}(\frac{\alpha}{2}), \; \hat{G}^{-1}(1-\frac{\alpha}{2})] \;\;\;\;\;\; (14)

where Ĝ(t)\hat{G}(t) denotes the empirical cdf of μ̂B\hat{\mu}_B evaluated at tt and thus Ĝ−1(p)\hat{G}^{-1}(p) denotes the pp’th empirical quantile of the distribution of μ̂B\hat{\mu}_B, that is, the pp’th quantile associated with the empirical cdf. Similarly, a one-sided lower confidence interval is computed as:

[Ĝ−1(α),∞](15) [\hat{G}^{-1}(\alpha), \; \infty] \;\;\;\;\;\; (15)

and a one-sided upper confidence interval is computed as:

[−∞,Ĝ−1(1−α)](16) [-\infty, \; \hat{G}^{-1}(1-\alpha)] \;\;\;\;\;\; (16)

The function enparCensored calls the R function quantile to compute the empirical quantiles used in Equations (14)-(16).

The percentile method bootstrap confidence interval is only first-order accurate (Efron and Tibshirani, 1993, pp.187-188), meaning that the probability that the confidence interval will contain the true value of μ\mu can be off by k/Nk/\sqrt{N}, where kk is some constant. Efron and Tibshirani (1993, pp.184–188) proposed a bias-corrected and accelerated interval that is second-order accurate, meaning that the probability that the confidence interval will contain the true value of μ\mu may be off by k/Nk/N instead of k/Nk/\sqrt{N}. The two-sided bias-corrected and accelerated confidence interval is computed as:

[Ĝ−1(α1),Ĝ−1(α2)](17) [\hat{G}^{-1}(\alpha_1), \; \hat{G}^{-1}(\alpha_2)] \;\;\;\;\;\; (17)

where

α1=Φ[ẑ0+ẑ0+zα/21−â(z0+zα/2)](18) \alpha_1 = \Phi[\hat{z}_0 + \frac{\hat{z}_0 + z_{\alpha/2}}{1 - \hat{a}(z_0 + z_{\alpha/2})}] \;\;\;\;\;\; (18)

α2=Φ[ẑ0+ẑ0+z1−α/21−â(z0+z1−α/2)](19) \alpha_2 = \Phi[\hat{z}_0 + \frac{\hat{z}_0 + z_{1-\alpha/2}}{1 - \hat{a}(z_0 + z_{1-\alpha/2})}] \;\;\;\;\;\; (19)

ẑ0=Φ−1[Ĝ(μ̂)](20) \hat{z}_0 = \Phi^{-1}[\hat{G}(\hat{\mu})] \;\;\;\;\;\; (20)

â=∑i=1N(μ̂(⋅)−μ̂(i))36[∑i=1N(μ̂(⋅)−μ̂(i))2]3/2(21) \hat{a} = \frac{\sum_{i=1}^N (\hat{\mu}_{(\cdot)} - \hat{\mu}_{(i)})^3}{6[\sum_{i=1}^N (\hat{\mu}_{(\cdot)} - \hat{\mu}_{(i)})^2]^{3/2}} \;\;\;\;\;\; (21)

where the quantity μ̂(i)\hat{\mu}_{(i)} denotes the estimate of μ\mu using all the values in x_\underline{x} except the ii’th one, and

μ̂(⋅)=1N∑i=1Nμ(i)̂(22) \hat{\mu}{(\cdot)} = \frac{1}{N} \sum_{i=1}^N \hat{\mu_{(i)}} \;\;\;\;\;\; (22)

A one-sided lower confidence interval is given by:

[Ĝ−1(α1),∞](23) [\hat{G}^{-1}(\alpha_1), \; \infty] \;\;\;\;\;\; (23)

and a one-sided upper confidence interval is given by:

[−∞,Ĝ−1(α2)](24) [-\infty, \; \hat{G}^{-1}(\alpha_2)] \;\;\;\;\;\; (24)

where α1\alpha_1 and α2\alpha_2 are computed as for a two-sided confidence interval, except α/2\alpha/2 is replaced with α\alpha in Equations (18) and (19).

The constant ẑ0\hat{z}_0 incorporates the bias correction, and the constant â\hat{a} is the acceleration constant. The term “acceleration” refers to the rate of change of the standard error of the estimate of μ\mu with respect to the true value of μ\mu (Efron and Tibshirani, 1993, p.186). For a normal (Gaussian) distribution, the standard error of the estimate of μ\mu does not depend on the value of μ\mu, hence the acceleration constant is not really necessary.

For the bootstrap-t method, the two-sided confidence interval (Efron and Tibshirani, 1993, p.160) is computed as:

[μ̂−t1−α/2σ̂μ̂,μ̂−tα/2σ̂μ̂](25) [\hat{\mu} - t_{1-\alpha/2}\hat{\sigma}_{\hat{\mu}}, \; \hat{\mu} - t_{\alpha/2}\hat{\sigma}_{\hat{\mu}}] \;\;\;\;\;\; (25)

where μ̂\hat{\mu} and σ̂μ̂\hat{\sigma}_{\hat{\mu}} denote the estimate of the mean and standard error of the estimate of the mean based on the original sample, and tpt_p denotes the pp’th empirical quantile of the bootstrap distribution of the statistic TT. Similarly, a one-sided lower confidence interval is computed as:

[μ̂−t1−ασ̂μ̂,∞](26) [\hat{\mu} - t_{1-\alpha}\hat{\sigma}_{\hat{\mu}}, \; \infty] \;\;\;\;\;\; (26)

and a one-sided upper confidence interval is computed as:

[−∞,μ̂−tασ̂μ̂](27) [-\infty, \; \hat{\mu} - t_{\alpha}\hat{\sigma}_{\hat{\mu}}] \;\;\;\;\;\; (27)

When ci.method="bootstrap", the function enparCensored computes the percentile method, bias-corrected and accelerated method, and bootstrap-t bootstrap confidence intervals. The percentile method is transformation respecting, but not second-order accurate. The bootstrap-t method is second-order accurate, but not transformation respecting. The bias-corrected and accelerated method is both transformation respecting and second-order accurate (Efron and Tibshirani, 1993, p.188).

eqnpar

Help topic: eqnpar.

If x contains any missing (NA), undefined (NaN) or infinite (Inf, -Inf) values, they will be removed prior to performing the estimation.

Estimation
The function eqnpar calls the R function quantile to estimate quantiles.

Confidence Intervals
Let x1,x2,…,xnx_1, x_2, \ldots, x_n denote a sample of nn independent and identically distributed random variables from some arbitrary distribution. Furthermore, let x(i)x_{(i)} denote the ii’th order statistic for these nn random variables. That is,

x(1)≤x(2)≤…≤x(n)(1) x_{(1)} \le x_{(2)} \le \ldots \le x_{(n)} \;\;\;\;\;\; (1)

Finally, let xpx_p denote the pp’th quantile of the distribution, that is:

Pr(X<xp)≤p(2) Pr(X < x_p) \le p \;\;\;\;\;\; (2)

Pr(X≤xp)≥p(3) Pr(X \le x_p) \ge p \;\;\;\;\;\; (3)

It can be shown (e.g., Conover, 1980, pp. 114-116) that for the ii’th order statistic:

Pr[xp<x(i)]=FB(n,p)[i−1];i=1,2,…,n(4) Pr[x_p < x_{(i)}] = F_{B(n,p)}[i-1]; \; i = 1, 2, \ldots, n \;\;\;\;\;\; (4)

for a continuous distribution and

Pr[xp<x(i)]≤FB(n,p)[i−1];i=1,2,…,n(5) Pr[x_p < x_{(i)}] \le F_{B(n,p)}[i-1]; \; i = 1, 2, \ldots, n \;\;\;\;\;\; (5)

Pr[xp≤x(i)]≥FB(n,p)[i−1];i=1,2,…,n(6) Pr[x_p \le x_{(i)}] \ge F_{B(n,p)}[i-1]; \; i = 1, 2, \ldots, n \;\;\;\;\;\; (6)

for a discrete distribution, where FB(n,p)[y]F_{B(n,p)}[y] denotes the cumulative distribution function of a binomial random variable with parameters size=nn and prob=pp evaluated at yy. These facts are used to construct confidence intervals for quantiles (see below).

Two-Sided Confidence Interval (ci.type="two-sided")
A two-sided nonparametric confidence interval for the pp’th quantile is constructed as:

[x(r),x(s)](7) [x_{(r)}, x_{(s)}] \;\;\;\;\;\; (7)

where

1≤r≤(n−1)(8) 1 \le r \le (n-1) \;\;\;\;\;\; (8)

2≤s≤n(9) 2 \le s \le n \;\;\;\;\;\; (9)

r<s(10) r < s \;\;\;\;\;\; (10)

Note that the argument lcl.rank corresponds to rr, and the argument ucl.rank corresponds to ss.

This confidence interval has an associated confidence level that is at least as large as:

FB(n,p)[s−1]−FB(n,p)[r−1](11) F_{B(n,p)}[s-1] - F_{B(n,p)}[r-1] \;\;\;\;\;\; (11)

for a discrete distribution and exactly equal to this value for a continuous distribution. This is because by Equations (4)-(6) above:

Pr[x(r)≤xp≤x(s)] Pr[x_{(r)} \le x_p \le x_{(s)}]

=Pr[xp≤x(s)]−Pr[xp<x(r)] = Pr[x_p \le x_{(s)}] - Pr[x_p < x_{(r)}]

≥FB(n,p)[s−1]−FB(n,p)[r−1](12) \ge F_{B(n,p)}[s-1] - F_{B(n,p)}[r-1] \;\;\;\;\;\; (12)

with equality if the distribution is continuous.

Exact Method (ci.method="exact")
When lcl.rank (rr) and ucl.rank (ss) are not supplied by the user, and ci.method="exact", rr and ss are initially chosen such that rr is the smallest integer satisfying equation (13) below, and ss is the largest integer satisfying equation (14) below:

FB(n,p)[r−1]≥α2(13) F_{B(n,p)}[r-1] \ge \frac{\alpha}{2} \;\;\;\;\;\; (13)

FB(n,p)[s−1]≤1−α2(14) F_{B(n,p)}[s-1] \le 1-\frac{\alpha}{2} \;\;\;\;\;\; (14)

where α=1−\alpha = 1 -approx.conf.level. The values of rr and ss are then each varied by ±2\pm 2 (with the restrictions r≥1r \ge 1, s≤ns \le n, and r<sr < s), and confidence levels computed for each of these combinations. If min.coverage=TRUE, the combination of rr and ss is selected that provides the closest coverage to approx.conf.level, with coverage greater than or equal to approx.conf.level. If min.coverage=FALSE, the combination of rr and ss is selected that provides the closest coverage to approx.conf.level, with coverage less than or equal to approx.conf.level + tol.

For this method, the confidence level associated with the confidence interval is exact if the underlying distribution is continuous.

Approximate Method (ci.method="approx")
Here the term “Approximate” simply refers to the method of initially choosing the ranks for the lower and upper bounds. As for ci.method="exact", the confidence level associated with the confidence interval is exact if the underlying distribution is continuous.

When lcl.rank (rr) and ucl.rank (ss) are not supplied by the user and ci.method="normal.approx", rr and ss are initially chosen such that:

r=np−h(15) r = np - h \;\;\;\;\;\; (15)

s=np+h(16) s = np + h \;\;\;\;\;\; (16)

where

h=tn−1,1−α/2np(1−p)(17) h = t_{n-1, 1-\alpha/2} \sqrt{np(1-p)} \;\;\;\;\;\; (17)

and tν,qt_{\nu,q} denotes the qq’th quantile of Student’s t-distribution with ν\nu degrees of freedom, and α=1−\alpha = 1 -approx.conf.level (Conover, 1980, p. 112). With the restictions that r≥1r \ge 1 and s≤ns \le n, rr is rounded down to the nearest integer r=r*=floor(r)r = r^* = floor(r) and ss is rounded up to the nearest integer s=s*=ceiling(s)s = s^* = ceiling(s). Again, with the restictions that s≤ns \le n, if the confidence level using s=s*+1s = s^* + 1 and r=r*r = r^* is less than or equal to approx.conf.level, then ss is set to s=s*+1s = s^* + 1. Once this has been checked, with the restriction that r≥1r \ge 1, if the confidence level using the current value of ss and r=r*−1r = r^* - 1 is less than or equal to approx.conf.level, then rr is set to r=r*−1r = r^* - 1.

Interpolate Method (ci.method="interpolate")
Let γ\gamma denote the desired confidence level associated with the confidence interval for the pp’th quantile. Based on the work of Hettmansperger and Sheather (1986), Nyblom (1992) showed that if [−∞,x(w+1)][-\infty, x_{(w+1)}] is a one-sided upper confidence interval for the pp’th quantile with associated confidence level γw+1\gamma_{w+1}, and γw+1≥γ≥γw\gamma_{w+1} \ge \gamma \ge \gamma_{w}, then the one-sided upper confidence interval

[−∞,(1−λ)x(w)+λx(w+1)](18) [-\infty, (1-\lambda) x_{(w)} + \lambda x_{(w+1)}] \;\;\;\;\;\; (18)

where

λ=λ(β,p,w,n) \lambda = \lambda(\beta, p, w, n)

=[1+w(1−p)(πw+1−β)(n−w)p(β−πw)]−1(19) = [ 1 + \frac{w(1-p)(\pi_{w+1}-\beta)}{(n-w)p(\beta-\pi_w)} ] ^ {-1} \;\;\;\;\;\; (19)

πw=FB(n,p)[w−1](20) \pi_w = F_{B(n,p)}[w-1] \;\;\;\;\;\; (20)

β=γ(21) \beta = \gamma \;\;\;\;\;\; (21)

has associated confidence level approximately equal to γ\gamma for a wide range of distributions.

Thus, to construct an approximate two-sided confidence interval for the pp’th quantile with confidence level γ\gamma, if [x(r),x(s)][x_{(r)}, x_{(s)}] has confidence level ≥γ\ge \gamma and [x(r+1),x(s−1)][x_{(r+1)}, x_{(s-1)}] has confidence level ≤γ\le \gamma, then the lower bound of the two-sided confidence interval is computed as:

(1−λ)x(r)+λx(r+1)(21) (1-\lambda) x_{(r)} + \lambda x_{(r+1)} \;\;\;\;\;\; (21)

where

β=α/2;α=1−γ(22) \beta = \alpha/2; \;\;\;\; \alpha = 1 - \gamma \;\;\;\;\;\; (22)

and the upper bound of the two-sided confidence interval is computed as:

(1−λ)x(s−1)+λx(s)(23) (1-\lambda) x_{(s-1)} + \lambda x_{(s)} \;\;\;\;\;\; (23)

where

β=1−α/2(24) \beta = 1 - \alpha/2 \;\;\;\;\;\; (24)

The values of rr and ss in Equations (21) and (23) are computed by using ci.method="exact" with the argument min.coverage=TRUE.

One-Sided Lower Confidence Interval (ci.type="lower")
A one-sided lower nonparametric confidence interval for the pp’th quantile is constructed as:

[x(r),ub](25) [x_{(r)}, ub] \;\;\;\;\;\; (25)

where ubub denotes the value of the ub argument (the user-supplied upper bound).

Exact Method (ci.method="exact")
When lcl.rank (rr) is not supplied by the user, and ci.method="exact", rr is initially chosen such that it is the smallest integer satisfying the following equation:

FB(n,p)[r−1]≥α(26) F_{B(n,p)}[r-1] \ge \alpha \;\;\;\;\;\; (26)

where α=1−\alpha = 1 -approx.conf.level. The value of rr is varied by ±2\pm 2 (with the restrictions r≥1r \ge 1 and r≤nr \le n), and confidence levels computed for each of these combinations. If min.coverage=TRUE, the value of rr is selected that provides the closest coverage to approx.conf.level, with coverage greater than or equal to approx.conf.level. If min.coverage=FALSE, the value of rr is selected that provides the closest coverage to approx.conf.level, with coverage less than or equal to approx.conf.level + tol.

For this method, the confidence level associated with the confidence interval is exact if the underlying distribution is continuous.

Approximate Method (ci.method="approx")
When lcl.rank (rr) is not supplied by the user and ci.method="normal.approx", rr is initially chosen such that

r=np−tn−1,1−αnp(1−p)(27) r = np - t_{n-1, 1-\alpha} \sqrt{np(1-p)} \;\;\;\;\;\; (27)

With the restriction that r≥1r \ge 1 and r≤nr \le n, if p is less than 0.5 then rr is rounded up to the nearest integer, otherwise it is rounded down to the nearest integer. Denote this value by r*r^*. With the restriction that r≥1r \ge 1, if the confidence level using r*−1r^* - 1 is less than or equal to approx.conf.level, then rr is set to r=r*−1r = r^* - 1.

Interpolate Method (ci.method="interpolate")
Let γ\gamma denote the desired confidence level associated with the confidence interval for the pp’th quantile. To construct an approximate one-sided lower confidence interval for the pp’th quantile with confidence level γ\gamma, if [x(r),ub][x_{(r)}, ub] has confidence level ≥γ\ge \gamma and [x(r+1),ub][x_{(r+1)}, ub] has confidence level ≤γ\le \gamma, then the lower bound of the confidence interval is computed as:

(1−λ)x(r)+λx(r+1)(28) (1-\lambda) x_{(r)} + \lambda x_{(r+1)} \;\;\;\;\;\; (28)

where

β=α;α=1−γ(29) \beta = \alpha; \;\;\;\; \alpha = 1 - \gamma \;\;\;\;\;\; (29)

The value of rr in Equation (28) is computed by using ci.method="exact" with the arguments ci.type="lower" and min.coverage=TRUE.

One-Sided Upper Confidence Interval (ci.type="upper")
A one-sided upper nonparametric confidence interval for the pp’th quantile is constructed as:

[lb,x(s)](30) [lb, x_{(s)}] \;\;\;\;\;\; (30)

where lblb denotes the value of the lb argument (the user-supplied lower bound).

Exact Method (ci.method="exact")
When ucl.rank (ss) is not supplied by the user, and ci.method="exact", ss is initially chosen such that it is the largest integer satisfying the following equation:

FB(n,p)[s−1]≤1−α(31) F_{B(n,p)}[s-1] \le 1-\alpha \;\;\;\;\;\; (31)

where α=1−\alpha = 1 -approx.conf.level. The value of ss is varied by ±2\pm 2 (with the restrictions s≥1s \ge 1 and s≤ns \le n), and confidence levels computed for each of these combinations. If min.coverage=TRUE, the value of ss is selected that provides the closest coverage to approx.conf.level, with coverage greater than or equal to approx.conf.level. If min.coverage=FALSE, the value of ss is selected that provides the closest coverage to approx.conf.level, with coverage less than or equal to approx.conf.level + tol.

For this method, the confidence level associated with the confidence interval is exact if the underlying distribution is continuous.

Approximate Method (ci.method="approx")
When ucl.rank (ss) is not supplied by the user and ci.method="normal.approx", ss is initially chosen such that

s=np+tn−1,1−αnp(1−p)(31) s = np + t_{n-1, 1-\alpha} \sqrt{np(1-p)} \;\;\;\;\;\; (31)

With the restriction that s≥1s \ge 1 and s≤ns \le n, if p is greater than 0.5 then ss is rounded down to the nearest integer, otherwise it is rounded up to the nearest integer. Denote this value by s*s^*. With the restriction that s≤ns \le n, if the confidence level using s*+1s^* + 1 is less than or equal to approx.conf.level, then ss is set to s=s*+1s = s^* + 1.

For this method, the confidence level associated with the confidence interval is exact if the underlying distribution is continuous.

Interpolate Method (ci.method="interpolate")
Let γ\gamma denote the desired confidence level associated with the confidence interval for the pp’th quantile. To construct an approximate one-sided upper confidence interval for the pp’th quantile with confidence level γ\gamma, if [lb,x(s)][lb, x_{(s)}] has confidence level ≥γ\ge \gamma and [lb,x(s−1)][lb, x_{(s-1)}] has confidence level ≤γ\le \gamma, then the upper bound of the confidence interval is computed as:

(1−λ)x(s−1)+λx(s)(32) (1-\lambda) x_{(s-1)} + \lambda x_{(s)} \;\;\;\;\;\; (32)

where

β=γ(33) \beta = \gamma \;\;\;\;\;\; (33)

The value of ss in Equation (32) is computed by using ci.method="exact" with the arguments ci.type = "upper", and min.coverage=TRUE.

Note on Value of Confidence Level
Because of the discrete nature of order statistics, when ci.method="exact" or
ci.method="normal.approx", the value of the confidence level returned by eqnpar will usually differ from the desired confidence level indicated by the value of the argument approx.conf.level. When
ci.method="interpolate", eqnpar returns for the confidence level the value of the argument approx.conf.level. Nyblom (1992) and Hettmasperger and Sheather (1986) have shown that the Interpolate method produces confidence intervals with confidence levels quite close to the assumed confidence level for a wide range of distributions.

twoSampleLinearRankTest

Help topic: twoSampleLinearRankTest.

The function twoSampleLinearRankTest allows you to compare two samples using a locally most powerful rank test (LMPRT) to determine whether the two samples come from the same distribution. The sections below explain the concepts of location and scale shifts, linear rank tests, and LMPRT’s.

Definitions of Location and Scale Shifts
Let XX denote a random variable representing measurements from group 1 with cumulative distribution function (cdf):

F1(t)=Pr(X≤t)(1) F_1(t) = Pr(X \le t) \;\;\;\;\;\; (1)

and let x1,x2,…,xmx_1, x_2, \ldots, x_m denote mm independent observations from this distribution. Let YY denote a random variable from group 2 with cdf:

F2(t)=Pr(Y≤t)(2) F_2(t) = Pr(Y \le t) \;\;\;\;\;\; (2)

and let y1,y2,…,yny_1, y_2, \ldots, y_n denote nn independent observations from this distribution. Set N=m+nN = m + n.

General Hypotheses to Test Differences Between Two Populations
A very general hypothesis to test whether two distributions are the same is given by:

H0:F1(t)=F2(t),−∞<t<∞(3) H_0: F_1(t) = F_2(t), -\infty < t < \infty \;\;\;\;\;\; (3)

versus the two-sided alternative hypothesis:

Ha:F1(t)≠F2(t)(4) H_a: F_1(t) \ne F_2(t) \;\;\;\;\;\; (4)

with strict inequality for at least one value of tt. The two possible one-sided hypotheses would be:

H0:F1(t)≥F2(t)(5) H_0: F_1(t) \ge F_2(t) \;\;\;\;\;\; (5)

versus the alternative hypothesis:

Ha:F1(t)<F2(t)(6) H_a: F_1(t) < F_2(t) \;\;\;\;\;\; (6)

and

H0:F1(t)≤F2(t)(7) H_0: F_1(t) \le F_2(t) \;\;\;\;\;\; (7)

versus the alternative hypothesis:

Ha:F1(t)>F2(t)(8) H_a: F_1(t) > F_2(t) \;\;\;\;\;\; (8)

A similar set of hypotheses to test whether the two distributions are the same are given by (Conover, 1980, p. 216):

H0:Pr(X<Y)=1/2(9) H_0: Pr(X < Y) = 1/2 \;\;\;\;\;\; (9)

versus the two-sided alternative hypothesis:

Ha:Pr(X<Y)≠1/2(10) H_a: Pr(X < Y) \ne 1/2 \;\;\;\;\;\; (10)

or

H0:Pr(X<Y)≥1/2(11) H_0: Pr(X < Y) \ge 1/2 \;\;\;\;\;\; (11)

versus the alternative hypothesis:

Ha:Pr(X<Y)<1/2(12) H_a: Pr(X < Y) < 1/2 \;\;\;\;\;\; (12)

or

H0:Pr(X<Y)≤1/2(13) H_0: Pr(X < Y) \le 1/2 \;\;\;\;\;\; (13)

versus the alternative hypothesis:

Ha:Pr(X<Y)>1/2(14) H_a: Pr(X < Y) > 1/2 \;\;\;\;\;\; (14)

Note that this second set of hypotheses (9)–(14) is not equivalent to the set of hypotheses (3)–(8). For example, if XX takes on the values 1 and 4 with probability 1/2 for each, and YY only takes on values in the interval (1, 4) with strict inequality at the enpoints (e.g., YY takes on the values 2 and 3 with probability 1/2 for each), then the null hypothesis (9) is true but the null hypothesis (3) is not true. However, the null hypothesis (3) implies the null hypothesis (9), (5) implies (11), and (7) implies (13).

Location Shift
A special case of the alternative hypotheses (4), (6), and (8) above is the location shift alternative:

Ha:F1(t)=F2(t−Δ)(15) H_a: F_1(t) = F_2(t - \Delta) \;\;\;\;\;\; (15)

where Δ\Delta denotes the shift between the two groups. (Note: some references refer to (15) above as a shift in the median, but in fact this kind of shift represents a shift in every single quantile, not just the median.) If Δ\Delta is positive, this means that observations in group 1 tend to be larger than observations in group 2, and if Δ\Delta is negative, observations in group 1 tend to be smaller than observations in group 2.

The alternative hypothesis (15) is called a location shift: the only difference between the two distributions is a difference in location (e.g., the standard deviation is assumed to be the same for both distributions). A location shift is not applicable to distributions that are bounded below or above by some constant, such as a lognormal distribution. For lognormal distributions, the location shift could refer to a shift in location of the distribution of the log-transformed observations.

For a location shift, the null hypotheses (3) can be generalized as:

H0:F1(t)=F2(t−Δ0),−∞<t<∞(16) H_0: F_1(t) = F_2(t - \Delta_0), -\infty < t < \infty \;\;\;\;\;\; (16)

where Δ0\Delta_0 denotes the null shift between the two groups. Almost always, however, the null shift is taken to be 0 and we will assume this for the rest of this section.

Alternatively, the null and alternative hypotheses can be written as

H0:Δ=0(17) H_0: \Delta = 0 \;\;\;\;\;\; (17)

versus the alternative hypothesis

Ha:Δ>0(18) H_a: \Delta > 0 \;\;\;\;\;\; (18)

The other one-sided alternative hypothesis (Δ<0\Delta < 0) and two-sided alternative hypothesis (Δ≠0\Delta \ne 0) could be considered as well.

The general hypotheses (3)-(14) are not location shift hypotheses (e.g., the standard deviation does not have to be the same for both distributions), but they do allow for distributions that are bounded below or above by a constant (e.g., lognormal distributions).

Scale Shift
A special kind of scale shift replaces the alternative hypothesis (15) with the alternative hypothesis:

Ha:F1(t)=F2(t/τ)(19) H_a: F_1(t) = F_2(t/\tau) \;\;\;\;\;\; (19)

where τ\tau denotes the shift in scale between the two groups. Alternatively, the null and alternative hypotheses for this scale shift can be written as

H0:τ=1(20) H_0: \tau = 1 \;\;\;\;\;\; (20)

versus the alternative hypothesis

Ha:τ>1(21) H_a: \tau > 1 \;\;\;\;\;\; (21)

The other one-sided alternative hypothesis (t<1t < 1) and two-sided alternative hypothesis (t≠1t \ne 1) could be considered as well.

This kind of scale shift often involves a shift in both location and scale. For example, suppose the underlying distribution for both groups is exponential, with parameter rate=λ\lambda. Then the mean and standard deviation of the reference group is 1/λ1/\lambda, while the mean and standard deviation of the treatment group is τ/λ\tau/\lambda. In this case, the alternative hypothesis (21) implies the more general alternative hypothesis (8).

Linear Rank Tests
The usual nonparametric test to test the null hypothesis of the same distribution for both groups versus the location-shift alternative (18) is the Wilcoxon Rank Sum test (Gilbert, 1987, pp.247-250; Helsel and Hirsch, 1992, pp.118-123; Hollander and Wolfe, 1999). Note that the Mann-Whitney U test is equivalent to the Wilcoxon Rank Sum test (Hollander and Wolfe, 1999; Conover, 1980, p.215, Zar, 2010). Hereafter, this test will be abbreviated as the MWW test. The MWW test is performed by combining the mmXX observations with the nnYY observations and ranking them from smallest to largest, and then computing the statistic

W=∑i=1mRi(22) W = \sum_{i=1}^m R_i \;\;\;\;\;\; (22)

where R1,R2,…,RmR_1, R_2, \ldots, R_m denote the ranks of the XX observations when the XX and YY observations are combined ranked. The null hypothesis (5), (11), or (17) is rejected in favor of the alternative hypothesis (6), (12) or (18) if the value of WW is too large. For small sample sizes, the exact distribution of WW under the null hypothesis is fairly easy to compute and may be found in tables (e.g., Hollander and Wolfe, 1999; Conover, 1980, pp.448-452). For larger sample sizes, a normal approximation is usually used (Hollander and Wolfe, 1999; Conover, 1980, p.217). For the R function wilcox.test, an exact p-value is computed if the samples contain less than 50 finite values and there are no ties.

It is important to note that the MWW test is actually testing the more general hypotheses (9)-(14) (Conover, 1980, p.216; Divine et al., 2013), even though it is often presented as only applying to location shifts.

The MWW W-statistic in Equation (22) is an example of a linear rank statistic (Hettmansperger, 1984, p.147; Prentice, 1985), which is any statistic that can be written in the form:

L=∑i=1ma(Ri)(23) L = \sum_{i=1}^m a(R_i) \;\;\;\;\;\; (23)

where a()a() denotes a score function. Statistics of this form are also called general scores statistics (Hettmansperger, 1984, p.147). The MWW test uses the identity score function:

a(Ri)=Ri(24) a(R_i) = R_i \;\;\;\;\;\; (24)

Any test based on a linear rank statistic is called a linear rank test. Under the null hypothesis (3), (9), (17), or (20), the distribution of the linear rank statistic LL does not depend on the form of the underlying distribution of the XX and YY observations. Hence, tests based on LL are nonparametric (also called distribution-free). If the null hypothesis is not true, however, the distribution of LL will depend not only on the distributions of the XX and YY observations, but also upon the form the score function a()a().

Locally Most Powerful Linear Rank Tests
The decision of what scores to use may be based on considering the power of the test. A locally most powerful rank test (LMPRT) of the null hypothesis (17) versus the alternative (18) maximizes the slope of the power (as a function of Δ\Delta) in the neighborhood where Δ=0\Delta=0. A LMPRT of the null hypothesis (20) versus the alternative (21) maximizes the slope of the power (as a function of τ\tau) in the neighborhood where τ=1\tau=1. That is, LMPRT’s are the best linear rank test you can use for detecting small shifts in location or scale.

Table 1 below shows the score functions associated with the LMPRT’s for various assumed underlying distributions (Hettmansperger, 1984, Chapter 3; Millard and Deverel, 1988, p.2090). A test based on the identity score function of Equation (24) is equivalent to a test based on the score shown in Table 1 associated with the logistic distribution, thus the MWW test is the LMPRT for detecting a location shift when the underlying observations follow the logistic distribution. When the underlying distribution is normal or lognormal, the LMPRT for a location shift uses the “Normal scores” shown in Table 1. When the underlying distribution is exponential, the LMPRT for detecting a scale shift is based on the “Savage scores” shown in Table 1.

Table 1. Scores of LMPRT’s for Various Distributions

Distribution Score a(Ri)a(R_i) Shift Type Test Name
Logistic [2/(N+1)]Ri−1[2/(N+1)]R_i - 1 Location Wilcoxon Rank Sum
Normal or Φ−1[Ri/(N+1)]\Phi^{-1}[R_i/(N+1)]* Location Van der Waerden or
Lognormal (log-scale)     Normal scores
Double Exponential sign[Ri−(N+1)/2]sign[R_i - (N+1)/2] Location Mood’s Median
Exponential or ∑j=1Ri(N−j+1)−1\sum_{j=1}^{R_i} (N-j+1)^{-1} Scale Savage scores
Extreme Value      

* Denotes an approximation to the true score. The symbol Φ\Phi denotes the cumulative distribution function of the standard normal distribution, and signsign denotes the sign function.

A large sample normal approximation to the distribution of the linear rank statistic LL for arbitrary score functions is given by Hettmansperger (1984, p.148). Under the null hypothesis (17) or (20), the mean and variance of LL are given by:

E(L)=μL=mN∑i=1Nai=ma‾(24) E(L) = \mu_L = \frac{m}{N} \sum_{i=1}^N a_i = m \bar{a} \;\;\;\;\;\; (24)

Var(L)=σL2=mnN(N−1)∑i=1N(ai−a‾)2(25) Var(L) = \sigma_L^2 = \frac{mn}{N(N-1)} \sum_{i=1}^N (a_i - \bar{a})^2 \;\;\;\;\;\; (25)

Hettmansperger (1984, Chapter 3) shows that under the null hypothesis of no difference between the two groups, the statistic

z=L−μLσL(26) z = \frac{L - \mu_L}{\sigma_L} \;\;\;\;\;\; (26)

is approximately distributed as a standard normal random variable for “large” sample sizes. This statistic will tend to be large if the observations in group 1 tend to be larger than the observations in group 2.

twoSampleLinearRankTestCensored

Help topic: twoSampleLinearRankTestCensored.

The function twoSampleLinearRankTestCensored allows you to compare two samples containing censored observations using a linear rank test to determine whether the two samples came from the same distribution. The section on twoSampleLinearRankTest explains linear rank tests for complete data (i.e., no censored observations are present), and here we assume you are familiar with that material. The sections below explain how linear rank tests can be extended to the case of censored data.

Notation
Several authors have proposed extensions of the MWW test to the case of censored data, mainly in the context of survival analysis (e.g., Breslow, 1970; Cox, 1972; Gehan, 1965; Mantel, 1966; Peto and Peto, 1972; Prentice, 1978). Prentice (1978) showed how all of these proposed tests are extensions of a linear rank test to the case of censored observations.

Survival analysis usually deals with right-censored data, whereas environmental data is rarely right-censored but often left-censored (some observations are reported as less than some detection limit). Fortunately, all of the methods developed for right-censored data can be applied to left-censored data as well. (See the sub-section Left-Censored Data below.)

In order to explain Prentice’s (1978) generalization of linear rank tests to censored data, we will use the following notation that closely follows Prentice (1978), Prentice and Marek (1979), and Latta (1981). Let XX denote a random variable representing measurements from group 1 with cumulative distribution function (cdf):

F1(t)=Pr(X≤t)(1) F_1(t) = Pr(X \le t) \;\;\;\;\;\; (1)

and let x1,x2,…,xmx_1, x_2, \ldots, x_m denote mm independent observations from this distribution. Let YY denote a random variable from group 2 with cdf:

F2(t)=Pr(Y≤t)(2) F_2(t) = Pr(Y \le t) \;\;\;\;\;\; (2)

and let y1,y2,…,yny_1, y_2, \ldots, y_n denote nn independent observations from this distribution. Set N=m+nN = m + n, the total number of observations. Assume the data are right-censored so that some observations are only recorded as greater than some censoring level, with possibly several different censoring levels. Let t1,t2,…,tkt_1, t_2, \ldots, t_k denote the kk ordered, unique, uncensored observations for the combined samples (in the context of survival data, tt usually stands for “time of death”). For i=1,2,…,ki = 1, 2, \ldots, k, let d1id_{1i} denote the number of observations from sample 1 (the XX observations) that are equal to tit_i, and let d2id_{2i} denote the observations from sample 2 (the YY observations) equal to this value. Set

di=d1i+d2i(3) d_i = d_{1i} + d_{2i} \;\;\;\;\;\; (3)

the total number of observations equal to tit_i. If there are no tied uncensored observations, then ti=1t_i = 1 for i=1,2,…,ki = 1, 2, \ldots, k, otherwise it is greater than 1 for at least on value of ii.

For i=1,2,…,ki = 1, 2, \ldots, k, let e1ie_{1i} denote the number of censored observations from sample 1 (the XX observations) with censoring levels that fall into the interval [ti,ti+1)[t_i, t_{i+1}) where tk+1=∞t_{k+1} = \infty by definition, and let e2ie_{2i} denote the number of censored observations from sample 2 (the YY observations) with censoring levels that fall into this interval. Set

ei=e1i+e2i(4) e_i = e_{1i} + e_{2i} \;\;\;\;\;\; (4)

the total number of censoring levels that fall into this interval.

Finally, set n1in_{1i} equal to the number of observations from sample 1 (uncensored and censored) known to be greater than or equal to tit_i, i.e., that lie in the interval [ti,∞)[t_i, \infty), set n2in_{2i} equal to the number of observations from sample 2 (uncensored and censored) that lie in this interval, and set

ni=n1i+n2i(5) n_i = n_{1i} + n_{2i} \;\;\;\;\;\; (5)

In survival analysis jargon, n1in_{1i} denotes the number of people from sample 1 who are “at risk” at time tit_i, that is, these people are known to still be alive at this time. Similarly, n2in_{2i} denotes the number of people from sample 2 who are at risk at time tit_i, and nin_i denotes the total number of people at risk at time tit_i.

Score Statistics for Multiply Censored Data
Prentice’s (1978) generalization of the two-sample score (linear rank) statistic is given by:

ν=∑i=1k(d1ici+e1iCi)(6) \nu = \sum_{i=1}^k (d_{1i} c_i + e_{1i} C_i) \;\;\;\;\;\; (6)

where cic_i and CiC_i denote the scores associated with the uncensored and censored observations, respectively. As for complete data, the form of the scores depends upon the assumed underlying distribution. Table 1 below shows scores for various assumed distributions as presented in Prentice (1978) and Latta (1981) (also see Table 5 of Millard and Deverel, 1988, p.2091). The last column shows what these tests reduce to in the case of complete data (no censored observations).

Table 1. Scores Associated with Various Censored Data Rank Tests

  Uncensored Censored   Uncensored
Distribution Score (cic_i) Score (CiC_i) Test Name Analogue
Logistic 2F̂i−12\hat{F}_i - 1 F̂i\hat{F}_i Peto-Peto Wilcoxon Rank Sum
“ i−nii - n_i ii Gehan or Breslow “
“ i−nii - \sqrt{n_i} ii Tarone-Ware “
Normal, Φ−1(F̂i)\Phi^{-1}(\hat{F}_i) ϕ(ci)/Ŝi\phi(c_i)/\hat{S}_i Normal Scores 1 Normal Scores
Lognormal        
“ “ niCi−1−cini−1\frac{n_i C_{i-1} - c_i}{n_i-1} Normal Scores 2 “
Double sign(F̂i−0.5)sign(\hat{F}_i - 0.5) F̂i1−F̂i,ifFî<0.5\frac{\hat{F}_i}{1-\hat{F}_i}, if \hat{F_i} < 0.5 Generalized Mood’s Median
Exponential   1,ifF̂i≥0.51, if \hat{F}_i \ge 0.5 Sign  
Exponential, −log(S̃i)−1-log(\tilde{S}_i) - 1 −log(S̃i)-log(\tilde{S}_i) Logrank Savage Scores
Extreme Value        

In Table 1 above, Φ\Phi denotes the cumulative distribution function of the standard normal distribution, ϕ\phi denotes the probability density function of the standard normal distribution, and signsign denotes the sign function. Also, the quantities F̂i\hat{F}_i and Ŝi\hat{S}_i denote the estimates of the cumulative distribution function (cdf) and survival function, respectively, at time tit_i for the combined sample. The estimated cdf is related to the estimated survival function by:

F̂i=1−Ŝi(7) \hat{F}_i = 1 - \hat{S}_i \;\;\;\;\;\; (7)

The quantity S̃i\tilde{S}_i denotes the Altshuler (1970) estimate of the survival function at time tit_i for the combined sample (see below).

The argument surv.est determines what method to use estimate the survival function. When surv.est="prentice" (the default), the survival function is estimated as:

Ŝi,P=∏j=1inj−dj+1nj+1(8) \hat{S}_{i,P} = \prod_{j=1}^{i} \frac{n_j - d_j + 1}{n_j + 1} \;\;\;\;\;\; (8)

(Prentice, 1978). When surv.est="kaplan-meier", the survival function is estimated as:

Ŝi,KM=∏j=1inj−djnj(9) \hat{S}_{i,KM} = \prod_{j=1}^{i} \frac{n_j - d_j}{n_j} \;\;\;\;\;\; (9)

(Kaplan and Meier, 1958), and when surv.est="peto-peto", the survival function is estimated as:

Ŝi,PP=12(Ŝi,KM+Ŝi−1,KM)(10) \hat{S}_{i,PP} = \frac{1}{2} (\hat{S}_{i,KM} + \hat{S}_{i-1, KM}) \;\;\;\;\;\; (10)

where Ŝ0,KM=0\hat{S}_{0,KM} = 0 (Peto and Peto, 1972). All three of these estimators of the survival function should produce very similar results. When surv.est="altshuler", the survival function is estimated as:

S̃i=exp(−∑j=1idjnj)(11) \tilde{S}_i = exp(-\sum_{j=1}^i \frac{d_j}{n_j}) \;\;\;\;\;\; (11)

(Altshuler, 1970). The scores for the logrank test use this estimator of survival.

Lee and Wang (2003, p. 116) present a slightly different version of the Peto-Peto test. They use the Peto-Peto estimate of the survival function for cic_i, but use the Kaplan-Meier estimate of the survival function for CiC_i.

The scores for the “Normal Scores 1” test shown in Table 1 above are based on the approximation (30) of Prentice (1978). The scores for the “Normal Scores 2” test are based on equation (7) of Prentice and Marek (1979). For the “Normal Scores 2” test, the following rules are used to construct the scores for the censored observations: C0=0C_0 = 0, and Ck=0C_k = 0 if nk=1n_k = 1.

The Distribution of the Score Statistic
Under the null hypothesis that the two distributions are the same, the expected value of the score statistic ν\nu in Equation (6) is 0. The variance of ν\nu can be computed in at least three different ways. If the censoring mechanism is the same for both groups, the permutation variance is appropriate (variance="permutation") and its estimate is given by:

σ̂ν2=mnN(N−1)∑i=1k(dici2+eiCi2)(12) \hat{\sigma}_{\nu}^2 = \frac{mn}{N(N-1)} \sum_{i=1}^k (d_i c_i^2 + e_i C_i^2) \;\;\;\;\;\; (12)

Often, however, it is not clear whether this assumption is valid, and both Prentice (1978) and Prentice and Marek (1979) caution against using the permuation variance (Prentice and Marek, 1979, state it can lead to inflated estimates of variance).

If the censoring mechanisms for the two groups are not necessarily the same, a more general estimator of the variance is based on a conditional permutation approach. In this case, the statistic ν\nu in Equation (6) is re-written as:

ν=∑i=1kwi[d1i−din1ini](13) \nu = \sum_{i=1}^k w_i [d_{1i} - d_i \frac{n_{1i}}{n_i}] \;\;\;\;\;\; (13)

where

wi=ci−Ci(14) w_i = c_i - C_i \;\;\;\;\;\; (14)

cic_i and CiC_i are given above in Table 1, and the conditional permutation or hypergeometric estimate (variance="hypergeometric") is given by:

σ̂ν2=∑i=1kdiwi2(n1ini)(1−n1ini)(ni−dini−1)(15) \hat{\sigma}_{\nu}^2 = \sum_{i=1}^k d_i w_i^2 (\frac{n_{1i}}{n_i}) (1 - \frac{n_{1i}}{n_i}) (\frac{n_i - d_i}{n_i - 1}) \;\;\;\;\;\; (15)

(Prentice and Marek, 1979; Latta, 1981; Millard and Deverel, 1988). Note that Equation (13) can be thought of as the sum of weighed values of observed minus expected observations.

Prentice (1978) derived an asymptotic estimator of the variance of the score statistic ν\nu given in Equation (6) above based on the log likelihood of the rank vector (variance="asymptotic"). This estimator is the same as the hypergeometric variance estimator for the logrank and Gehan tests (assuming no tied uncensored observations), but for the Peto-Peto test, this estimator is given by:

σ̂ν2=∑i=1k{Ŝi(1−ai)bi−(ai−Ŝi)bi[Ŝibi+2∑j=i+1kŜjbj]}(16) \hat{\sigma}_{\nu}^2 = \sum_{i=1}^k \{ \hat{S}_i (1 - a_i) b_i - (a_i - \hat{S}_i) b_i [\hat{S}_i b_i + 2 \sum_{j=i+1}^k \hat{S}_j b_j ]\} \;\;\;\;\;\; (16)

where

ai=∏j=1inj+1nj+2(17) a_i = \prod_{j=1}^i \frac{n_j + 1}{n_j + 2} \;\;\;\;\;\; (17)

bi=2d1i+e1i(18) b_i = 2 d_{1i} + e_{1i} \;\;\;\;\;\; (18)

(Prentice, 1978; Latta, 1981; Millard and Deverel, 1988). Note that equation (14) of Millard and Deverel (1988) contains a typographical error.

The Treatment of Ties
If the hypergeometric estimator of variance is being used, no modifications need to be made for ties; Equations (13)-(15) already account for ties. For the case of the permutation or asymptotic variance estimators, Equations (6), (12), and (16) all assume no ties in the uncensored observations. If ties exist in the uncensored observations, Prentice (1978) suggests computing the scores shown in Table 1 above as if there were no ties, and then assigning average scores to the tied observations. (This modification also applies to the quantities aia_i and Ŝi\hat{S}_i in Equation (16) above.) For this algorithm, the statistic in Equation (6) is not in general the same as the one in Equation (13).

Computing a Test Statistic
Under the null hypothesis that the two distributions are the same, the statistic

z=νσ̂ν(19) z = \frac{\nu}{\hat{\sigma}_{\nu}} \;\;\;\;\;\; (19)

is approximately distributed as a standard normal random variable for “large” sample sizes. This statistic will tend to be large if the observations in group 1 (the XX observations) tend to be larger than the observations in group 2 (the YY observations).

Left-Censored Data
Most of the time, if censored observations occur in environmental data, they are left-censored (e.g., observations are reported as less than one or more detection limits). For the two-sample test of differences between groups, the methods that apply to right-censored data are easily adapted to left-censored data: simply multiply the observations by -1, compute the z-statistic shown in Equation (20), then reverse the sign of this statistic before computing the p-value.

twoSamplePermutationTestLocation

Help topic: twoSamplePermutationTestLocation.

Randomization Tests
In 1935, R.A. Fisher introduced the idea of a randomization test (Manly, 2007, p. 107; Efron and Tibshirani, 1993, Chapter 15), which is based on trying to answer the question: “Did the observed pattern happen by chance, or does the pattern indicate the null hypothesis is not true?” A randomization test works by simply enumerating all of the possible outcomes under the null hypothesis, then seeing where the observed outcome fits in. A randomization test is also called a permutation test, because it involves permuting the observations during the enumeration procedure (Manly, 2007, p. 3).

In the past, randomization tests have not been used as extensively as they are now because of the “large” computing resources needed to enumerate all of the possible outcomes, especially for large sample sizes. The advent of more powerful personal computers and software has allowed randomization tests to become much easier to perform. Depending on the sample size, however, it may still be too time consuming to enumerate all possible outcomes. In this case, the randomization test can still be performed by sampling from the randomization distribution, and comparing the observed outcome to this sampled permutation distribution.

Two-Sample Randomization Test for Location (paired=FALSE)
Let x_=x1,x2,…,xn1\underline{x} = x_1, x_2, \ldots, x_{n1} be a vector of n1n1 independent and identically distributed (i.i.d.) observations from some distribution with location parameter (e.g., mean or median) θ1\theta_1, and let y_=y1,y2,…,yn2\underline{y} = y_1, y_2, \ldots, y_{n2} be a vector of n2n2 i.i.d. observations from the same distribution with possibly different location parameter θ2\theta_2.

Consider the test of the null hypothesis that the difference in the location parameters is equal to some specified value:

H0:δ=δ0(1) H_0: \delta = \delta_0 \;\;\;\;\;\; (1)

where

δ=θ1−θ2(2) \delta = \theta_1 - \theta_2 \;\;\;\;\;\; (2)

and δ0\delta_0 denotes the hypothesized difference in the meansures of location (usually δ0=0\delta_0 = 0).

The three possible alternative hypotheses are the upper one-sided alternative (alternative="greater")

Ha:δ>δ0(3) H_a: \delta > \delta_0 \;\;\;\;\;\; (3)

the lower one-sided alternative (alternative="less")

Ha:δ<δ0(4) H_a: \delta < \delta_0 \;\;\;\;\;\; (4)

and the two-sided alternative

Ha:δ≠δ0(5) H_a: \delta \ne \delta_0 \;\;\;\;\;\; (5)

To perform the test of the null hypothesis (1) versus any of the three alternatives (3)-(5), you can use the two-sample permutation test. The two sample permutation test is based on trying to answer the question, “Did the observed difference in means or medians happen by chance, or does the observed difference indicate that the null hypothesis is not true?” Under the null hypothesis, the underlying distributions for each group are the same, therefore it should make no difference which group an observation gets assigned to. The two-sample permutation test works by simply enumerating all possible permutations of group assignments, and for each permutation computing the difference between the measures of location for each group (Manly, 2007, p. 113; Efron and Tibshirani, 1993, p. 202). The measure of location for a group could be the mean, median, or any other measure you want to use. For example, if the observations from Group 1 are 3 and 5, and the observations from Group 2 are 4, 6, and 7, then there are 10 different ways of splitting these five observations into one group of size 2 and another group of size 3. The table below lists all of the possible group assignments, along with the differences in the group means.

Group 1 Group 2 Mean 1 - Mean 2
3, 4 5, 6, 7 -2.5
3, 5 4, 6, 7 -1.67
3, 6 4, 5, 7 -0.83
3, 7 4, 5, 6 0
4, 5 3, 6, 7 -0.83
4, 6 3, 5, 7 0
4, 7 3, 5, 6 0.83
5, 6 3, 4, 7 0.83
5, 7 3, 4, 6 1.67
6, 7 3, 4, 5 2.5

In this example, the observed group assignments and difference in means are shown in the second row of the table.

For a one-sided upper alternative (Equation (3)), the p-value is computed as the proportion of times that the differences of the means (or medians) in the permutation distribution are greater than or equal to the observed difference in means (or medians). For a one-sided lower alternative hypothesis (Equation (4)), the p-value is computed as the proportion of times that the differences in the means (or medians) in the permutation distribution are less than or equal to the observed difference in the means (or medians). For a two-sided alternative hypothesis (Equation (5)), the p-value is computed as the proportion of times the absolute values of the differences in the means (or medians) in the permutation distribution are greater than or equal to the absolute value of the observed difference in the means (or medians).

For this simple example, the one-sided upper, one-sided lower, and two-sided p-values are 0.9, 0.2 and 0.4, respectively.

Note: Because of the nature of machine arithmetic and how the permutation distribution is computed, a one-sided upper p-value is computed as the proportion of times that the differences of the means (or medians) in the permutation distribution are greater than or equal to theobserveddifferenceinmeans(ormedians)−asmalltolerancevaluethe observed difference in means (or medians) - a small tolerance value, where the tolerance value is determined by the argument tol. Similarly, a one-sided lower p-value is computed as the proportion of times that the differences in the means (or medians) in the permutation distribution are less than or equal to theobserveddifferenceinthemeans(ormedians)+asmalltolerancevaluethe observed difference in the means (or medians) + a small tolerance value. Finally, a two-sided p-value is computed as the proportion of times the absolute values of the differences in the means (or medians) in the permutation distribution are greater than or equal to theabsolutevalueoftheobserveddifferenceinthemeans(ormedians)−asmalltolerancevaluethe absolute value of the observed difference in the means (or medians) - a small tolerance value.

In this simple example, we assumed the hypothesized differences in the means under the null hypothesis was δ0=0\delta_0 = 0. If we had hypothesized a different value for δ0\delta_0, then we would have had to subtract this value from each of the observations in Group 1 before permuting the group assignments to compute the permutation distribution of the differences of the means. As in the case of the one-sample permutation test, if the sample sizes for the groups become too large to compute all possible permutations of the group assignments, the permutation test can still be performed by sampling from the permutation distribution and comparing the observed difference in locations to the sampled permutation distribution of the difference in locations.

Unlike the two-sample Student’s t-test, we do not have to worry about the normality assumption when we use a permutation test. The permutation test still assumes, however, that under the null hypothesis, the distributions of the observations from each group are exactly the same, and under the alternative hypothesis there is simply a shift in location (that is, the whole distribution of group 1 is shifted by some constant relative to the distribution of group 2). Mathematically, this can be written as follows:

F1(t)=F2(t−δ),−∞<t<∞(6) F_1(t) = F_2(t - \delta), \;\; -\infty < t < \infty \;\;\;\;\; (6)

where F1F_1 and F2F_2 denote the cumulative distribution functions for group 1 and group 2, respectively. If δ>0\delta > 0, this implies that the observations in group 1 tend to be larger than the observations in group 2, and if δ<0\delta < 0, this implies that the observations in group 1 tend to be smaller than the observations in group 2. Thus, the shape and spread (variance) of the two distributions should be the same whether the null hypothesis is true or not. Therefore, the Type I error rate for a permutation test can be affected by differences in variances between the two groups.

Confidence Intervals for the Difference in Means or Medians
Based on the relationship between hypothesis tests and confidence intervals, it is possible to construct a two-sided or one-sided (1−α)100%(1-\alpha)100\% confidence interval for the difference in means or medians based on the two-sample permutation test by finding the values of δ0\delta_0 that correspond to obtaining a p-value of α\alpha (Manly, 2007, pp. 18–20, 114). A confidence interval based on the bootstrap however, will yield a similar type of confidence interval (Efron and Tibshirani, 1993, p. 214); see the help file for boot in the R package boot.

Paired-Sample Randomization Test for Location (paired=TRUE)
When the argument paired=TRUE, the arguments x and y are assumed to have the same length, and the n1=n2=nn1 = n2 = n differences yi=xi−yiy_i = x_i - y_i, i=1,2,…,ni = 1, 2, \ldots, n are assumed to be independent observations from some symmetric distribution with mean μ\mu. The one-sample permutation test can then be applied to the differences.