vignettes/distribution-diagnostics.Rmd
distribution-diagnostics.RmdThis vignette explains probability plots, plotting positions, goodness-of-fit tests, and Box-Cox transformations. Complete and censored samples are treated together so that the assumptions and extensions of each diagnostic can be compared.
Related vignettes:
Help topic: qqPlot.
If y is not supplied, the vector x is
assumed to be a sample from the probability distribution specified by
the argument distribution (and param.list if
estimate.params=FALSE). When plot.type="Q-Q",
the quantiles of x are plotted on the
-axis
against the quantiles of the assumed distribution on the
-axis.
If y is supplied and plot.type="Q-Q", the
empirical quantiles of y are plotted against the empirical
quantiles of x.
When plot.type="Tukey Mean-Difference Q-Q", the
difference of the quantiles is plotted on the
-axis
against the mean of the quantiles on the
-axis.
Special Distributions
When y is not supplied and the argument
distribution specifies one of the following distributions,
the function qqPlot behaves in the manner described
below.
"lnorm" Lognormal
Distribution. The log-transformed quantiles are plotted against
quantiles from a Normal (Gaussian) distribution.
"lnormAlt" Lognormal
Distribution (alternative parameterization). The untransformed
quantiles are plotted against quantiles from a Lognormal
distribution.
"lnorm3" Three-Parameter
Lognormal Distribution. The quantiles of
log(x-threshold) are plotted against quantiles from a
Normal (Gaussian) distribution. The value of threshold is
either specified in the argument param.list, or, if
estimate.params=TRUE, then it is estimated.
"zmnorm" Zero-Modified Normal
Distribution. The quantiles of the non-zero values (i.e.,
x[x!=0]) are plotted against quantiles from a Normal
(Gaussian) distribution.
"zmlnorm" Zero-Modified
Lognormal Distribution. The quantiles of the log-transformed
positive values (i.e., log(x[x>0])) are plotted against
quantiles from a Normal (Gaussian) distribution.
"zmlnormAlt" Lognormal
Distribution (alternative parameterization). The quantiles of the
untransformed positive values (i.e., x[x>0]) are plotted
against quantiles from a Lognormal distribution.
Explanation of Q-Q Plots
A probability plot or
quantile-quantile (Q-Q) plot is a graphical
display invented by Wilk and Gnanadesikan (1968) to compare a data set
to a particular probability distribution or to compare it to another
data set. The idea is that if two population distributions are exactly
the same, then they have the same quantiles (percentiles), so a plot of
the quantiles for the first distribution vs. the quantiles for the
second distribution will fall on the 0-1 line (i.e., the straight line
with intercept 0 and slope 1). If the two distributions have the same
shape and spread but different locations, then the plot of the quantiles
will fall on the line
(parallel to the 0-1 line) where
denotes the difference in locations. If the distributions have different
locations and differ by a multiplicative constant
,
then the plot of the quantiles will fall on the line
(D’Agostino, 1986a, p. 25; Helsel and Hirsch, 1986, p. 42). Various
kinds of differences between distributions will yield various kinds of
deviations from a straight line.
Comparing Observations to a Hypothesized Distribution
Let
denote the observations in a random sample of size
from some unknown distribution with cumulative distribution function
,
and let
denote the ordered observations. Depending on the particular formula
used for the empirical cdf (see ecdfPlot),
the
’th
order statistic is an estimate of the
’th,
’th,
etc., quantile. For the moment, assume the
’th
order statistic is an estimate of the
’th
quantile, that is:
so
If we knew the form of the true cdf , then the plot of vs. would form approximately a straight line based on Equation (2) above. A probability plot is a plot of vs. , where denotes the cdf associated with the hypothesized distribution. The probability plot should fall roughly on the line if . If and merely differ by a shift in location and scale, that is, if , then the plot should fall roughly on the line .
The quantity in Equation (1) above is called the plotting position for the probability plot. This particular formula for the plotting position is appealing because it can be shown that for any continuous distribution
(Nelson, 1982, pp. 299-300; Stedinger et al., 1993). That is, the ’th plotting position defined as in Equation (1) is the expected value of the true cdf evaluated at the ’th order statistic. Many authors and practitioners, however, prefer to use a plotting position that satisfies:
or one that satisfies
where denotes the median of the distribution of the ’th order statistic, and denotes the ’th order statistic in a random sample of uniform (0,1) random variates.
The plotting positions in Equation (4) are often approximated since the expected value of the ’th order statistic is often difficult and time-consuming to compute. Note that these plotting positions will differ for different distributions.
The plotting positions in Equation (5) were recommended by Filliben (1975) because they require computing or approximating only the medians of uniform (0,1) order statistics, no matter what the form of the assumed cdf . Also, the median may be preferred as a measure of central tendency because the distributions of most order statistics are skewed.
Most plotting positions can be written as:
where
(D’Agostino, 1986a, p.25; Stedinger et al., 1993). The quantity
is sometimes called the “plotting position constant”, and is determined
by the argument plot.pos.con in the function
qqPlot. The table below, adapted from Stedinger et
al. (1993), displays commonly used plotting positions based on equation
(6) for several distributions.
| Distribution | |||
| Often Used | |||
| Name | a | With | References |
| Weibull | 0 | Weibull, | Weibull (1939), |
| Uniform | Stedinger et al. (1993) | ||
| Median | 0.3175 | Several | Filliben (1975), |
| Vogel (1986) | |||
| Blom | 0.375 | Normal | Blom (1958), |
| and Others | Looney and Gulledge (1985) | ||
| Cunnane | 0.4 | Several | Cunnane (1978), |
| Chowdhury et al. (1991) | |||
| Gringorten | 0.44 | Gumbel | Gringorton (1963), |
| Vogel (1986) | |||
| Hazen | 0.5 | Several | Hazen (1914), |
| Chambers et al. (1983), | |||
| Cleveland (1993) |
For moderate and large sample sizes, there is very little difference in visual appearance of the Q-Q plot for different choices of plotting positions.
Comparing Two Data Sets
Let
denote the observations in a random sample of size
from some unknown distribution with cumulative distribution function
,
and let
denote the ordered observations. Similarly, let
denote the observations in a random sample of size
from some unknown distribution with cumulative distribution function
,
and let
denote the ordered observations. Suppose we are interested in
investigating whether the shape of the distribution with cdf
is the same as the shape of the distribution with cdf
(e.g.,
and
may both be normal distributions but differ in mean and standard
deviation).
When , we can visually explore this question by plotting vs. , for . The values in are spread out in a certain way depending on the true distribution: they may be more or less symmetric about some value (the population mean or median) or they may be skewed to the right or left; they may be concentrated close to the mean or median (platykurtic) or there may be several observations “far away” from the mean or median on either side (leptokurtic). Similarly, the values in are spread out in a certain way. If the values in and are spread out in the same way, then the plot of vs. will be approximately a straight line. If the cdf is exactly the same as the cdf , then the plot of vs. will fall roughly on the straight line . If and differ by a shift in location and scale, that is, if , then the plot will fall roughly on the line .
When , a slight adjustment has to be made to produce the plot. Let denote the plotting positions corresponding to the empirical quantiles for the ’s and let denote the plotting positions corresponding the empirical quantiles for the ’s. Then we plot vs. for where
That is, the values for the ’s are determined by linear interpolation based on the values of the plotting positions for and .
A similar adjustment is made when .
Note that the R function qqplot uses a different method
than the one in Equation (7) above; it uses linear interpolation based
on 1:n and m by calling the
approx function.
Help topic: gofTest.
Shapiro-Wilk Goodness-of-Fit Test
(test="sw").
The Shapiro-Wilk goodness-of-fit test (Shapiro and Wilk, 1965;
Royston, 1992a) is one of the most commonly used goodness-of-fit tests
for normality. You can use it to test the following hypothesized
distributions: Normal, Lognormal, Three-Parameter
Lognormal, Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta). In addition, you can also use it to test
the null hypothesis of any continuous distribution that is
available (see the section on Distribution.df,
and see explanation below).
Shapiro-Wilk W-Statistic and P-Value for Testing
Normality
Let
denote a random variable with cumulative distribution function (cdf)
.
Suppose we want to test the null hypothesis that
is the cdf of a normal
(Gaussian) distribution with some arbitrary mean
and standard deviation
against the alternative hypothesis that
is the cdf of some other distribution. The table below shows the random
variable for which
is the assumed cdf, given the value of the argument
distribution.
|
Value of |
|
Random Variable for |
|
|
Distribution Name |
which is the cdf |
|
|
Normal |
|
|
|
Lognormal (Log-space) |
|
|
|
Lognormal (Untransformed) |
|
|
|
Three-Parameter Lognormal |
|
|
|
Zero-Modified Normal |
|
|
|
Zero-Modified Lognormal (Log-space) |
|
|
|
Zero-Modified Lognormal (Untransformed) |
Note that for the three-parameter lognormal distribution, the symbol denotes the threshold parameter.
Let denote the vector of ordered observations assumed to come from a normal distribution.
The Shapiro-Wilk W-Statistic
Shapiro and Wilk (1965) introduced the following statistic to test the
null hypothesis that
is the cdf of a normal distribution:
where the quantity is the ’th element of the vector defined by:
where denotes the transpose operator, and is the vector of expected values and is the variance-covariance matrix of the order statistics of a random sample of size from a standard normal distribution. That is, the values of are the expected values of the standard normal order statistics weighted by their variance-covariance matrix, and normalized so that
It can be shown that the coefficients are antisymmetric, that is,
and for odd ,
Now because
and
the -statistic in Equation (1) is the same as the square of the sample product-moment correlation between the vectors and :
where
(see the R help file for cor).
The Shapiro-Wilk -statistic is also simply the ratio of two estimators of variance, and can be rewritten as
where the numerator is the square of the best linear unbiased estimate (BLUE) of the standard deviation, and the denominator is the minimum variance unbiased estimator (MVUE) of the variance:
Small values of indicate the null hypothesis is probably not true. Shapiro and Wilk (1965) computed the values of the coefficients and the percentage points for (based on smoothing the empirical null distribution of ) for sample sizes up to 50. Computation of the -statistic for larger sample sizes can be cumbersome, since computation of the coefficients requires storage of at least reals followed by matrix inversion (Royston, 1992a).
The Shapiro-Francia W’-Statistic
Shapiro and Francia (1972) introduced a modification of the
-test
that depends only on the expected values of the order statistics
()
and not on the variance-covariance matrix
():
where the quantity is the ’th element of the vector defined by:
Several authors, including Ryan and Joiner (1973), Filliben (1975), and Weisberg and Bingham (1975), note that the -statistic is intuitively appealing because it is the squared Pearson correlation coefficient associated with a normal probability plot. That is, it is the squared correlation between the ordered sample values and the expected normal order statistics :
Shapiro and Francia (1972) present a table of empirical percentage points for based on a Monte Carlo simulation. It can be shown that the asymptotic null distributions of and are identical, but convergence is very slow (Verrill and Johnson, 1988).
The Weisberg-Bingham Approximation to the W’-Statistic
Weisberg and Bingham (1975) introduced an approximation of the
Shapiro-Francia
-statistic
that is easier to compute. They suggested using Blom scores (Blom, 1958,
pp.68–75) to approximate the element of
:
where the quantity is the ’th element of the vector defined by:
and
and denotes the standard normal cdf. That is, the values of the elements of in Equation (14) are replaced with their estimates based on the usual plotting positions for a normal distribution.
Royston’s Approximation to the Shapiro-Wilk W-Test
Royston (1992a) presents an approximation for the coefficients
necessary to compute the Shapiro-Wilk
-statistic,
and also a transformation of the
-statistic
that has approximately a standard normal distribution under the null
hypothesis.
Noting that, up to a constant, the components of in Equation (14) and in Equation (17) differ from those of in Equation (2) mainly in the first and last two components, Royston (1992a) used the approximation as the basis for approximating using polynomial (quintic) regression analysis. For , the approximation gave the following equations for the last two (and hence first two) components of :
where
The other components are computed as:
for if , or if , where
if , and
if .
Royston (1992a) found his approximation to to be accurate to at least in the third decimal place over all values of and selected values of , and also found that critical percentage points of based on his approximation agreed closely with the exact critical percentage points calculated by Verrill and Johnson (1988).
Transformation of the Null Distribution of W to
Normality
In order to compute a p-value associated with a particular value of
,
Royston (1992a) approximated the distribution of
by a three-parameter
lognormal distribution for
,
and the upper half of the distribution of
by a two-parameter lognormal
distribution for
.
Setting
the p-value associated with is given by:
For , the quantities necessary to compute are given by:
For , the quantities necessary to compute are given by:
For the last approximation when , Royston (1992a) claims this approximation is actually valid for sample sizes up to .
Modification for the Three-Parameter Lognormal
Distribution
When distribution="lnorm3", the function
gofTest assumes the vector
is a random sample from a three-parameter
lognormal distribution. It estimates the threshold parameter via the
zero-skewness method (see elnorm3),
and then performs the Shapiro-Wilk goodness-of-fit test for normality on
where
is the estimated threshold parmater. Because the threshold parameter has
to be estimated, however, the p-value associated with the computed
z-statistic will tend to be conservative (larger than it should be under
the null hypothesis). Royston (1992b) proposed the following
transformation of the z-statistic:
where for ,
and for ,
where
and denotes the threshold parameter. The p-value associated with this test is then given by:
Testing Goodness-of-Fit for Any Continuous
Distribution
The function gofTest extends the Shapiro-Wilk test to test
for goodness-of-fit for any continuous distribution by using the idea of
Chen and Balakrishnan (1995), who proposed a general purpose approximate
goodness-of-fit test based on the Cramer-von Mises or Anderson-Darling
goodness-of-fit tests for normality. The function gofTest
modifies the approach of Chen and Balakrishnan (1995) by using the same
first 2 steps, and then applying the Shapiro-Wilk test:
Shapiro-Francia Goodness-of-Fit Test
(test="sf").
The Shapiro-Francia goodness-of-fit test (Shapiro and Francia, 1972;
Weisberg and Bingham, 1975; Royston, 1992c) is also one of the most
commonly used goodness-of-fit tests for normality. You can use it to
test the following hypothesized distributions: Normal,
Lognormal, Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta). In addition, you can also use it to test the null
hypothesis of any continuous distribution that is available (see the
section on Distribution.df).
See the section Testing Goodness-of-Fit for Any Continuous
Distribution above for an explanation of how this is done.
Royston’s Transformation of the Shapiro-Francia W’-Statistic to
Normality
Equation (13) above gives the formula for the Shapiro-Francia
W’-statistic, and Equation (16) above gives the formula for
Weisberg-Bingham approximation to the W’-statistic (denoted
).
Royston (1992c) presents an algorithm to transform the
-statistic
so that its null distribution is approximately a standard normal. For
,
Royston (1992c) approximates the distribution of
by a lognormal
distribution. Setting
the p-value associated with is given by:
The quantities necessary to compute are given by:
Testing Goodness-of-Fit for Any Continuous
Distribution
The function gofTest extends the Shapiro-Francia test to
test for goodness-of-fit for any continuous distribution by using the
idea of Chen and Balakrishnan (1995), who proposed a general purpose
approximate goodness-of-fit test based on the Cramer-von Mises or
Anderson-Darling goodness-of-fit tests for normality. The function
gofTest modifies the approach of Chen and Balakrishnan
(1995) by using the same first 2 steps, and then applying the
Shapiro-Francia test:
Probability Plot Correlation Coefficient (PPCC)
Goodness-of-Fit Test (test="ppcc").
The PPPCC goodness-of-fit test (Filliben, 1975; Looney and Gulledge,
1985) can be used to test the following hypothesized distributions:
Normal, Lognormal, Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta). In addition, you can also use it to test the null
hypothesis of any continuous distribution that is available (see the
section on Distribution.df).
The function gofTest computes the PPCC test statistic using
Blom plotting positions.
Filliben (1975) proposed using the correlation coefficient from a normal probability plot to perform a goodness-of-fit test for normality, and he provided a table of critical values for under the for samples sizes between 3 and 100. Vogel (1986) provided an additional table for sample sizes between 100 and 10,000.
Looney and Gulledge (1985) investigated the characteristics of
Filliben’s probability plot correlation coefficient (PPCC) test using
the plotting position formulas given in Filliben (1975), as well as
three other plotting position formulas: Hazen plotting positions,
Weibull plotting positions, and Blom plotting positions (see the section
on qqPlot for
an explanation of these plotting positions). They concluded that the
PPCC test based on Blom plotting positions performs slightly better than
tests based on other plotting positions, and they provide a table of
empirical percentage points for the distribution of
based on Blom plotting positions.
The function gofTest computes the PPCC test statistic
using Blom plotting positions. It can be shown that the square of this
statistic is equivalent to the Weisberg-Bingham Approximation to the
Shapiro-Francia W’-Test (Weisberg and Bingham, 1975; Royston, 1993).
Thus the PPCC goodness-of-fit test is equivalent to the Shapiro-Francia
goodness-of-fit test.
Anderson-Darling Goodness-of-Fit Test
(test="ad").
The Anderson-Darling goodness-of-fit test (Stephens, 1986a; Thode,
2002) can be used to test the following hypothesized distributions:
Normal, Lognormal, Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta).
When test="ad", the function gofTest calls
the function ad.test
in the package nortest. Documentation from that package is as
follows:
The Anderson-Darling test is an EDF omnibus test for the composite hypothesis of normality. The test statistic is:
where . Here, is the cumulative distribution function of the standard normal distribution, and and are mean and standard deviation of the data values. The p-value is computed from the modified statistic according to Table 4.9 in Stephens .
Cramer-von Mises Goodness-of-Fit Test
(test="cvm").
The Cramer-von Mises goodness-of-fit test (Stephens, 1986a; Thode,
2002) can be used to test the following hypothesized distributions:
Normal, Lognormal, Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta).
When test="cvm", the function gofTest calls
the function cvm.test
in the package nortest. Documentation from that package is as
follows:
The Cramer-von Mises test is an EDF omnibus test for the composite hypothesis of normality. The test statistic is:
where . Here, is the cumulative distribution function of the standard normal distribution, and and are mean and standard deviation of the data values. The p-value is computed from the modified statistic according to Table 4.9 in Stephens .
Lilliefors Goodness-of-Fit Test
(test="lillie").
The Lilliefors goodness-of-fit test (Stephens, 1974; Dallal and
Wilkinson, 1986; Thode, 2002) can be used to test the following
hypothesized distributions: Normal, Lognormal,
Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta).
When test="lillie", the function gofTest
calls the function lillie.test
in the package nortest. Documentation from that package is as
follows:
The Lilliefors (Kolmogorov-Smirnov) test is an EDF omnibus test for the composite hypothesis of normality. The test statistic is the maximal absolute difference between empirical and hypothetical cumulative distribution function. It may be computed as with
where . Here, is the cumulative distribution function of the standard normal distribution, and and are mean and standard deviation of the data values. The p-value is computed from the Dallal-Wilkinson (1986) formula, which is claimed to be only reliable when the p-value is smaller than 0.1. If the Dallal-Wilkinson p-value turns out to be greater than 0.1, then the p-value is computed from the distribution of the modified statistic , see Stephens (1974), the actual p-value formula being obtained by a simulation and approximation process.
Zero-Skew Goodness-of-Fit Test
(test="skew").
The Zero-skew goodness-of-fit test (D’Agostino, 1970) can be used to
test the following hypothesized distributions: Normal,
Lognormal, Zero-Modified
Normal, or Zero-Modified
Lognormal (Delta).
When test="skew", the function gofTest
tests the null hypothesis that the skew of the distribution is 0:
where
and the quantity denotes the ’th moment about the mean (also called the ’th central moment). The quantity is called the coefficient of skewness, and is estimated by:
where
denotes the ’th sample central moment.
The possible alternative hypotheses are:
which correspond to alternative="two-sided",
alternative="less", andalternative="greater", respectively.
To test the null hypothesis of zero skew, D’Agostino (1970) derived an approximation to the distribution of under the null hypothesis of zero-skew, assuming the observations comprise a random sample from a normal (Gaussian) distribution. Based on D’Agostino’s approximation, the statistic shown below is assumed to follow a standard normal distribution and is used to compute the p-value associated with the test of :
where
When the sample size is at least 150, a simpler approximation may be used in which in Equation (61) is assumed to follow a standard normal distribution and is used to compute the p-value associated with the hypothesis test.
Kolmogorov-Smirnov Goodness-of-Fit Test
(test="ks").
When test="ks", the function gofTest calls
the R function ks.test to compute the test statistic and
p-value. Note that for the one-sample case, the distribution parameters
should be pre-specified and not estimated from the data, and if the
distribution parameters are estimated from the data you will receive a
warning that this test is very conservative (Type I error smaller than
assumed; high Type II error) in this case.
ProUCL Kolmogorov-Smirnov Goodness-of-Fit Test for
Gamma (test="proucl.ks.gamma").
When test="proucl.ks.gamma", the function
gofTest calls the R function ks.test to
compute the Kolmogorov-Smirnov test statistic based on the maximum
likelihood estimates of the shape and scale parameters (see egamma).
The p-value is computed based on the simulated critical values given in
ProUCL.Crit.Vals.for.KS.Test.for.Gamma.array
(USEPA, 2015). The sample size must be between 5 and 1000, and the value
of the maximum likelihood estimate of the shape parameter must be
between 0.025 and 50. The critical value for the test statistic is
computed using the simulated critical values and linear
interpolation.
ProUCL Anderson-Darling Goodness-of-Fit Test for
Gamma (test="proucl.ad.gamma").
When test="proucl.ad.gamma", the function
gofTest computes the Anderson-Darling test statistic
(Stephens, 1986a, p.101) based on the maximum likelihood estimates of
the shape and scale parameters (see egamma).
The p-value is computed based on the simulated critical values given in
ProUCL.Crit.Vals.for.AD.Test.for.Gamma.array
(USEPA, 2015). The sample size must be between 5 and 1000, and the value
of the maximum likelihood estimate of the shape parameter must be
between 0.025 and 50. The critical value for the test statistic is
computed using the simulated critical values and linear
interpolation.
Chi-Squared Goodness-of-Fit Test
(test="chisq").
The method used by gofTest is a modification of what is
used for chisq.test. If the hypothesized distribution
function is completely specified, the degrees of freedom are
where
denotes the number of classes. If any parameters are estimated, the
degrees of freedom depend on the method of estimation. The function
gofTest follows the convention of computing degrees of
freedom as
,
where
is the number of parameters estimated. It can be shown that if the
parameters are estimated by maximum likelihood, the degrees of freedom
are bounded between
and
.
Therefore, especially when the sample size is small, it is important to
compare the test statistic to the chi-squared distribution with both
and
degrees of freedom. See Kendall and Stuart (1991, Chapter 30) for a more
complete discussion.
The distribution theory of chi-square statistics is a large sample theory. The expected cell counts are assumed to be at least moderately large. As a rule of thumb, each should be at least 5. Although authors have found this rule to be conservative (especially when the class probabilities are not too different from each other), the user should regard p-values with caution when expected cell counts are small.
Wilk-Shapiro Goodness-of-Fit Test for Uniform
Distribution (test="ws").
Wilk and Shapiro (1968) suggested this test in the context of jointly testing several independent samples for normality simultaneously. If denote the p-values associated with the test for normality of independent samples, then under the null hypothesis that all samples come from a normal distribution, the p-values are a random sample of observations from a Uniform distribution, that is a Uniform distribution with minimum 0 and maximum 1. Wilk and Shapiro (1968) suggested two different methods for testing whether the p-values come from a Uniform distribution:
Test Based on Normal Scores. Under the null hypothesis, the normal scores
are a random sample of observations from a standard normal distribution. Wilk and Shapiro (1968) denote the ’th normal score by
and note that under the null hypothesis, the quantity defined as
has a standard normal distribution. Wilk and Shapiro (1968) were
interested in the alternative hypothesis that some of the
independent samples did not come from a normal distribution and hence
would be associated with smaller p-values than expected under the null
hypothesis, which translates to the alternative that the cdf for the
distribution of the p-values is greater than the cdf of a Uniform
distribution (alternative="greater"). In terms of the test
statistic
,
this alternative hypothesis would tend to make
smaller than expected, so the p-value is given by
.
For the one-sided lower alternative that the cdf for the distribution of
p-values is less than the cdf for a Uniform
distribution, the p-value is given by
.
Test Based on Chi-Square Scores. Under the null hypothesis, the chi-square scores
are a random sample of observations from a chi-square distribution with 2 degrees of freedom (Fisher, 1950). Wilk and Shapiro (1968) denote the ’th chi-square score by
and note that under the null hypothesis, the quantity defined as
has a chi-square distribution with
degrees of freedom. Wilk and Shapiro (1968) were interested in the
alternative hypothesis that some of the
independent samples did not come from a normal distribution and hence
would be associated with smaller p-values than expected under the null
hypothesis, which translates to the alternative that the cdf for the
distribution of the p-values is greater than the cdf of a Uniform
distribution (alternative="greater"). In terms of the test
statistic
,
this alternative hypothesis would tend to make
larger than expected, so the p-value is given by
where denotes the cumulative distribution function of the chi-square distribution with degrees of freedom. For the one-sided lower alternative that the cdf for the distribution of p-values is less than the cdf for a Uniform distribution, the p-value is given by
Help topic: ppointsCensored.
Methods for computing plotting positions for complete data sets (no
censored observations) are discussed in D’Agostino, R.B. (1986a) and
Cleveland (1993). For data sets with censored observations, these
methods must be modified. The function ppointsCensored
allows you to compute plotting positions based on any of the following
methods:
prob.method="kaplan-meier").prob.method="nelson").prob.method="michael-schucany") (the default).prob.method="hirsch-stedinger").Let denote a random sample of observations from some distribution. Assume () of these observations are known and () of these observations are all censored below (left-censored) or all censored above (right-censored) at fixed censoring levels
For the case when , the data are said to be Type I multiply censored. For the case when , set . If the data are left-censored and all known observations are greater than or equal to , or if the data are right-censored and all known observations are less than or equal to , then the data are said to be Type I singly censored (Nelson, 1982, p.7), otherwise they are considered to be Type I multiply censored.
Let denote the number of observations censored below or above censoring level for , so that
Let denote the “ordered” observations, where now “observation” means either the actual observation (for uncensored observations) or the censoring level (for censored observations). For right-censored data, if a censored observation has the same value as an uncensored one, the uncensored observation should be placed first. For left-censored data, if a censored observation has the same value as an uncensored one, the censored observation should be placed first.
Note that in this case the quantity does not necessarily represent the ’th “largest” observation from the (unknown) complete sample.
Finally, let (omega) denote the set of subscripts in the “ordered” sample that correspond to uncensored observations.
Product-Limit Method of Kaplan and Meier
(prob.method="kaplan-meier")
For complete data sets (no censored observations), the
empirical probabilities estimator of the
cumulative distribution function evaluated at the
’th
ordered observation is given by (D’Agostino, 1986a, p.8):
where
denotes the number of observations less than or equal to
(see the help file for ecdfPlot).
Kaplan and Meier (1958) extended this method of computing the empirical
cdf to the case of right-censored data.
Right-Censored Data
(censoring.side="right")
Let
denote the survival function evaluated at
,
that is:
Kaplan and Meier (1958) show that a nonparametric estimate of the survival function at the ’th ordered observation that is not censored (i.e., ), is given by:
where is the number of observations (uncensored or censored) with values greater than or equal to , and denotes the number of uncensored observations exactly equal to (if there are no tied uncensored observations then will equal 1 for all values of ). (See also Lee and Wang, 2003, pp. 64–69; Michael and Schucany, 1986). By convention, the estimate of the survival function at a censored observation is set equal to the estimated value of the survival function at the largest uncensored observation less than or equal to that censoring level. If there are no uncensored observations less than or equal to a particular censoring level, the estimate of the survival function is set to 1 for that censoring level.
Thus the Kaplan-Meier plotting position at the ’th ordered observation that is not censored (i.e., ), is given by:
The plotting position for a censored observation is set equal to the plotting position associated with the largest uncensored observation less than or equal to that censoring level. If there are no uncensored observations less than or equal to a particular censoring level, the plotting position is set to 0 for that censoring level.
As an example, consider the following right-censored data set:
The table below shows how the plotting positions are computed.
| Plotting Position | |||||
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Note that for complete data sets, Equation (6) reduces to Equation (3).
Left-Censored Data
(censoring.side="left")
Gillespie et al. (2010) give formulas for the Kaplan-Meier estimator for
the case of left-cesoring (censoring.side="left"). In this
case, the plotting position for the
’th
ordered observation, assuming it is not censored, is computed as:
where is the number of observations (uncensored or censored) with values less than or equal to , and denotes the number of uncensored observations exactly equal to (if there are no tied uncensored observations then will equal 1 for all values of ). The plotting position is equal to 1 for the largest uncensored order statistic.
As an example, consider the following left-censored data set:
The table below shows how the plotting positions are computed.
| Plotting Position | |||||
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Note that for complete data sets, Equation (7) reduces to Equation (3).
Modified Kaplan-Meier Method
(prob.method="modified kaplan-meier")
(Left-Censored Data Only.) For left-censored data, the modified
Kaplan-Meier method is the same as the Kaplan-Meier method, except that
for the largest uncensored order statistic, the plotting position is not
set to 1 but rather is set equal to the Blom plotting position:
.
This method is useful, for example, when creating Quantile-Quantile
plots.
Hazard Plotting Method of Nelson
(prob.method="nelson")
(Right-Censored Data Only.) For right-censored data, Equation (5) can be
re-written as:
Nelson (1972) proposed the following formula for plotting positions for the uncensored observations in the context of estimating the hazard function (see Michael and Schucany,1986, p.469):
See Lee and Wang (2003) for more information about the hazard function.
As for the Kaplan and Meier (1958) method, the plotting position for a censored observation is set equal to the plotting position associated with the largest uncensored observation less than or equal to that censoring level. If there are no uncensored observations less than or equal to a particular censoring level, the plotting position is set to 0 for that censoring level.
Generalization of Product-Limit Method, Michael and
Schucany
(prob.method="michael-schucany")
For complete data sets, the disadvantage of using Equation (3) above to
define plotting positions is that it implies the largest observed value
is the maximum possible value of the distribution (the
’th
percentile). This may be satisfactory if the underlying distribution is
known to be discrete, but it is usually not satisfactory if the
underlying distribution is known to be continuous.
A more frequently used formula for plotting positions for complete data sets is given by:
where
(Cleveland, 1993, p. 18; D’Agostino, 1986a, pp. 8,25). The value of
is usually chosen so that the plotting positions are approximately
unbiased (i.e., approximate the mean of their distribution) or else
approximate the median value of their distribution (see the help file
for ecdfPlot).
Michael and Schucany (1986) extended this method for both left- and
right-censored data sets.
Right-Censored Data
(censoring.side="right")
For right-censored data sets, the plotting positions for the uncensored
observations are computed as:
Note that the plotting positions proposed by Herd (1960) and Johnson (1964) are a special case of Equation (11) with . Equation (11) reduces to Equation (10) in the case of complete data sets. Note that unlike the Kaplan-Meier method, plotting positions associated with tied uncensored observations are not the same (just as in the case for complete data using Equation (10)).
As for the Kaplan and Meier (1958) method, for right-censored data the plotting position for a censored observation is set equal to the plotting position associated with the largest uncensored observation less than or equal to that censoring level. If there are no uncensored observations less than or equal to a particular censoring level, the plotting position is set to 0 for that censoring level.
Left-Censored Data
(censoring.side="left")
For left-censored data sets the plotting positions are computed as:
Equation (12) reduces to Equation (10) in the case of complete data sets. Note that unlike the Kaplan-Meier method, plotting positions associated with tied uncensored observations are not the same (just as in the case for complete data using Equation (10)).
For left-censored data, the plotting position for a censored observation is set equal to the plotting position associated with the smallest uncensored observation greater than or equal to that censoring level. If there are no uncensored observations greater than or equal to a particular censoring level, the plotting position is set to 1 for that censoring level.
Generalization of Product-Limit Method, Hirsch and
Stedinger
(prob.method="hirsch-stedinger")
Hirsch and Stedinger (1987) use a slightly different approach than
Kaplan and Meier (1958) and Michael and Schucany (1986) to derive a
nonparametric estimate of the survival function (probability of
exceedance) in the context of left-censored data. First they estimate
the value of the survival function at each of the censoring levels. The
value of the survival function for an uncensored observation between two
adjacent censoring levels is then computed by linear interpolation (in
the form of a plotting position). See also Helsel and Cohn (1988).
The discussion below presents an extension of the method of Hirsch and Stedinger (1987) to the case of right-censored data, and then presents the original derivation due to Hirsch and Stedinger (1987) for left-censored data.
Right-Censored Data
(censoring.side="right")
For right-censored data, the survival function is estimated as follows.
For the
’th
censoring level
(),
write the value of the survival function as:
where
Now set
| # uncensored observations in | ||
| # observations in |
for . Then the method of moments estimator of the conditional probability in Equation (13) is given by:
Hence, by equations (13) and (18) we have
which can be rewritten as:
Equation (20) can be solved interatively for . Note that
Once the values of the survival function at the censoring levels are computed, the plotting positions for the uncensored observations in the interval () are computed as
where denotes the plotting position constant, , and denotes the rank of the ’th observation among the uncensored observations in the interval . (Tied observations are given distinct ranks.)
For the observations censored at censoring level (), the plotting positions are computed as:
where denotes the rank of the ’th observation among the observations censored at censoring level . Note that all the observations censored at the same censoring level are given distinct ranks, even though there is no way to distinguish between them.
Left-Censored Data
(censoring.side="left")
For left-censored data, Hirsch and Stedinger (1987) modify the
definition of the survival function as follows:
For continuous distributions, the functions in Equations (4) and (25) are identical.
Hirsch and Stedinger (1987) show that for the ’th censoring level (), the value of the survival function can be written as:
where and are defined in Equations (14) and (15).
Now set
| # uncensored observations in | ||
| # observations in |
for . Then the method of moments estimator of the conditional probability in Equation (26) is given by:
Hence, by Equations (26) and (29) we have
which can be solved interatively for . Note that
Once the values of the survival function at the censoring levels are computed, the plotting positions for the uncensored observations in the interval () are computed as
where denotes the plotting position constant, , and denotes the rank of the ’th observation among the uncensored observations in the interval . (Tied observations are given distinct ranks.)
For the observations censored at censoring level (), the plotting positions are computed as:
where denotes the rank of the ’th observation among the observations censored at censoring level . Note that all the observations censored at the same censoring level are given distinct ranks, even though there is no way to distinguish between them.
Help topic: gofTestCensored.
Let
denote a vector of
observations from from some distribution with cdf
.
Suppose we want to test the null hypothesis that
is the cdf of a normal
(Gaussian) distribution with some arbitrary mean
and standard deviation
against the alternative hypothesis that
is the cdf of some other distribution. The table below shows the random
variable for which
is the assumed cdf, given the value of the argument
distribution.
| Value of | Random Variable for | |
distribution
|
Distribution Name | which is the cdf |
“norm”
|
Normal | |
“lnorm”
|
Lognormal (Log-space) | |
“lnormAlt”
|
Lognormal (Untransformed) |
Assume () of these observations are known and () of these observations are all censored below (left-censored) or all censored above (right-censored) at fixed censoring levels
For the case when , the data are said to be Type I multiply censored. For the case when , set . If the data are left-censored and all known observations are greater than or equal to , or if the data are right-censored and all known observations are less than or equal to , then the data are said to be Type I singly censored (Nelson, 1982, p.7), otherwise they are considered to be Type I multiply censored.
Let denote the number of observations censored below or above censoring level for , so that
Let denote the “ordered” observations, where now “observation” means either the actual observation (for uncensored observations) or the censoring level (for censored observations). For right-censored data, if a censored observation has the same value as an uncensored one, the uncensored observation should be placed first. For left-censored data, if a censored observation has the same value as an uncensored one, the censored observation should be placed first.
Note that in this case the quantity does not necessarily represent the ’th “largest” observation from the (unknown) complete sample.
Note that for singly left-censored data:
and for singly right-censored data:
Finally, let (omega) denote the set of subscripts in the “ordered” sample that correspond to uncensored observations.
Shapiro-Wilk Goodness-of-Fit Test for Singly Censored
Data (test="sw")
Equation (8) in the section on gofTest
shows that for the case of complete ordered data
,
the Shapiro-Wilk
-statistic
is the same as the square of the sample product-moment correlation
between the vectors
and
:
where
and is defined by:
where denotes the transpose operator, and is the vector of expected values and is the variance-covariance matrix of the order statistics of a random sample of size from a standard normal distribution. That is, the values of are the expected values of the standard normal order statistics weighted by their variance-covariance matrix, and normalized so that
Computing Shapiro-Wilk W-Statistic for Singly Censored
Data
For the case of singly censored data, following Smith and Bain (1976)
and Verrill and Johnson (1988), Royston (1993) generalizes the
Shapiro-Wilk
-statistic
to:
where for left singly-censored data:
and for right singly-censored data:
Just like the function gofTest,
when test="sw", the function gofTestCensored
uses Royston’s (1992a) approximation for the coefficients
(see the section on gofTest).
Computing P-Values for the Shapiro-Wilk Test
Verrill and Johnson (1988) show that the asymptotic distribution of the
statistic in Equation (9) above is normal, but the rate of convergence
is “surprisingly slow” even for complete samples. They provide a table
of empirical percentiles of the distribution for the
-statistic
shown in Equation (9) above for several sample sizes and percentages of
censoring.
Based on the tables given in Verrill and Johnson (1988), Royston (1993) approximated the 90’th, 95’th, and 99’th percentiles of the distribution of the z-statistic computed from the -statistic. (The distribution of this z-statistic is assumed to be normal, but not necessarily a standard normal.) Denote these percentiles by , , and . The true mean and standard deviation of the z-statistic are estimated by the intercept and slope, respectively, from the linear regression of on for = 0.9, 0.95, and 0.99, where denotes the cumulative distribution function of the standard normal distribution. The p-value associated with this test is then computed as:
Note: Verrill and Johnson (1988) produced their tables based on Type II censoring. Royston’s (1993) approximation to the p-value of these tests, however, should be fairly accurate for Type I censored data as well.
Testing Goodness-of-Fit for Any Continuous
Distribution
The function gofTestCensored extends the Shapiro-Wilk test
that accounts for censoring to test for goodness-of-fit for any
continuous distribution by using the idea of Chen and Balakrishnan
(1995), who proposed a general purpose approximate goodness-of-fit test
based on the Cramer-von Mises or Anderson-Darling goodness-of-fit tests
for normality. The function gofTestCensored modifies the
approach of Chen and Balakrishnan (1995) by using the same first 2
steps, and then applying the Shapiro-Wilk test that accounts for
censoring:
linkegammaAltCensored).Shapiro-Francia Goodness-of-Fit Test
(test="sf")
Equation (15) in the section on gofTest
shows that for the complete ordered data
,
the Shapiro-Francia
-statistic
is the same as the squared Pearson correlation coefficient associated
with a normal probability plot.
Computing Shapiro-Francia W’-Statistic for Censored
Data
For the case of singly censored data, following Smith and Bain (1976)
and Verrill and Johnson (1988), Royston (1993) extends the computation
of the Weisberg-Bingham Approximation to the
-statistic
to the case of singly censored data:
where for left singly-censored data:
and for right singly-censored data:
and is defined as:
where
and
denotes the standard normal cdf. Note: Do not confuse
the elements of the vector
with the scalar
which denotes the number of censored observations. We use
here to be consistent with the notation in the section on gofTest.
Just like the function gofTest,
when test="sf", the function gofTestCensored
uses Royston’s (1992a) approximation for the coefficients
(see the section on gofTest).
In general, the Shapiro-Francia test statistic can be extended to multiply censored data using Equation (14) with defined as the orderd values of associated with uncensored observations, and defined as the ordered values of associated with uncensored observations:
and where the plotting positions in Equation (20) are replaced with
any of the plotting positions available in ppointsCensored
(see the description for the argument prob.method).
Computing P-Values for the Shapiro-Francia Test
Verrill and Johnson (1988) show that the asymptotic distribution of the
statistic in Equation (14) above is normal, but the rate of convergence
is “surprisingly slow” even for complete samples. They provide a table
of empirical percentiles of the distribution for the
-statistic
shown in Equation (14) above for several sample sizes and percentages of
censoring.
As for the Shapiro-Wilk test, based on the tables given in Verrill and Johnson (1988), Royston (1993) approximated the 90’th, 95’th, and 99’th percentiles of the distribution of the z-statistic computed from the -statistic. (The distribution of this z-statistic is assumed to be normal, but not necessarily a standard normal.) Denote these percentiles by , , and . The true mean and standard deviation of the z-statistic are estimated by the intercept and slope, respectively, from the linear regression of on for = 0.9, 0.95, and 0.99, where denotes the cumulative distribution function of the standard normal distribution. The p-value associated with this test is then computed as:
Note: Verrill and Johnson (1988) produced their tables based on Type II censoring. Royston’s (1993) approximation to the p-value of these tests, however, should be fairly accurate for Type I censored data as well, although this is an area that requires further investigation.
Testing Goodness-of-Fit for Any Continuous
Distribution
The function gofTestCensored extends the Shapiro-Francia
test that accounts for censoring to test for goodness-of-fit for any
continuous distribution by using the idea of Chen and Balakrishnan
(1995), who proposed a general purpose approximate goodness-of-fit test
based on the Cramer-von Mises or Anderson-Darling goodness-of-fit tests
for normality. The function gofTestCensored modifies the
approach of Chen and Balakrishnan (1995) by using the same first 2
steps, and then applying the Shapiro-Francia test that accounts for
censoring:
linkegammaAltCensored).Probability Plot Correlation Coefficient (PPCC)
Goodness-of-Fit Test (test="ppcc")
The function gofTestCensored computes the PPCC test
statistic using Blom plotting positions. It can be shown that the square
of this statistic is equivalent to the Weisberg-Bingham Approximation to
the Shapiro-Francia
-test
(Weisberg and Bingham, 1975; Royston, 1993). Thus the PPCC
goodness-of-fit test is equivalent to the Shapiro-Francia
goodness-of-fit test.
Help topic: boxcoxCensored.
Two common assumptions for several standard parametric hypothesis tests are:
For example, the standard one-sample t-test assumes all the observations come from the same normal distribution, and the standard two-sample t-test assumes that all the observations come from a normal distribution with the same variance, although the mean may differ between the two groups.
When the original data do not satisfy the above assumptions, data transformations are often used to attempt to satisfy these assumptions. Box and Cox (1964) presented a formalized method for deciding on a data transformation. Given a random variable from some distribution with only positive values, the Box-Cox family of power transformations is defined as:
| = | |||
where
is assumed to come from a normal distribution. This transformation is
continuous in
.
Note that this transformation also preserves ordering. See the help file
for boxcoxTransform
for more information on data transformations.
Box and Cox (1964) proposed choosing the appropriate value of based on maximizing the likelihood function. Alternatively, an appropriate value of can be chosen based on another objective, such as maximizing the probability plot correlation coefficient or the Shapiro-Wilk goodness-of-fit statistic.
Shumway et al. (1989) investigated extending the method of Box and Cox (1964) to the case of Type I censored data, motivated by the desire to produce estimated means and confidence intervals for air monitoring data that included censored values.
In the case when optimize=TRUE, the function
boxcoxCensored calls the R function nlminb to
minimize the negative value of the objective (i.e., maximize the
objective) over the range of possible values of
specified in the argument lambda. The starting value for
the optimization is always
(i.e., no transformation).
The next section explains assumptions and notation, and the section
after that explains how the objective is computed for the various
options for objective.name.
Assumptions and Notation
Let
denote a random sample of
observations from some continuous distribution. Assume
()
of these observations are known and
()
of these observations are all censored below (left-censored) or all
censored above (right-censored) at
fixed censoring levels
For the case when , the data are said to be Type I multiply censored. For the case when , set . If the data are left-censored and all known observations are greater than or equal to , or if the data are right-censored and all known observations are less than or equal to , then the data are said to be Type I singly censored (Nelson, 1982, p.7), otherwise they are considered to be Type I multiply censored.
Let denote the number of observations censored below or above censoring level for , so that
Let denote the “ordered” observations, where now “observation” means either the actual observation (for uncensored observations) or the censoring level (for censored observations). For right-censored data, if a censored observation has the same value as an uncensored one, the uncensored observation should be placed first. For left-censored data, if a censored observation has the same value as an uncensored one, the censored observation should be placed first.
Note that in this case the quantity does not necessarily represent the ’th “largest” observation from the (unknown) complete sample.
Finally, let (omega) denote the set of subscripts in the “ordered” sample that correspond to uncensored observations, and let denote the set of subscripts in the “ordered” sample that correspond to the censored observations censored at censoring level for .
We assume that there exists some value of such that the transformed observations
| = | |||
() form a random sample of Type I censored data from a normal distribution.
Note that for the censored observations, Equation (4) becomes:
| = | |||
where .
Computing the Objective
Objective Based on Probability Plot Correlation Coefficient
(objective.name="PPCC")
When objective.name="PPCC", the objective is computed as
the value of the normal probability plot correlation coefficient based
on the transformed data (see the description of the Probability Plot
Correlation Coefficient (PPCC) goodness-of-fit test in the section on gofTestCensored).
That is, the objective is the correlation coefficient for the normal quantile-quantile
plot for the transformed data. Large values of the PPCC tend to
indicate a good fit to a normal distribution.
Objective Based on Shapiro-Wilk Goodness-of-Fit Statistic
(objective.name="Shapiro-Wilk")
When objective.name="Shapiro-Wilk", the objective is
computed as the value of the Shapiro-Wilk goodness-of-fit statistic
based on the transformed data (see the description of the Shapiro-Wilk
test in the section on gofTestCensored).
Large values of the Shapiro-Wilk statistic tend to indicate a good fit
to a normal distribution.
Objective Based on Log-Likelihood Function
(objective.name="Log-Likelihood")
When objective.name="Log-Likelihood", the objective is
computed as the value of the log-likelihood function. Assuming the
transformed observations in Equation (4) above come from a normal
distribution with mean
and standard deviation
,
we can use the change of variable formula to write the log-likelihood
function as follows.
For Type I left censored data, the likelihood function is given by:
where and denote the probability density function (pdf) and cumulative distribution function (cdf) of the population. That is,
where and denote the pdf and cdf of the standard normal distribution, respectively (Shumway et al., 1989). For left singly censored data, Equation (6) simplifies to:
Similarly, for Type I right censored data, the likelihood function is given by:
and for right singly censored data this simplifies to:
For a fixed value of
,
the log-likelihood function is maximized by replacing
and
with their maximum likelihood estimators (see Maximum Likelihood
Estimation in the section on enormCensored).
Thus, when optimize=TRUE, Equation (6) or (10) is
maximized by iteratively solving for
using the MLEs for
and
.
When optimize=FALSE, the value of the objective is computed
by using Equation (6) or (10), using the values of
specified in the argument lambda, and using the MLEs of
and
.