vignettes/nonparametric-methods.Rmd
nonparametric-methods.RmdThis 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:
Help topic: enpar.
Let denote a vector of observations from some distribution with mean and standard deviation .
Estimation
Unbiased and consistent estimators of the mean and variance are:
A consistent (but not unbiased) estimate of the standard deviation is given by the square root of the estimated variance above:
It can be shown that the variance of the sample mean is given by:
so the standard deviation of the sample mean (usually called the standard error) can be estimated by:
Confidence Intervals
This section explains how confidence intervals for the mean
are computed.
Normal Approximation
(ci.method="normal.approx")
This method constructs approximate
confidence intervals for
based on the assumption that the estimator of
,
i.e., the sample mean, is approximately normally distributed. That is, a
two-sided
confidence interval for
is constructed as:
where denotes the estimate of , denotes the estimated asymptotic standard deviation of the estimator of , denotes the assumed sample size for the confidence interval, and denotes the ’th quantile of Student’s t-distribuiton with degrees of freedom. One-sided confidence intervals are computed in a similar fashion.
When pivot.statistic="z", the
’th
quantile from the standard
normal distribution is used in place of the
’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 confidence interval for the population mean , the bootstrap can be broken down into the following steps:
enpar, the number of
bootstraps
is determined by the argument n.bootstraps (see the
arguments in the enpar
help page). The default value of n.bootstraps is
1000.ecdfPlot),
and then create a confidence interval for
based on this estimated cdf.The two-sided percentile interval (Efron and Tibshirani, 1993, p.170) is computed as:
where denotes the empirical cdf of evaluated at and thus denotes the ’th empirical quantile of the distribution of , that is, the ’th quantile associated with the empirical cdf. Similarly, a one-sided lower confidence interval is computed as:
and a one-sided upper confidence interval is computed as:
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 can be off by , where 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 may be off by instead of . The two-sided bias-corrected and accelerated confidence interval is computed as:
where
where the quantity denotes the estimate of using all the values in except the ’th one, and
A one-sided lower confidence interval is given by:
and a one-sided upper confidence interval is given by:
where and are computed as for a two-sided confidence interval, except is replaced with in Equations (11) and (12).
The constant incorporates the bias correction, and the constant is the acceleration constant. The term “acceleration” refers to the rate of change of the standard error of the estimate of with respect to the true value of (Efron and Tibshirani, 1993, p.186). For a normal (Gaussian) distribution, the standard error of the estimate of does not depend on the value of , 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:
where and denote the estimate of the mean and standard error of the estimate of the mean based on the original sample, and denotes the ’th empirical quantile of the bootstrap distribution of the statistic . Similarly, a one-sided lower confidence interval is computed as:
and a one-sided upper confidence interval is computed as:
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).
Help topic: enparCensored.
Let denote a vector of observations from some positive-valued distribution with mean and standard deviation . Assume () of these observations are known and () of these observations are all censored below (left-censored) or all censored above (right-censored) at censoring levels
Let denote the ordered uncensored observations, and let 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 , and .
Let denote the ordered distinct uncensored observations, let denote the number of detects at (), and let denote the number of , i.e., the number of observations (censored and uncensored) less than or equal to (). For example, if the left-censored data are {<10, 14, 14, <15, 20}, then , , and .
Estimation
This section explains how the mean
,
standard deviation
,
and standard error of the mean
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
denotes the cumulative distribution function evaluated at
and
denotes the survival function evaluated at
.
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
denote the Kaplan-Meier estimator of the empirical cumulative
distribution function (ecdf) evaluated at
,
and let
denote the estimated survival function evaluated at
.
(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):
where and by definition. It can be shown that this formula is eqivalent to:
where by definition, and this is equivalent to:
(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:
which is equivalent to:
(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:
where
(Beal, 2010; USEPA, 2022, pp. 128–129).
For rigth-censored data, the formula for the estimated standard error of the mean is:
where
(Lee and Wang, 2003, p. 74).
Kaplan and Meier suggest using a bias correction of for the estimated variance of the mean (Lee and Wang, 2003, p.75):
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
are computed.
Normal Approximation
(ci.method="normal.approx")
This method constructs approximate
confidence intervals for
based on the assumption that the estimator of
is approximately normally distributed. That is, a two-sided
confidence interval for
is constructed as:
where denotes the estimate of , denotes the estimated asymptotic standard deviation of the estimator of , denotes the assumed sample size for the confidence interval, and denotes the ’th quantile of Student’s t-distribuiton with degrees of freedom. One-sided confidence intervals are computed in a similar fashion.
The argument ci.sample.size determines the value of
.
The possible values are the total number of observations,
(ci.sample.size="Total"), or the number of uncensored
observations,
(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
’th
quantile from the standard
normal distribution is used in place of the
’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 confidence interval for the population mean , the bootstrap can be broken down into the following steps:
enparCensored, the
number of bootstraps
is determined by the argument n.bootstraps (see the
arguments in the enparCensored
help page). The default value of n.bootstraps is
1000.ecdfPlot),
and then create a confidence interval for
based on this estimated cdf.The two-sided percentile interval (Efron and Tibshirani, 1993, p.170) is computed as:
where denotes the empirical cdf of evaluated at and thus denotes the ’th empirical quantile of the distribution of , that is, the ’th quantile associated with the empirical cdf. Similarly, a one-sided lower confidence interval is computed as:
and a one-sided upper confidence interval is computed as:
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 can be off by , where 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 may be off by instead of . The two-sided bias-corrected and accelerated confidence interval is computed as:
where
where the quantity denotes the estimate of using all the values in except the ’th one, and
A one-sided lower confidence interval is given by:
and a one-sided upper confidence interval is given by:
where and are computed as for a two-sided confidence interval, except is replaced with in Equations (18) and (19).
The constant incorporates the bias correction, and the constant is the acceleration constant. The term “acceleration” refers to the rate of change of the standard error of the estimate of with respect to the true value of (Efron and Tibshirani, 1993, p.186). For a normal (Gaussian) distribution, the standard error of the estimate of does not depend on the value of , 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:
where and denote the estimate of the mean and standard error of the estimate of the mean based on the original sample, and denotes the ’th empirical quantile of the bootstrap distribution of the statistic . Similarly, a one-sided lower confidence interval is computed as:
and a one-sided upper confidence interval is computed as:
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).
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
denote a sample of
independent and identically distributed random variables from some
arbitrary distribution. Furthermore, let
denote the
’th
order statistic for these
random variables. That is,
Finally, let denote the ’th quantile of the distribution, that is:
It can be shown (e.g., Conover, 1980, pp. 114-116) that for the ’th order statistic:
for a continuous distribution and
for a discrete distribution, where
denotes the cumulative distribution function of a binomial
random variable with parameters
size=
and
prob=
evaluated at
.
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
’th
quantile is constructed as:
where
Note that the argument lcl.rank corresponds to
,
and the argument ucl.rank corresponds to
.
This confidence interval has an associated confidence level that is at least as large as:
for a discrete distribution and exactly equal to this value for a continuous distribution. This is because by Equations (4)-(6) above:
with equality if the distribution is continuous.
Exact Method (ci.method="exact")
When lcl.rank
()
and ucl.rank
()
are not supplied by the user, and ci.method="exact",
and
are initially chosen such that
is the smallest integer satisfying equation (13) below, and
is the largest integer satisfying equation (14) below:
where
approx.conf.level.
The values of
and
are then each varied by
(with the restrictions
,
,
and
),
and confidence levels computed for each of these combinations. If
min.coverage=TRUE, the combination of
and
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
and
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
()
and ucl.rank
()
are not supplied by the user and ci.method="normal.approx",
and
are initially chosen such that:
where
and
denotes the
’th
quantile of Student’s
t-distribution with
degrees of freedom, and
approx.conf.level
(Conover, 1980, p. 112). With the restictions that
and
,
is rounded down to the nearest integer
and
is rounded up to the nearest integer
.
Again, with the restictions that
,
if the confidence level using
and
is less than or equal to approx.conf.level, then
is set to
.
Once this has been checked, with the restriction that
,
if the confidence level using the current value of
and
is less than or equal to approx.conf.level, then
is set to
.
Interpolate Method
(ci.method="interpolate")
Let
denote the desired confidence level associated with the confidence
interval for the
’th
quantile. Based on the work of Hettmansperger and Sheather (1986),
Nyblom (1992) showed that if
is a one-sided upper confidence interval for the
’th
quantile with associated confidence level
,
and
,
then the one-sided upper confidence interval
where
has associated confidence level approximately equal to for a wide range of distributions.
Thus, to construct an approximate two-sided confidence interval for the ’th quantile with confidence level , if has confidence level and has confidence level , then the lower bound of the two-sided confidence interval is computed as:
where
and the upper bound of the two-sided confidence interval is computed as:
where
The values of
and
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
’th
quantile is constructed as:
where
denotes the value of the ub argument (the user-supplied
upper bound).
Exact Method (ci.method="exact")
When lcl.rank
()
is not supplied by the user, and ci.method="exact",
is initially chosen such that it is the smallest integer satisfying the
following equation:
where
approx.conf.level.
The value of
is varied by
(with the restrictions
and
),
and confidence levels computed for each of these combinations. If
min.coverage=TRUE, the value of
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
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
()
is not supplied by the user and ci.method="normal.approx",
is initially chosen such that
With the restriction that
and
,
if p is less than 0.5 then
is rounded up to the nearest integer, otherwise it is rounded down to
the nearest integer. Denote this value by
.
With the restriction that
,
if the confidence level using
is less than or equal to approx.conf.level, then
is set to
.
Interpolate Method
(ci.method="interpolate")
Let
denote the desired confidence level associated with the confidence
interval for the
’th
quantile. To construct an approximate one-sided lower confidence
interval for the
’th
quantile with confidence level
,
if
has confidence level
and
has confidence level
,
then the lower bound of the confidence interval is computed as:
where
The value of
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
’th
quantile is constructed as:
where
denotes the value of the lb argument (the user-supplied
lower bound).
Exact Method (ci.method="exact")
When ucl.rank
()
is not supplied by the user, and ci.method="exact",
is initially chosen such that it is the largest integer satisfying the
following equation:
where
approx.conf.level.
The value of
is varied by
(with the restrictions
and
),
and confidence levels computed for each of these combinations. If
min.coverage=TRUE, the value of
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
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
()
is not supplied by the user and ci.method="normal.approx",
is initially chosen such that
With the restriction that
and
,
if p is greater than 0.5 then
is rounded down to the nearest integer, otherwise it is rounded up to
the nearest integer. Denote this value by
.
With the restriction that
,
if the confidence level using
is less than or equal to approx.conf.level, then
is set to
.
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
denote the desired confidence level associated with the confidence
interval for the
’th
quantile. To construct an approximate one-sided upper confidence
interval for the
’th
quantile with confidence level
,
if
has confidence level
and
has confidence level
,
then the upper bound of the confidence interval is computed as:
where
The value of
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" orci.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. Whenci.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.
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
denote a random variable representing measurements from group 1 with
cumulative distribution function (cdf):
and let denote independent observations from this distribution. Let denote a random variable from group 2 with cdf:
and let denote independent observations from this distribution. Set .
General Hypotheses to Test Differences Between Two
Populations
A very general hypothesis to test whether two distributions are the same
is given by:
versus the two-sided alternative hypothesis:
with strict inequality for at least one value of . The two possible one-sided hypotheses would be:
versus the alternative hypothesis:
and
versus the alternative hypothesis:
A similar set of hypotheses to test whether the two distributions are the same are given by (Conover, 1980, p. 216):
versus the two-sided alternative hypothesis:
or
versus the alternative hypothesis:
or
versus the alternative hypothesis:
Note that this second set of hypotheses (9)–(14) is not equivalent to the set of hypotheses (3)–(8). For example, if takes on the values 1 and 4 with probability 1/2 for each, and only takes on values in the interval (1, 4) with strict inequality at the enpoints (e.g., 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:
where 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 is positive, this means that observations in group 1 tend to be larger than observations in group 2, and if 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:
where 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
versus the alternative hypothesis
The other one-sided alternative hypothesis () and two-sided alternative hypothesis () 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:
where denotes the shift in scale between the two groups. Alternatively, the null and alternative hypotheses for this scale shift can be written as
versus the alternative hypothesis
The other one-sided alternative hypothesis () and two-sided alternative hypothesis () 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=.
Then the mean and standard deviation of the reference group is
,
while the mean and standard deviation of the treatment group is
.
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
observations with the
observations and ranking them from smallest to largest, and then
computing the statistic
where
denote the ranks of the
observations when the
and
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
is too large. For small sample sizes, the exact distribution of
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:
where 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:
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 does not depend on the form of the underlying distribution of the and observations. Hence, tests based on are nonparametric (also called distribution-free). If the null hypothesis is not true, however, the distribution of will depend not only on the distributions of the and observations, but also upon the form the score function .
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
)
in the neighborhood where
.
A LMPRT of the null hypothesis (20) versus the alternative (21)
maximizes the slope of the power (as a function of
)
in the neighborhood where
.
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 | Shift Type | Test Name |
| Logistic | Location | Wilcoxon Rank Sum | |
| Normal or | * | Location | Van der Waerden or |
| Lognormal (log-scale) | Normal scores | ||
| Double Exponential | Location | Mood’s Median | |
| Exponential or | Scale | Savage scores | |
| Extreme Value |
* Denotes an approximation to the true score. The symbol
denotes the cumulative distribution function of the standard normal
distribution, and
denotes the sign function.
A large sample normal approximation to the distribution of the linear rank statistic for arbitrary score functions is given by Hettmansperger (1984, p.148). Under the null hypothesis (17) or (20), the mean and variance of are given by:
Hettmansperger (1984, Chapter 3) shows that under the null hypothesis of no difference between the two groups, the statistic
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.
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 denote a random variable representing measurements from group 1 with cumulative distribution function (cdf):
and let denote independent observations from this distribution. Let denote a random variable from group 2 with cdf:
and let denote independent observations from this distribution. Set , 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 denote the ordered, unique, uncensored observations for the combined samples (in the context of survival data, usually stands for “time of death”). For , let denote the number of observations from sample 1 (the observations) that are equal to , and let denote the observations from sample 2 (the observations) equal to this value. Set
the total number of observations equal to . If there are no tied uncensored observations, then for , otherwise it is greater than 1 for at least on value of .
For , let denote the number of censored observations from sample 1 (the observations) with censoring levels that fall into the interval where by definition, and let denote the number of censored observations from sample 2 (the observations) with censoring levels that fall into this interval. Set
the total number of censoring levels that fall into this interval.
Finally, set equal to the number of observations from sample 1 (uncensored and censored) known to be greater than or equal to , i.e., that lie in the interval , set equal to the number of observations from sample 2 (uncensored and censored) that lie in this interval, and set
In survival analysis jargon, denotes the number of people from sample 1 who are “at risk” at time , that is, these people are known to still be alive at this time. Similarly, denotes the number of people from sample 2 who are at risk at time , and denotes the total number of people at risk at time .
Score Statistics for Multiply Censored
Data
Prentice’s (1978) generalization of the two-sample score (linear rank)
statistic is given by:
where and 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 () | Score () | Test Name | Analogue |
| Logistic | Peto-Peto | Wilcoxon Rank Sum | ||
| “ | Gehan or Breslow | “ | ||
| “ | Tarone-Ware | “ | ||
| Normal, | Normal Scores 1 | Normal Scores | ||
| Lognormal | ||||
| “ | “ | Normal Scores 2 | “ | |
| Double | Generalized | Mood’s Median | ||
| Exponential | Sign | |||
| Exponential, | Logrank | Savage Scores | ||
| Extreme Value |
In Table 1 above,
denotes the cumulative distribution function of the standard normal
distribution,
denotes the probability density function of the standard normal
distribution, and
denotes the sign function. Also, the quantities
and
denote the estimates of the cumulative distribution function (cdf) and
survival function, respectively, at time
for the combined sample. The estimated cdf is related to the estimated
survival function by:
The quantity denotes the Altshuler (1970) estimate of the survival function at time 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:
(Prentice, 1978). When surv.est="kaplan-meier", the
survival function is estimated as:
(Kaplan and Meier, 1958), and when surv.est="peto-peto",
the survival function is estimated as:
where
(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:
(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 , but use the Kaplan-Meier estimate of the survival function for .
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: , and if .
The Distribution of the Score
Statistic
Under the null hypothesis that the two distributions are the same, the
expected value of the score statistic
in Equation (6) is 0. The variance of
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:
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 in Equation (6) is re-written as:
where
and
are given above in Table 1, and the conditional permutation or
hypergeometric estimate
(variance="hypergeometric") is given by:
(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
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:
where
(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
and
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
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 observations) tend to be larger than the observations in group 2 (the 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.
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
be a vector of
independent and identically distributed (i.i.d.) observations from some
distribution with location parameter (e.g., mean or median)
,
and let
be a vector of
i.i.d. observations from the same distribution with possibly different
location parameter
.
Consider the test of the null hypothesis that the difference in the location parameters is equal to some specified value:
where
and denotes the hypothesized difference in the meansures of location (usually ).
The three possible alternative hypotheses are the upper one-sided
alternative (alternative="greater")
the lower one-sided alternative (alternative="less")
and the two-sided alternative
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
,
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
.
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
.
In this simple example, we assumed the hypothesized differences in the means under the null hypothesis was . If we had hypothesized a different value for , 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:
where and denote the cumulative distribution functions for group 1 and group 2, respectively. If , this implies that the observations in group 1 tend to be larger than the observations in group 2, and if , 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
confidence interval for the difference in means or medians based on the
two-sample permutation test by finding the values of
that correspond to obtaining a p-value of
(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
differences
,
are assumed to be independent observations from some symmetric
distribution with mean
.
The one-sample
permutation test can then be applied to the differences.