This 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:

qqPlot

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 yy-axis against the quantiles of the assumed distribution on the xx-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 yy-axis against the mean of the quantiles on the xx-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 y=xy = x 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 y=x+by = x + b (parallel to the 0-1 line) where bb denotes the difference in locations. If the distributions have different locations and differ by a multiplicative constant mm, then the plot of the quantiles will fall on the line y=mx+by = mx + b (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 x_=x1,x2,…,xn\underline{x} = x_1, x_2, \ldots, x_n denote the observations in a random sample of size nn from some unknown distribution with cumulative distribution function F()F(), and let x(1),x(2),…,x(n)x_{(1)}, x_{(2)}, \ldots, x_{(n)} denote the ordered observations. Depending on the particular formula used for the empirical cdf (see ecdfPlot), the ii’th order statistic is an estimate of the i/(n+1)i/(n+1)’th, (i−0.5)/n(i-0.5)/n’th, etc., quantile. For the moment, assume the ii’th order statistic is an estimate of the i/(n+1)i/(n+1)’th quantile, that is:

F̂[x(i)]=p̂i=in+1(1) \hat{F}[x_{(i)}] = \hat{p}_i = \frac{i}{n+1} \;\;\;\;\;\; (1)

so

x(i)≈F−1(p̂i)(2) x_{(i)} \approx F^{-1}(\hat{p}_i) \;\;\;\;\;\; (2)

If we knew the form of the true cdf FF, then the plot of x(i)x_{(i)} vs. F−1(p̂i)F^{-1}(\hat{p}_i) would form approximately a straight line based on Equation (2) above. A probability plot is a plot of x(i)x_{(i)} vs. F0−1(p̂i)F_0^{-1}(\hat{p}_i), where F0F_0 denotes the cdf associated with the hypothesized distribution. The probability plot should fall roughly on the line y=xy=x if F=F0F=F_0. If FF and F0F_0 merely differ by a shift in location and scale, that is, if F[(x−μ)/σ]=F0(x)F[(x - \mu) / \sigma] = F_0(x), then the plot should fall roughly on the line y=σx+μy = \sigma x + \mu.

The quantity p̂i=i/(n+1)\hat{p}_i = i/(n+1) 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

E{F[x(i)]}=in+1(3) E\{F[x_{(i)}]\} = \frac{i}{n+1} \;\;\;\;\;\; (3)

(Nelson, 1982, pp. 299-300; Stedinger et al., 1993). That is, the ii’th plotting position defined as in Equation (1) is the expected value of the true cdf evaluated at the ii’th order statistic. Many authors and practitioners, however, prefer to use a plotting position that satisfies:

F−1(p̂i)=E[x(i)](4) F^{-1}(\hat{p}_i) = E[x_{(i)}] \;\;\;\;\;\; (4)

or one that satisfies

F−1(p̂i)=M[x(i)]=F−1{M[u(i)]}(5) F^{-1}(\hat{p}_i) = M[x_{(i)}] = F^{-1}\{M[u_{(i)}]\} \;\;\;\;\;\; (5)

where M[x(i)]M[x_{(i)}] denotes the median of the distribution of the ii’th order statistic, and u(i)u_{(i)} denotes the ii’th order statistic in a random sample of nnuniform (0,1) random variates.

The plotting positions in Equation (4) are often approximated since the expected value of the ii’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 F0F_0. 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:

p̂i=i−an−2a+1(6) \hat{p}_i = \frac{i - a}{n - 2a + 1} \;\;\;\;\;\; (6)

where 0≤a≤10 \le a \le 1 (D’Agostino, 1986a, p.25; Stedinger et al., 1993). The quantity aa 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 x_=x1,x2,…,xn\underline{x} = x_1, x_2, \ldots, x_n denote the observations in a random sample of size nn from some unknown distribution with cumulative distribution function F()F(), and let x(1),x(2),…,x(n)x_{(1)}, x_{(2)}, \ldots, x_{(n)} denote the ordered observations. Similarly, let y_=y1,y2,…,ym\underline{y} = y_1, y_2, \ldots, y_m denote the observations in a random sample of size mm from some unknown distribution with cumulative distribution function G()G(), and let y(1),y(2),…,y(m)y_{(1)}, y_{(2)}, \ldots, y_{(m)} denote the ordered observations. Suppose we are interested in investigating whether the shape of the distribution with cdf FF is the same as the shape of the distribution with cdf GG (e.g., FF and GG may both be normal distributions but differ in mean and standard deviation).

When n=mn = m, we can visually explore this question by plotting y(i)y_{(i)} vs. x(i)x_{(i)}, for i=1,2,…,ni = 1, 2, \ldots, n. The values in y_\underline{y} 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 x_\underline{x} are spread out in a certain way. If the values in x_\underline{x} and y_\underline{y} are spread out in the same way, then the plot of y(i)y_{(i)} vs. x(i)x_{(i)} will be approximately a straight line. If the cdf FF is exactly the same as the cdf GG, then the plot of y(i)y_{(i)} vs. x(i)x_{(i)} will fall roughly on the straight line y=xy = x. If FF and GG differ by a shift in location and scale, that is, if F[(x−μ)/σ]=G(x)F[(x-\mu)/\sigma] = G(x), then the plot will fall roughly on the line y=σx+μy = \sigma x + \mu.

When n>mn > m, a slight adjustment has to be made to produce the plot. Let p̂1,p̂2,…,p̂m\hat{p}_1, \hat{p}_2, \ldots, \hat{p}_m denote the plotting positions corresponding to the mm empirical quantiles for the yy’s and let p̂1*,p̂2*,…,p̂n*\hat{p}^*_1, \hat{p}^*_2, \ldots, \hat{p}^*_n denote the plotting positions corresponding the nn empirical quantiles for the xx’s. Then we plot y(j)y_{(j)} vs. x(j)*x^*_{(j)} for j=1,2,…,mj = 1, 2, \ldots, m where

x(j)*=(1−r)x(i)+rx(i+1)(7) x^*_{(j)} = (1 - r) x_{(i)} + r x_{(i+1)} \;\;\;\;\;\; (7)

r=p̂j−p̂i*p̂i+1*−p̂i*(8) r = \frac{\hat{p}_j - \hat{p}^*_i}{\hat{p}^*_{i+1} - \hat{p}^*_i} \;\;\;\;\;\; (8)

p̂i*≤p̂j≤p̂i+1*(9) \hat{p}^*_i \le \hat{p}_j \le \hat{p}^*_{i+1} \;\;\;\;\;\; (9)

That is, the values for the x(j)*x^*_{(j)}’s are determined by linear interpolation based on the values of the plotting positions for x_\underline{x} and y_\underline{y}.

A similar adjustment is made when n<mn < m.

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.

gofTest

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 XX denote a random variable with cumulative distribution function (cdf) FF. Suppose we want to test the null hypothesis that FF is the cdf of a normal (Gaussian) distribution with some arbitrary mean μ\mu and standard deviation σ\sigma against the alternative hypothesis that FF is the cdf of some other distribution. The table below shows the random variable for which FF is the assumed cdf, given the value of the argument distribution.

    Value of

     

    Random Variable for

    distribution

    Distribution Name

    which FFis the cdf

    “norm”

    Normal

    XX

    “lnorm”

    Lognormal (Log-space)

    log(X)log(X)

    “lnormAlt”

    Lognormal (Untransformed)

    log(X)log(X)

    “lnorm3”

    Three-Parameter Lognormal

    log(X−γ)log(X-\gamma)

    “zmnorm”

    Zero-Modified Normal

    X|X>0X | X > 0

    “zmlnorm”

    Zero-Modified Lognormal (Log-space)

    log(X)|X>0log(X) | X > 0

    “zmlnormAlt”

    Zero-Modified Lognormal (Untransformed)

    log(X)|X>0log(X) | X > 0

    Note that for the three-parameter lognormal distribution, the symbol γ\gamma denotes the threshold parameter.

    Let x_=(x1,x2,…,xn)\underline{x} = (x_1, x_2, \ldots, x_n) denote the vector of nnordered 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 FF is the cdf of a normal distribution:

    W=(∑i=1naixi)2∑i=1n(xi−x‾)2(1) W = \frac{(\sum_{i=1}^n a_i x_i)^2}{\sum_{i=1}^n (x_i - \bar{x})^2} \;\;\;\;\;\; (1)

    where the quantity aia_i is the ii’th element of the vector a_\underline{a} defined by:

    a_=m_TV−1[m_TV−1V−1m_]1/2(2) \underline{a} = \frac{\underline{m}^T V^{-1}}{[\underline{m}^T V^{-1} V^{-1} \underline{m}]^{1/2}} \;\;\;\;\;\; (2)

    where TT denotes the transpose operator, and m_\underline{m} is the vector of expected values and VV is the variance-covariance matrix of the order statistics of a random sample of size nn from a standard normal distribution. That is, the values of a_\underline{a} are the expected values of the standard normal order statistics weighted by their variance-covariance matrix, and normalized so that

    a_Ta_=1(3) \underline{a}^T \underline{a} = 1 \;\;\;\;\;\; (3)

    It can be shown that the coefficients a_\underline{a} are antisymmetric, that is,

    ai=−an−i+1(4) a_i = -a_{n-i+1} \;\;\;\;\;\; (4)

    and for odd nn,

    a(n+1)/2=0(5) a_{(n+1)/2} = 0 \;\;\;\;\;\; (5)

    Now because

    a‾=1n∑i=1nai=0(6) \bar{a} = \frac{1}{n} \sum_{i=1}^n a_i = 0 \;\;\;\;\;\ (6)

    and

    ∑i=1n(ai−a‾)2=∑i=1nai2=a_Ta_=1(7) \sum_{i=1}^n (a_i - \bar{a})^2 = \sum_{i=1}^n a_i^2 = \underline{a}^T \underline{a} = 1 \;\;\;\;\;\; (7)

    the WW-statistic in Equation (1) is the same as the square of the sample product-moment correlation between the vectors a_\underline{a} and x_\underline{x}:

    W=r(a_,x_)2(8) W = r(\underline{a}, \underline{x})^2 \;\;\;\;\;\; (8)

    where

    r(x_,y_)=∑i=1n(xi−x‾)(yi−y‾)[∑i=1n(xi−x‾)2∑i=1n(yi−y‾)2]1/2(9) r(\underline{x}, \underline{y}) = \frac{\sum_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})}{[\sum_{i=1}^n (x_i - \bar{x})^2 \sum_{i=1}^n (y_i - \bar{y})^2]^{1/2}} \;\;\;\;\;\;\; (9)

    (see the R help file for cor).

    The Shapiro-Wilk WW-statistic is also simply the ratio of two estimators of variance, and can be rewritten as

    W=σ̂BLUE2σ̂MVUE2(10) W = \frac{\hat{\sigma}_{BLUE}^2}{\hat{\sigma}_{MVUE}^2} \;\;\;\;\;\; (10)

    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:

    σ̂BLUE=∑i=1naixin−1(11) \hat{\sigma}_{BLUE} = \frac{\sum_{i=1}^n a_i x_i}{\sqrt{n-1}} \;\;\;\;\;\; (11)

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

    Small values of WW indicate the null hypothesis is probably not true. Shapiro and Wilk (1965) computed the values of the coefficients a_\underline{a} and the percentage points for WW (based on smoothing the empirical null distribution of WW) for sample sizes up to 50. Computation of the WW-statistic for larger sample sizes can be cumbersome, since computation of the coefficients a_\underline{a} requires storage of at least n+[n(n+1)/2]n + [n(n+1)/2] reals followed by n×nn \times n matrix inversion (Royston, 1992a).

    The Shapiro-Francia W’-Statistic
    Shapiro and Francia (1972) introduced a modification of the WW-test that depends only on the expected values of the order statistics (m_\underline{m}) and not on the variance-covariance matrix (VV):

    W′=(∑i=1nbixi)2∑i=1n(xi−x‾)2(13) W' = \frac{(\sum_{i=1}^n b_i x_i)^2}{\sum_{i=1}^n (x_i - \bar{x})^2} \;\;\;\;\;\; (13)

    where the quantity bib_i is the ii’th element of the vector b_\underline{b} defined by:

    b_=m_[m_Tm_]1/2(14) \underline{b} = \frac{\underline{m}}{[\underline{m}^T \underline{m}]^{1/2}} \;\;\;\;\;\; (14)

    Several authors, including Ryan and Joiner (1973), Filliben (1975), and Weisberg and Bingham (1975), note that the W′W'-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 x_\underline{x} and the expected normal order statistics m_\underline{m}:

    W′=r(b_,x_)2=r(m_,x_)2(15) W' = r(\underline{b}, \underline{x})^2 = r(\underline{m}, \underline{x})^2 \;\;\;\;\;\; (15)

    Shapiro and Francia (1972) present a table of empirical percentage points for W′W' based on a Monte Carlo simulation. It can be shown that the asymptotic null distributions of WW and W′W' 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 W′W'-statistic that is easier to compute. They suggested using Blom scores (Blom, 1958, pp.68–75) to approximate the element of m_\underline{m}:

    W̃′=(∑i=1ncixi)2∑i=1n(xi−x‾)2(16) \tilde{W}' = \frac{(\sum_{i=1}^n c_i x_i)^2}{\sum_{i=1}^n (x_i - \bar{x})^2} \;\;\;\;\;\; (16)

    where the quantity cic_i is the ii’th element of the vector c_\underline{c} defined by:

    c_=m̃_[m̃_Tm̃_]1/2(17) \underline{c} = \frac{\underline{\tilde{m}}}{[\underline{\tilde{m}}^T \underline{\tilde{m}}]^{1/2}} \;\;\;\;\;\; (17)

    and

    m̃i=Φ−1[i−(3/8)n+(1/4)](18) \tilde{m}_i = \Phi^{-1}[\frac{i - (3/8)}{n + (1/4)}] \;\;\;\;\;\; (18)

    and Φ\Phi denotes the standard normal cdf. That is, the values of the elements of m_\underline{m} 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 a_\underline{a} necessary to compute the Shapiro-Wilk WW-statistic, and also a transformation of the WW-statistic that has approximately a standard normal distribution under the null hypothesis.

    Noting that, up to a constant, the components of b_\underline{b} in Equation (14) and c_\underline{c} in Equation (17) differ from those of a_\underline{a} in Equation (2) mainly in the first and last two components, Royston (1992a) used the approximation c_\underline{c} as the basis for approximating a_\underline{a} using polynomial (quintic) regression analysis. For 4≤n≤10004 \le n \le 1000, the approximation gave the following equations for the last two (and hence first two) components of a_\underline{a}:

    ãn=cn+0.221157y−0.147981y2−2.071190y3+4.434685y4−2.706056y5(19) \tilde{a}_n = c_n + 0.221157 y - 0.147981 y^2 - 2.071190 y^3 + 4.434685 y^4 - 2.706056 y^5 \;\;\;\;\;\; (19)

    ãn−1=cn−1+0.042981y−0.293762y2−1.752461y3+5.682633y4−3.582633y5(20) \tilde{a}_{n-1} = c_{n-1} + 0.042981 y - 0.293762 y^2 - 1.752461 y^3 + 5.682633 y^4 - 3.582633 y^5 \;\;\;\;\;\; (20)

    where

    y=n(21) y = \sqrt{n} \;\;\;\;\;\; (21)

    The other components are computed as:

    ãi=m̃iη(22) \tilde{a}_i = \frac{\tilde{m}_i}{\sqrt{\eta}} \;\;\;\;\;\; (22)

    for i=2,…,n−1i = 2, \ldots , n-1 if n≤5n \le 5, or i=3,…,n−2i = 3, \ldots, n-2 if n>5n > 5, where

    η=m̃_Tm̃_−2m̃n21−2ãn2(23) \eta = \frac{\underline{\tilde{m}}^T \underline{\tilde{m}} - 2 \tilde{m}_n^2}{1 - 2 \tilde{a}_n^2} \;\;\;\;\;\; (23)

    if n≤5n \le 5, and

    η=m̃_Tm̃_−2m̃n2−2m̃n−121−2ãn2−2ãn−12(24) \eta = \frac{\underline{\tilde{m}}^T \underline{\tilde{m}} - 2 \tilde{m}_n^2 - 2 \tilde{m}_{n-1}^2}{1 - 2 \tilde{a}_n^2 - 2 \tilde{a}_{n-1}^2} \;\;\;\;\;\; (24)

    if n>5n > 5.

    Royston (1992a) found his approximation to a_\underline{a} to be accurate to at least ±1\pm 1 in the third decimal place over all values of ii and selected values of nn, and also found that critical percentage points of WW 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 WW, Royston (1992a) approximated the distribution of (1−W)(1-W) by a three-parameter lognormal distribution for 4≤n≤114 \le n \le 11, and the upper half of the distribution of (1−W)(1-W) by a two-parameter lognormal distribution for 12≤n≤200012 \le n \le 2000. Setting

    z=w−μσ(25) z = \frac{w - \mu}{\sigma} \;\;\;\;\;\; (25)

    the p-value associated with WW is given by:

    p=1−Φ(z)(26) p = 1 - \Phi(z) \;\;\;\;\;\; (26)

    For 4≤n≤114 \le n \le 11, the quantities necessary to compute zz are given by:

    w=−log[γ−log(1−W)](27) w = -log[\gamma - log(1 - W)] \;\;\;\;\;\; (27)

    γ=−2.273+0.459n(28) \gamma = -2.273 + 0.459 n \;\;\;\;\;\; (28)

    μ=0.5440−0.39978n+0.025054n2−0.000671n3(29) \mu = 0.5440 - 0.39978 n + 0.025054 n^2 - 0.000671 n^3 \;\;\;\;\;\; (29)

    σ=exp(1.3822−0.77857n+0.062767n2−0.0020322n3)(30) \sigma = exp(1.3822 - 0.77857 n + 0.062767 n^2 - 0.0020322 n^3) \;\;\;\;\;\; (30)

    For 12≤n≤200012 \le n \le 2000, the quantities necessary to compute zz are given by:

    w=log(1−W)(31) w = log(1 - W) \;\;\;\;\;\; (31)

    γ=log(n)(32) \gamma = log(n) \;\;\;\;\;\; (32)

    μ=−1.5861−0.31082y−0.083751y2+0.00038915y3(33) \mu = -1.5861 - 0.31082 y - 0.083751 y^2 + 0.00038915 y^3 \;\;\;\;\;\; (33)

    σ=exp(−0.4803−0.082676y+0.0030302y2)(34) \sigma = exp(-0.4803 - 0.082676 y + 0.0030302 y^2) \;\;\;\;\;\; (34)

    For the last approximation when 12≤n≤200012 \le n \le 2000, Royston (1992a) claims this approximation is actually valid for sample sizes up to n=5000n = 5000.

    Modification for the Three-Parameter Lognormal Distribution
    When distribution="lnorm3", the function gofTest assumes the vector x_\underline{x} 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 log(x−γ̂)log(x-\hat{\gamma}) where γ̂\hat{\gamma} 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:

    z′=z−μzσz(35) z' = \frac{z - \mu_z}{\sigma_z} \;\;\;\;\;\; (35)

    where for 5≤n≤115 \le n \le 11,

    μz=−3.8267+2.8242u−0.63673u2−0.020815v(36) \mu_z = -3.8267 + 2.8242 u - 0.63673 u^2 - 0.020815 v \;\;\;\;\;\; (36)

    σz=−4.9914+8.6724u−4.27905u2+0.70350u3−0.013431v(37) \sigma_z = -4.9914 + 8.6724 u - 4.27905 u^2 + 0.70350 u^3 - 0.013431 v \;\;\;\;\;\; (37)

    and for 12≤n≤200012 \le n \le 2000,

    μz=−3.7796+2.4038u−0.6675u2−0.082863u3−0.0037935u4−0.027027v−0.0019887vu(38) \mu_z = -3.7796 + 2.4038 u - 0.6675 u^2 - 0.082863 u^3 - 0.0037935 u^4 - 0.027027 v - 0.0019887 vu \;\;\;\;\;\; (38)

    σz=2.1924−1.0957u+0.33737u2−0.043201u3+0.0019974u4−0.0053312vu(39) \sigma_z = 2.1924 - 1.0957 u + 0.33737 u^2 - 0.043201 u^3 + 0.0019974 u^4 - 0.0053312 vu \;\;\;\;\;\; (39)

    where

    u=log(n)(40) u = log(n) \;\;\;\;\;\; (40)

    v=u(σ̂−σ̂2)(41) v = u (\hat{\sigma} - \hat{\sigma}^2) \;\;\;\;\;\; (41)

    σ̂2=1n−1∑i=1n(yi−y‾)2(42) \hat{\sigma}^2 = \frac{1}{n-1} \sum_{i=1}^n (y_i - \bar{y})^2 \;\;\;\;\;\; (42)

    yi=log(xi−γ̂)(43) y_i = log(x_i - \hat{\gamma}) \;\;\;\;\;\; (43)

    and γ\gamma denotes the threshold parameter. The p-value associated with this test is then given by:

    p=1−Φ(z′)(44) p = 1 - \Phi(z') \;\;\;\;\;\; (44)

    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:

    1. Let x_=x1,x2,…,xn\underline{x} = x_1, x_2, \ldots, x_n denote the vector of nnordered observations. Compute cumulative probabilities for each xix_i based on the cumulative distribution function for the hypothesized distribution. That is, compute pi=F(xi,θ̂)p_i = F(x_i, \hat{\theta}) where F(x,θ)F(x, \theta) denotes the hypothesized cumulative distribution function with parameter(s) θ\theta, and θ̂\hat{\theta} denotes the estimated parameter(s).
    2. Compute standard normal deviates based on the computed cumulative probabilities:
      yi=Φ−1(pi)y_i = \Phi^{-1}(p_i)
    3. Perform the Shapiro-Wilk goodness-of-fit test on the yiy_i’s.
  • 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 W̃′\tilde{W}'). Royston (1992c) presents an algorithm to transform the W̃′\tilde{W}'-statistic so that its null distribution is approximately a standard normal. For 5≤n≤50005 \le n \le 5000, Royston (1992c) approximates the distribution of (1−W̃′)(1-\tilde{W}') by a lognormal distribution. Setting

    z=w−μσ(45) z = \frac{w-\mu}{\sigma} \;\;\;\;\;\; (45)

    the p-value associated with W̃′\tilde{W}' is given by:

    p=1−Φ(z)(46) p = 1 - \Phi(z) \;\;\;\;\;\; (46)

    The quantities necessary to compute zz are given by:

    w=log(1−W̃′)(47) w = log(1 - \tilde{W}') \;\;\;\;\;\; (47)

    ν=log(n)(48) \nu = log(n) \;\;\;\;\;\; (48)

    u=log(ν)−ν(49) u = log(\nu) - \nu \;\;\;\;\;\; (49)

    μ=−1.2725+1.0521u(50) \mu = -1.2725 + 1.0521 u \;\;\;\;\;\; (50)

    v=log(ν)+2ν(51) v = log(\nu) + \frac{2}{\nu} \;\;\;\;\;\; (51)

    σ=1.0308−0.26758v(52) \sigma = 1.0308 - 0.26758 v \;\;\;\;\;\; (52)

    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:

    1. Let x_=x1,x2,…,xn\underline{x} = x_1, x_2, \ldots, x_n denote the vector of nnordered observations. Compute cumulative probabilities for each xix_i based on the cumulative distribution function for the hypothesized distribution. That is, compute pi=F(xi,θ̂)p_i = F(x_i, \hat{\theta}) where F(x,θ)F(x, \theta) denotes the hypothesized cumulative distribution function with parameter(s) θ\theta, and θ̂\hat{\theta} denotes the estimated parameter(s).
    2. Compute standard normal deviates based on the computed cumulative probabilities:
      yi=Φ−1(pi)y_i = \Phi^{-1}(p_i)
    3. Perform the Shapiro-Francia goodness-of-fit test on the yiy_i’s.
  • 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 rr from a normal probability plot to perform a goodness-of-fit test for normality, and he provided a table of critical values for rr 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 rr based on Blom plotting positions.

    The function gofTest computes the PPCC test statistic rr 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:

    A=−n−1n∑i=1n[2i−1][ln(p(i))+ln(1−p(n−i+1))] A = -n - \frac{1}{n} \sum_{i=1}^n [2i - 1][ln(p_{(i)}) + ln(1 - p_{(n-i+1)})]

    where p(i)=Φ([x(i)−x‾]/s)p_{(i)} = \Phi([x_{(i)} - \bar{x}]/s). Here, Φ\Phi is the cumulative distribution function of the standard normal distribution, and x‾\bar{x} and ss are mean and standard deviation of the data values. The p-value is computed from the modified statistic Z=A(1.0+0.75/n+2.25/n2)Z = A (1.0 + 0.75/n + 2.25/n^2) according to Table 4.9 in Stephens (1986a)(1986a).

  • 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:

    W=112n+∑i=1n(p(i)−2i−12n)2 W = \frac{1}{12n} + \sum_{i=1}^n \left(p_{(i)} - \frac{2i-1}{2n}\right)^2

    where p(i)=Φ([x(i)−x‾]/s)p_{(i)} = \Phi([x_{(i)} - \bar{x}]/s). Here, Φ\Phi is the cumulative distribution function of the standard normal distribution, and x‾\bar{x} and ss are mean and standard deviation of the data values. The p-value is computed from the modified statistic Z=W(1.0+0.75/n)Z = W (1.0 + 0.75/n) according to Table 4.9 in Stephens (1986a)(1986a).

  • 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 D=max{D+,D−}D = max\{D^+, D^-\} with

    D+=maxi=1,…,n{i/n−p(i)},D−=maxi=1,…,n{p(i)−(i−1)/n} D^+ = \max_{i = 1, \ldots, n} \{i/n - p_{(i)}\}, \;\; D^- = \max_{i = 1, \ldots, n} \{p_{(i)} - (i-1)/n\}

    where p(i)=Φ([x(i)−x‾]/s)p_{(i)} = \Phi([x_{(i)} - \bar{x}]/s). Here, Φ\Phi is the cumulative distribution function of the standard normal distribution, and x‾\bar{x} and ss 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 Z=D(n−0.01+0.85/n)Z = D (\sqrt{n} - 0.01 + 0.85/\sqrt{n}), 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:

    H0:β1=0(53) H_0: \sqrt{\beta}_1 = 0 \;\;\;\;\;\; (53)

    where

    β1=μ3μ23/2(54) \sqrt{\beta}_1 = \frac{\mu_3}{\mu_2^{3/2}} \;\;\;\;\;\; (54)

    and the quantity μr\mu_r denotes the rr’th moment about the mean (also called the rr’th central moment). The quantity β1\sqrt{\beta_1} is called the coefficient of skewness, and is estimated by:

    b1=m3m23/2(55) \sqrt{b}_1 = \frac{m_3}{m_2^{3/2}} \;\;\;\;\;\; (55)

    where

    mr=1n∑i=1n(xi−x‾)r(56) m_r = \frac{1}{n} \sum_{i=1}^n (x_i - \bar{x})^r \;\;\;\;\;\; (56)

    denotes the rr’th sample central moment.

    The possible alternative hypotheses are:

    Ha:β1≠0(57) H_a: \sqrt{\beta}_1 \ne 0 \;\;\;\;\;\; (57)

    Ha:β1<0(58) H_a: \sqrt{\beta}_1 < 0 \;\;\;\;\;\; (58)

    Ha:β1>0(59) H_a: \sqrt{\beta}_1 > 0 \;\;\;\;\;\; (59)

    which correspond to alternative="two-sided", alternative="less", and
    alternative="greater", respectively.

    To test the null hypothesis of zero skew, D’Agostino (1970) derived an approximation to the distribution of b1\sqrt{b_1} 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 ZZ shown below is assumed to follow a standard normal distribution and is used to compute the p-value associated with the test of H0H_0:

    Z=δlog{Yα+[(Yα)2+1]1/2}(60) Z = \delta \;\; log\{ \frac{Y}{\alpha} + [(\frac{Y}{\alpha})^2 + 1]^{1/2} \} \;\;\;\;\;\; (60)

    where

    Y=b1[(n+1)(n+3)6(n−2)]1/2(61) Y = \sqrt{b_1} [\frac{(n+1)(n+3)}{6(n-2)}]^{1/2} \;\;\;\;\;\; (61)

    β2=3(n2+27n−70)(n+1)(n+3)(n−2)(n+5)(n+7)(n+9)(62) \beta_2 = \frac{3(n^2 + 27n - 70)(n+1)(n+3)}{(n-2)(n+5)(n+7)(n+9)} \;\;\;\;\;\; (62)

    W2=−1+2β2−2(63) W^2 = -1 + \sqrt{2\beta_2 - 2} \;\;\;\;\;\; (63)

    δ=1/log(W)(64) \delta = 1 / \sqrt{log(W)} \;\;\;\;\;\; (64)

    α=[2/(W2−1)]1/2(65) \alpha = [2 / (W^2 - 1)]^{1/2} \;\;\;\;\;\; (65)

    When the sample size nn is at least 150, a simpler approximation may be used in which YY 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 m−1m-1 where mm 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 m−1−km-1-k, where kk 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 m−1m-1 and m−1−km-1-k. Therefore, especially when the sample size is small, it is important to compare the test statistic to the chi-squared distribution with both m−1m-1 and m−1−km-1-k 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 0,10, 1 Distribution (test="ws").

    Wilk and Shapiro (1968) suggested this test in the context of jointly testing several independent samples for normality simultaneously. If p1,p2,…,pnp_1, p_2, \ldots, p_n denote the p-values associated with the test for normality of nn independent samples, then under the null hypothesis that all nn samples come from a normal distribution, the p-values are a random sample of nn observations from a Uniform 0,10,1 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 0,10, 1 distribution:

    • Test Based on Normal Scores. Under the null hypothesis, the normal scores

      Φ−1(p1),Φ−1(p2),…,Φ−1(pn) \Phi^{-1}(p_1), \Phi^{-1}(p_2), \ldots, \Phi^{-1}(p_n)

      are a random sample of nn observations from a standard normal distribution. Wilk and Shapiro (1968) denote the ii’th normal score by

      Gi=Φ−1(pi)(66) G_i = \Phi^{-1}(p_i) \;\;\;\;\;\; (66)

      and note that under the null hypothesis, the quantity GG defined as

      G=1n∑1nGi(67) G = \frac{1}{\sqrt{n}} \, \sum^n_{1}{G_i} \;\;\;\;\;\; (67)

      has a standard normal distribution. Wilk and Shapiro (1968) were interested in the alternative hypothesis that some of the nn 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 0,10, 1 distribution (alternative="greater"). In terms of the test statistic GG, this alternative hypothesis would tend to make GG smaller than expected, so the p-value is given by Φ(G)\Phi(G). For the one-sided lower alternative that the cdf for the distribution of p-values is less than the cdf for a Uniform 0,10, 1 distribution, the p-value is given by

      p=1−Φ(G)(68) p = 1 - \Phi(G) \;\;\;\;\;\; (68)

      .

    • Test Based on Chi-Square Scores. Under the null hypothesis, the chi-square scores

      −2log(p1),−2log(p2),…,−2log(pn) -2 \, log(p_1), -2 \, log(p_2), \ldots, -2 \, log(p_n)

      are a random sample of nn observations from a chi-square distribution with 2 degrees of freedom (Fisher, 1950). Wilk and Shapiro (1968) denote the ii’th chi-square score by

      Ci=−2log(pi)(69) C_i = -2 \, log(p_i) \;\;\;\;\;\; (69)

      and note that under the null hypothesis, the quantity CC defined as

      C=∑1nCi(70) C = \sum^n_{1}{C_i} \;\;\;\;\;\; (70)

      has a chi-square distribution with 2n2n degrees of freedom. Wilk and Shapiro (1968) were interested in the alternative hypothesis that some of the nn 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 0,10, 1 distribution (alternative="greater"). In terms of the test statistic CC, this alternative hypothesis would tend to make CC larger than expected, so the p-value is given by

      p=1−F2n(C)(71) p = 1 - F_{2n}(C) \;\;\;\;\;\; (71)

      where F2nF_2n denotes the cumulative distribution function of the chi-square distribution with 2n2n 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 0,10, 1 distribution, the p-value is given by

      p=F2n(C)(72) p = F_{2n}(C) \;\;\;\;\;\; (72)

ppointsCensored

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:

  • Product-limit method of Kaplan and Meier (1958) (prob.method="kaplan-meier").
  • Hazard plotting method of Nelson (1972) (prob.method="nelson").
  • Generalization of the product-limit method due to Michael and Schucany (1986)
    (prob.method="michael-schucany") (the default).
  • Generalization of the product-limit method due to Hirsch and Stedinger (1987)
    (prob.method="hirsch-stedinger").

Let x_\underline{x} denote a random sample of NN observations from some distribution. Assume nn (0<n<N0 < n < N) of these observations are known and cc (c=N−nc=N-n) of these observations are all censored below (left-censored) or all censored above (right-censored) at kk fixed censoring levels

T1,T2,…,TK;K≥1(1) T_1, T_2, \ldots, T_K; \; K \ge 1 \;\;\;\;\;\; (1)

For the case when K≥2K \ge 2, the data are said to be Type I multiply censored. For the case when K=1K=1, set T=T1T = T_1. If the data are left-censored and all nn known observations are greater than or equal to TT, or if the data are right-censored and all nn known observations are less than or equal to TT, 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 cjc_j denote the number of observations censored below or above censoring level TjT_j for j=1,2,…,Kj = 1, 2, \ldots, K, so that

∑i=1Kcj=c(2) \sum_{i=1}^K c_j = c \;\;\;\;\;\; (2)

Let x(1),x(2),…,x(N)x_{(1)}, x_{(2)}, \ldots, x_{(N)} 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 x(i)x_{(i)} does not necessarily represent the ii’th “largest” observation from the (unknown) complete sample.

Finally, let Ω\Omega (omega) denote the set of nn 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 ii’th ordered observation is given by (D’Agostino, 1986a, p.8):

F̂[x(i)]=p̂i=#[xj≤x(i)]n(3) \hat{F}[x_{(i)}] = \hat{p}_i = \frac{\#[x_j \le x_{(i)}]}{n} \;\;\;\;\;\; (3)

where #[xj≤x(i)]\#[x_j \le x_{(i)}] denotes the number of observations less than or equal to x(i)x_{(i)} (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 S(t)S(t) denote the survival function evaluated at tt, that is:

S(t)=1−F(t)=Pr(X>t)(4) S(t) = 1 - F(t) = Pr(X > t) \;\;\;\;\;\; (4)

Kaplan and Meier (1958) show that a nonparametric estimate of the survival function at the ii’th ordered observation that is not censored (i.e., i∈Ωi \in \Omega), is given by:

Ŝ[x(i)]\hat{S}[x_{(i)}] == Pr̂[X>x(i)]\widehat{Pr}[X > x_{(i)}]
  == Pr̂[X>x(1)]\widehat{Pr}[X > x_{(1)}]
    Pr̂[X>x(2)|X>x(1)]⋯\;\; \widehat{Pr}[X > x_{(2)} | X > x_{(1)}] \;\; \cdots
    Pr̂[X>x(i)|X>x(i−1)]\;\; \widehat{Pr}[X > x_{(i)} | X > x_{(i-1)}]
  == ∏j∈Ω,j≤inj−djnj,i∈Ω(5)\prod_{j \in \Omega, j \le i} \frac{n_j - d_j}{n_j}, \;\; i \in \Omega \;\;\;\;\; (5)

where njn_j is the number of observations (uncensored or censored) with values greater than or equal to x(j)x_{(j)}, and djd_j denotes the number of uncensored observations exactly equal to x(j)x_{(j)} (if there are no tied uncensored observations then djd_j will equal 1 for all values of jj). (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 ii’th ordered observation that is not censored (i.e., i∈Ωi \in \Omega), is given by:

p̂i=F̂[x(i)]=1−∏j∈Ω,j≤inj−djnj(6) \hat{p}_i = \hat{F}[x_{(i)}] = 1 - \prod_{j \in \Omega, j \le i} \frac{n_j - d_j}{n_j} \;\;\;\;\;\; (6)

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:

3,≥4,≥4,5,5,6 3, \ge4, \ge4, 5, 5, 6

The table below shows how the plotting positions are computed.

ii x(i)x_{(i)} nin_i did_i ni−dini\frac{n_i-d_i}{n_i} Plotting Position
1 33 66 11 5/65/6 1−(5/6)=0.1671 - (5/6) = 0.167
2 ≥4\ge4        
3 ≥4\ge4        
4 55 33 22 1/31/3 1−(5/6)(1/3)=0.7221 - (5/6)(1/3) = 0.722
5 55       0.7220.722
6 66 11 11 0/10/1 1−(5/6)(1/3)(0/1)=11 - (5/6)(1/3)(0/1) = 1

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 ii’th ordered observation, assuming it is not censored, is computed as:

p̂i=F̂[x(i)]=∏j∈Ω,j>inj−djnj(7) \hat{p}_i = \hat{F}[x_{(i)}] = \prod_{j \in \Omega, j > i} \frac{n_j - d_j}{n_j} \;\;\;\;\;\; (7)

where njn_j is the number of observations (uncensored or censored) with values less than or equal to x(j)x_{(j)}, and djd_j denotes the number of uncensored observations exactly equal to x(j)x_{(j)} (if there are no tied uncensored observations then djd_j will equal 1 for all values of jj). The plotting position is equal to 1 for the largest uncensored order statistic.

As an example, consider the following left-censored data set:

3,<4,<4,5,5,6 3, <4, <4, 5, 5, 6

The table below shows how the plotting positions are computed.

ii x(i)x_{(i)} nin_i did_i ni−dini\frac{n_i-d_i}{n_i} Plotting Position
1 33 11 11 0/10/1 1(5/6)(3/5)=0.51(5/6)(3/5) = 0.5
2 <4<4        
3 <4<4        
4 55 55 22 3/53/5 0.8330.833
5 55       1(5/6)=0.8331(5/6) = 0.833
6 66 66 11 5/65/6 11

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: (N−0.375)/(N+0.25)(N - 0.375)/(N + 0.25). 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:

Ŝ[x(i)]=∏j∈Ω,j≤iN−jN−j+1,i∈Ω(8) \hat{S}[x_{(i)}] = \prod_{j \in \Omega, j \le i} \frac{N-j}{N-j+1}, \;\; i \in \Omega \;\;\;\;\;\; (8)

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):

p̂i=F̂[x(i)]=1−∏j∈Ω,j≤iexp(−1N−j+1)(9) \hat{p}_i = \hat{F}[x_{(i)}] = 1 - \prod_{j \in \Omega, j \le i} exp(\frac{-1}{N-j+1}) \;\;\;\;\;\; (9)

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 100100’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:

F̂[x(i)]=p̂i=i−aN−2a+1(10) \hat{F}[x_{(i)}] = \hat{p}_i = \frac{i - a}{N - 2a + 1} \;\;\;\;\;\; (10)

where 0≤a≤10 \le a \le 1 (Cleveland, 1993, p. 18; D’Agostino, 1986a, pp. 8,25). The value of aa 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:

p̂i=1−N−a+1N−2a+1∏j∈Ω,j≤iN−j−a+1N−j−a+2i∈Ω(11) \hat{p}_i = 1 - \frac{N-a+1}{N-2a+1} \prod_{j \in \Omega, j \le i} \frac{N-j-a+1}{N-j-a+2} \;\; i \in \Omega \;\;\;\;\;\; (11)

Note that the plotting positions proposed by Herd (1960) and Johnson (1964) are a special case of Equation (11) with a=0a=0. 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:

p̂i=N−a+1N−2a+1∏j∈Ω,j≥ij−aj−a+1i∈Ω(12) \hat{p}_i = \frac{N-a+1}{N-2a+1} \prod_{j \in \Omega, j \ge i} \frac{j-a}{j-a+1} \;\; i \in \Omega \;\;\;\;\;\; (12)

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 jj’th censoring level (j=0,1,…,Kj = 0, 1, \ldots, K), write the value of the survival function as:

S(Tj)S(T_j) == Pr[X>Tj]Pr[X > T_j]
  == Pr[X>Tj+1]+Pr[Tj<X≤Tj+1]Pr[X > T_{j+1}] + Pr[T_j < X \le T_{j+1}]
  == S(Tj+1)+Pr[Tj<X≤Tj+1|X>Tj]Pr[X>Tj]S(T_{j+1}) + Pr[T_j < X \le T_{j+1} | X > T_j] Pr[X > T_j]
  == S(Tj+1)+Pr[Tj<X≤Tj+1|X>Tj]S(Tj)(13)S(T_{j+1}) + Pr[T_j < X \le T_{j+1} | X > T_j] S(T_j) \;\;\;\;\;\; (13)

where

T0=−∞,(14) T_0 = -\infty, \;\;\;\;\;\; (14)

TK+1=∞(15) T_{K+1} = \infty \;\;\;\;\;\; (15)

Now set

AjA_j == # uncensored observations in (Tj,Tj+1](16)(T_j, T_{j+1}] \;\;\;\;\;\; (16)
BjB_j == # observations in (Tj+1,∞)(17)(T_{j+1}, \infty) \;\;\;\;\;\; (17)

for j=0,1,…,Kj = 0, 1, \ldots, K. Then the method of moments estimator of the conditional probability in Equation (13) is given by:

Pr̂[Tj<X≤Tj+1|X>Tj]=AjAj+Bj(18) \widehat{Pr}[T_j < X \le T_{j+1} | X > T_j] = \frac{A_j}{A_j + B_j} \;\;\;\;\;\; (18)

Hence, by equations (13) and (18) we have

Ŝ(Tj)=Ŝ(Tj+1)+(AjAj+Bj)Ŝ(Tj)(19) \hat{S}(T_j) = \hat{S}(T_{j+1}) + (\frac{A_j}{A_j + B_j}) \hat{S}(T_{j}) \;\;\;\;\;\; (19)

which can be rewritten as:

Ŝ(Tj+1)=Ŝ(Tj)[1−(AjAj+Bj)](20) \hat{S}(T_{j+1}) = \hat{S}(T_j) [1 - (\frac{A_j}{A_j + B_j})] \;\;\;\;\;\; (20)

Equation (20) can be solved interatively for j=1,2,…,Kj = 1, 2, \ldots, K. Note that

Ŝ(T0)=Ŝ(−∞)=S(−∞)=1(21) \hat{S}(T_0) = \hat{S}(-\infty) = S(-\infty) = 1 \;\;\;\;\;\; (21)

Ŝ(TK+1)=Ŝ(∞)=S(∞)=0(22) \hat{S}(T_{K+1}) = \hat{S}(\infty) = S(\infty) = 0 \;\;\;\;\;\; (22)

Once the values of the survival function at the censoring levels are computed, the plotting positions for the AjA_j uncensored observations in the interval (TJ,Tj+1](T_J, T_{j+1}] (j=0,1,…,Kj = 0, 1, \ldots, K) are computed as

p̂i=[1−Ŝ(Tj)]+[Ŝ(Tj)−Ŝ(Tj+1)]r−aAj−2a+1(23) \hat{p}_i = [1 - \hat{S}(T_j)] + [\hat{S}(T_j) - \hat{S}(T_{j+1})] \frac{r-a}{A_j - 2a + 1} \;\;\;\;\;\; (23)

where aa denotes the plotting position constant, 0≤a≤10 \le a \le 1, and rr denotes the rank of the ii’th observation among the AjA_j uncensored observations in the interval (TJ,Tj+1](T_J, T_{j+1}]. (Tied observations are given distinct ranks.)

For the cjc_j observations censored at censoring level TjT_j (j=1,2,…,Kj = 1, 2, \ldots, K), the plotting positions are computed as:

p̂i=1−[Ŝ(Tj)r−acj−2a+1](24) \hat{p}_i = 1 - [\hat{S}(T_j) \frac{r-a}{c_j - 2a + 1}] \;\;\;\;\;\; (24)

where rr denotes the rank of the ii’th observation among the cjc_j observations censored at censoring level TjT_j. 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:

S*(t)=Pr[X≥t](25) S^*(t) = Pr[X \ge t] \;\;\;\;\;\; (25)

For continuous distributions, the functions in Equations (4) and (25) are identical.

Hirsch and Stedinger (1987) show that for the jj’th censoring level (j=0,1,…,Kj = 0, 1, \ldots, K), the value of the survival function can be written as:

S(Tj)S(T_j) == Pr[X≥Tj]Pr[X \ge T_j]
  == Pr[X≥Tj+1]+Pr[Tj≤X<Tj+1]Pr[X \ge T_{j+1}] + Pr[T_j \le X < T_{j+1}]
  == S*(Tj+1)+Pr[Tj≤X<Tj+1|X<Tj+1]Pr[X<Tj+1]S^*(T_{j+1}) + Pr[T_j \le X < T_{j+1} | X < T_{j+1}] Pr[X < T_{j+1}]
  == S*(Tj+1)+Pr[Tj≤X<Tj+1|X<Tj][1−S*(Tj)](26)S^*(T_{j+1}) + Pr[T_j \le X < T_{j+1} | X < T_j] [1 - S^*(T_j)] \;\;\;\;\;\; (26)

where T0T_0 and TK+1T_{K+1} are defined in Equations (14) and (15).

Now set

AjA_j == # uncensored observations in [Tj,Tj+1)(27)[T_j, T_{j+1}) \;\;\;\;\;\; (27)
BjB_j == # observations in (−∞,Tj)(28)(-\infty, T_j) \;\;\;\;\;\; (28)

for j=0,1,…,Kj = 0, 1, \ldots, K. Then the method of moments estimator of the conditional probability in Equation (26) is given by:

Pr[Tj≤X<Tj+1|X<Tj+1]=AjAj+Bj(29) Pr[T_j \le X < T_{j+1} | X < T_{j+1}] = \frac{A_j}{A_j + B_j} \;\;\;\;\;\; (29)

Hence, by Equations (26) and (29) we have

Ŝ(Tj)=Ŝ(Tj+1)+(AjAj+Bj)Ŝ(Tj)(30) \hat{S}(T_j) = \hat{S}(T_{j+1}) + (\frac{A_j}{A_j + B_j}) \hat{S}(T_{j}) \;\;\;\;\;\; (30)

which can be solved interatively for j=1,2,…,Kj = 1, 2, \ldots, K. Note that

S*̂(TK+1)=S*̂(∞)=S*(∞)=0(31) \widehat{S^*}(T_{K+1}) = \widehat{S^*}(\infty) = S^*(\infty) = 0 \;\;\;\;\;\; (31)

S*̂(T0)=S*̂(−∞)=S*(−∞)=1(32) \widehat{S^*}(T_0) = \widehat{S^*}(-\infty) = S^*(-\infty) = 1 \;\;\;\;\;\; (32)

Once the values of the survival function at the censoring levels are computed, the plotting positions for the AjA_j uncensored observations in the interval [TJ,Tj+1)[T_J, T_{j+1}) (j=0,1,…,Kj = 0, 1, \ldots, K) are computed as

p̂i=[1−S*̂(Tj)]+[S*̂(Tj)−S*̂(Tj+1)]r−aAj−2a+1(33) \hat{p}_i = [1 - \widehat{S^*}(T_j)] + [\widehat{S^*}(T_j) - \widehat{S^*}(T_{j+1})] \frac{r-a}{A_j - 2a + 1} \;\;\;\;\;\; (33)

where aa denotes the plotting position constant, 0≤a≤0.50 \le a \le 0.5, and rr denotes the rank of the ii’th observation among the AjA_j uncensored observations in the interval [TJ,Tj+1)[T_J, T_{j+1}). (Tied observations are given distinct ranks.)

For the cjc_j observations censored at censoring level TjT_j (j=1,2,…,Kj = 1, 2, \ldots, K), the plotting positions are computed as:

p̂i=[1−S*̂(Tj)]r−acj−2a+1(34) \hat{p}_i = [1 - \widehat{S^*}(T_j)] \frac{r-a}{c_j - 2a + 1} \;\;\;\;\;\; (34)

where rr denotes the rank of the ii’th observation among the cjc_j observations censored at censoring level TjT_j. 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.

gofTestCensored

Help topic: gofTestCensored.

Let x_=c(x1,x2,…,xN)\underline{x} = c(x_1, x_2, \ldots, x_N) denote a vector of NN observations from from some distribution with cdf FF. Suppose we want to test the null hypothesis that FF is the cdf of a normal (Gaussian) distribution with some arbitrary mean μ\mu and standard deviation σ\sigma against the alternative hypothesis that FF is the cdf of some other distribution. The table below shows the random variable for which FF is the assumed cdf, given the value of the argument distribution.

Value of   Random Variable for
distribution Distribution Name which FFis the cdf
“norm” Normal XX
“lnorm” Lognormal (Log-space) log(X)log(X)
“lnormAlt” Lognormal (Untransformed) log(X)log(X)

Assume nn (0<n<N0 < n < N) of these observations are known and cc (c=N−nc=N-n) of these observations are all censored below (left-censored) or all censored above (right-censored) at kk fixed censoring levels

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

For the case when k≥2k \ge 2, the data are said to be Type I multiply censored. For the case when k=1k=1, set T=T1T = T_1. If the data are left-censored and all nn known observations are greater than or equal to TT, or if the data are right-censored and all nn known observations are less than or equal to TT, 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 cjc_j denote the number of observations censored below or above censoring level TjT_j for j=1,2,…,kj = 1, 2, \ldots, k, so that

∑i=1kcj=c(2) \sum_{i=1}^k c_j = c \;\;\;\;\;\; (2)

Let x(1),x(2),…,x(N)x_{(1)}, x_{(2)}, \ldots, x_{(N)} 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 x(i)x_{(i)} does not necessarily represent the ii’th “largest” observation from the (unknown) complete sample.

Note that for singly left-censored data:

x(1)=x(2)=⋯=x(c)=T(3) x_{(1)} = x_{(2)} = \cdots = x_{(c)} = T \;\;\;\;\;\; (3)

and for singly right-censored data:

x(n+1)=x(n+2)=⋯=x(N)=T(4) x_{(n+1)} = x_{(n+2)} = \cdots = x_{(N)} = T \;\;\;\;\;\; (4)

Finally, let Ω\Omega (omega) denote the set of nn 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 x_\underline{x}, the Shapiro-Wilk WW-statistic is the same as the square of the sample product-moment correlation between the vectors a_\underline{a} and x_\underline{x}:

W=r(a_,x_)2(5) W = r(\underline{a}, \underline{x})^2 \;\;\;\;\;\; (5)

where

r(x_,y_)=∑i=1N(xi−x‾)(yi−y‾)[∑i=1n(xi−x‾)2∑i=1n(yi−y‾)2]1/2(6) r(\underline{x}, \underline{y}) = \frac{\sum_{i=1}^N (x_i - \bar{x})(y_i - \bar{y})}{[\sum_{i=1}^n (x_i - \bar{x})^2 \sum_{i=1}^n (y_i - \bar{y})^2]^{1/2}} \;\;\;\;\;\;\; (6)

and a_\underline{a} is defined by:

a_=m_TV−1[m_TV−1V−1m_]1/2(7) \underline{a} = \frac{\underline{m}^T V^{-1}}{[\underline{m}^T V^{-1} V^{-1} \underline{m}]^{1/2}} \;\;\;\;\;\; (7)

where T^T denotes the transpose operator, and m_\underline{m} is the vector of expected values and VV is the variance-covariance matrix of the order statistics of a random sample of size NN from a standard normal distribution. That is, the values of a_\underline{a} are the expected values of the standard normal order statistics weighted by their variance-covariance matrix, and normalized so that

a_Ta_=1(8) \underline{a}^T \underline{a} = 1 \;\;\;\;\;\; (8)

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 WW-statistic to:

W=r(a_Δ,x_Δ)2(9) W = r(\underline{a}_{\Delta}, \underline{x}_{\Delta})^2 \;\;\;\;\;\; (9)

where for left singly-censored data:

a_Δ=(ac+1,ac+2,…,aN)(10) \underline{a}_{\Delta} = (a_{c+1}, a_{c+2}, \ldots, a_{N}) \;\;\;\;\;\; (10)

x_Δ=(x(c+1),x(c+2),…,x(N))(11) \underline{x}_{\Delta} = (x_{(c+1)}, x_{(c+2)}, \ldots, x_{(N)}) \;\;\;\;\;\; (11)

and for right singly-censored data:

a_Δ=(a1,a2,…,an)(12) \underline{a}_{\Delta} = (a_1, a_2, \ldots, a_n) \;\;\;\;\;\; (12)

x_Δ=(x(1),x(2),…,x(n))(13) \underline{x}_{\Delta} = (x_{(1)}, x_{(2)}, \ldots, x_{(n)}) \;\;\;\;\;\; (13)

Just like the function gofTest, when test="sw", the function gofTestCensored uses Royston’s (1992a) approximation for the coefficients a_\underline{a} (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 WW-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 WW-statistic. (The distribution of this z-statistic is assumed to be normal, but not necessarily a standard normal.) Denote these percentiles by Z0.90Z_{0.90}, Z0.95Z_{0.95}, and Z0.99Z_{0.99}. The true mean and standard deviation of the z-statistic are estimated by the intercept and slope, respectively, from the linear regression of ZαZ_{\alpha} on Φ−1(α)\Phi^{-1}(\alpha) for α\alpha = 0.9, 0.95, and 0.99, where Φ\Phi denotes the cumulative distribution function of the standard normal distribution. The p-value associated with this test is then computed as:

p=1−Φ(z−μzσz)(14) p = 1 - \Phi(\frac{z - \mu_z}{\sigma_z}) \;\;\;\;\;\; (14)

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:

  1. Let x_=x1,x2,…,xn\underline{x} = x_1, x_2, \ldots, x_n denote the vector of nnordered observations, ignoring censoring status. Compute cumulative probabilities for each xix_i based on the cumulative distribution function for the hypothesized distribution. That is, compute pi=F(xi,θ̂)p_i = F(x_i, \hat{\theta}), where F(x,θ)F(x, \theta) denotes the hypothesized cumulative distribution function with parameter(s) θ\theta, and θ̂\hat{\theta} denotes the estimated parameter(s) using an estimation method that accounts for censoring (e.g., assuming a Gamma distribution with alternative parameterization, call the function linkegammaAltCensored).
  2. Compute standard normal deviates based on the computed cumulative probabilities:
    yi=Φ−1(pi)y_i = \Phi^{-1}(p_i)
  3. Perform the Shapiro-Wilk goodness-of-fit test (that accounts for censoring) on the yiy_i’s.

Shapiro-Francia Goodness-of-Fit Test (test="sf")
Equation (15) in the section on gofTest shows that for the complete ordered data x_\underline{x}, the Shapiro-Francia W′W'-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 W′W'-statistic to the case of singly censored data:

W̃′=r(c_Δ,x_Δ)2(14) \tilde{W}' = r(\underline{c}_{\Delta}, \underline{x}_{\Delta})^2 \;\;\;\;\;\; (14)

where for left singly-censored data:

c_Δ=(cc+1,cc+2,…,cN)(15) \underline{c}_{\Delta} = (c_{c+1}, c_{c+2}, \ldots, c_{N}) \;\;\;\;\;\; (15)

x_Δ=(x(c+1),x(c+2),…,x(N))(16) \underline{x}_{\Delta} = (x_{(c+1)}, x_{(c+2)}, \ldots, x_{(N)}) \;\;\;\;\;\; (16)

and for right singly-censored data:

a_Δ=(a1,a2,…,an)(17) \underline{a}_{\Delta} = (a_1, a_2, \ldots, a_n) \;\;\;\;\;\; (17)

x_Δ=(x(1),x(2),…,x(n))(18) \underline{x}_{\Delta} = (x_{(1)}, x_{(2)}, \ldots, x_{(n)}) \;\;\;\;\;\; (18)

and c_\underline{c} is defined as:

c_=m̃_[m̃_′m̃_]1/2(19) \underline{c} = \frac{\underline{\tilde{m}}}{[\underline{\tilde{m}}' \underline{\tilde{m}}]^{1/2}} \;\;\;\;\;\; (19)

where

m̃i=Φ−1(i−(3/8)n+(1/4))(20) \tilde{m}_i = \Phi^{-1}(\frac{i - (3/8)}{n + (1/4)}) \;\;\;\;\;\; (20)

and Φ\Phi denotes the standard normal cdf. Note: Do not confuse the elements of the vector c_\underline{c} with the scalar cc which denotes the number of censored observations. We use c_\underline{c} 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 c_\underline{c} (see the section on gofTest).

In general, the Shapiro-Francia test statistic can be extended to multiply censored data using Equation (14) with c_Δ\underline{c}_{\Delta} defined as the orderd values of cic_i associated with uncensored observations, and x_Δ\underline{x}_{\Delta} defined as the ordered values of xix_i associated with uncensored observations:

c_Δ=∪i∈Ωc(i)(21) \underline{c}_{\Delta} = \cup_{i \in \Omega} \;\; c_{(i)} \;\;\;\;\;\; (21)

x_Δ=∪i∈Ωx(i)(22) \underline{x}_{\Delta} = \cup_{i \in \Omega} \;\; x_{(i)} \;\;\;\;\;\; (22)

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 W̃′\tilde{W}'-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 W̃′\tilde{W}'-statistic. (The distribution of this z-statistic is assumed to be normal, but not necessarily a standard normal.) Denote these percentiles by Z0.90Z_{0.90}, Z0.95Z_{0.95}, and Z0.99Z_{0.99}. The true mean and standard deviation of the z-statistic are estimated by the intercept and slope, respectively, from the linear regression of ZαZ_{\alpha} on Φ−1(α)\Phi^{-1}(\alpha) for α\alpha = 0.9, 0.95, and 0.99, where Φ\Phi denotes the cumulative distribution function of the standard normal distribution. The p-value associated with this test is then computed as:

p=1−Φ(z−μzσz)(23) p = 1 - \Phi(\frac{z - \mu_z}{\sigma_z}) \;\;\;\;\;\; (23)

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:

  1. Let x_=x1,x2,…,xn\underline{x} = x_1, x_2, \ldots, x_n denote the vector of nnordered observations, ignoring censoring status. Compute cumulative probabilities for each xix_i based on the cumulative distribution function for the hypothesized distribution. That is, compute pi=F(xi,θ̂)p_i = F(x_i, \hat{\theta}) where F(x,θ)F(x, \theta) denotes the hypothesized cumulative distribution function with parameter(s) θ\theta, and θ̂\hat{\theta} denotes the estimated parameter(s) using an estimation method that accounts for censoring (e.g., assuming a Gamma distribution with alternative parameterization, call the function linkegammaAltCensored).
  2. Compute standard normal deviates based on the computed cumulative probabilities:
    yi=Φ−1(pi)y_i = \Phi^{-1}(p_i)
  3. Perform the Shapiro-Francia goodness-of-fit test (that accounts for censoring) on the yiy_i’s.

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 W′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.

boxcoxCensored

Help topic: boxcoxCensored.

Two common assumptions for several standard parametric hypothesis tests are:

  1. The observations all come from a normal distribution.
  2. The observations all come from distributions with the same variance.

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 XX from some distribution with only positive values, the Box-Cox family of power transformations is defined as:

YY = Xλ−1λ\frac{X^\lambda - 1}{\lambda} λ≠0\lambda \ne 0
    log(X)log(X) λ=0(1)\lambda = 0 \;\;\;\;\;\; (1)

where YY is assumed to come from a normal distribution. This transformation is continuous in λ\lambda. 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 λ\lambda based on maximizing the likelihood function. Alternatively, an appropriate value of λ\lambda 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 λ\lambda specified in the argument lambda. The starting value for the optimization is always λ=1\lambda=1 (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 x_\underline{x} denote a random sample of NN observations from some continuous distribution. Assume nn (0<n<N0 < n < N) of these observations are known and cc (c=N−nc=N-n) of these observations are all censored below (left-censored) or all censored above (right-censored) at kk fixed censoring levels

T1,T2,…,TK;K≥1(2) T_1, T_2, \ldots, T_K; \; K \ge 1 \;\;\;\;\;\; (2)

For the case when K≥2K \ge 2, the data are said to be Type I multiply censored. For the case when K=1K=1, set T=T1T = T_1. If the data are left-censored and all nn known observations are greater than or equal to TT, or if the data are right-censored and all nn known observations are less than or equal to TT, 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 cjc_j denote the number of observations censored below or above censoring level TjT_j for j=1,2,…,Kj = 1, 2, \ldots, K, so that

∑i=1Kcj=c(3) \sum_{i=1}^K c_j = c \;\;\;\;\;\; (3)

Let x(1),x(2),…,x(N)x_{(1)}, x_{(2)}, \ldots, x_{(N)} 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 x(i)x_{(i)} does not necessarily represent the ii’th “largest” observation from the (unknown) complete sample.

Finally, let Ω\Omega (omega) denote the set of nn subscripts in the “ordered” sample that correspond to uncensored observations, and let Ωj\Omega_j denote the set of cjc_j subscripts in the “ordered” sample that correspond to the censored observations censored at censoring level TjT_j for j=1,2,…,kj = 1, 2, \ldots, k.

We assume that there exists some value of λ\lambda such that the transformed observations

yiy_i = xiλ−1λ\frac{x_i^\lambda - 1}{\lambda} λ≠0\lambda \ne 0
    log(xi)log(x_i) λ=0(4)\lambda = 0 \;\;\;\;\;\; (4)

(i=1,2,…,ni = 1, 2, \ldots, n) form a random sample of Type I censored data from a normal distribution.

Note that for the censored observations, Equation (4) becomes:

y(i)=Tj*y_{(i)} = T_j^* = Tjλ−1λ\frac{T_j^\lambda - 1}{\lambda} λ≠0\lambda \ne 0
    log(Tj)log(T_j) λ=0(5)\lambda = 0 \;\;\;\;\;\; (5)

where i∈Ωji \in \Omega_j.

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 μ\mu and standard deviation σ\sigma, 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:

log[L(λ,μ,σ)]=log[(Nc1c2…ckn)]+∑j=1kcjlog[F(Tj*)]+∑i∈Ωlog{f[y(i)]}+(λ−1)∑i∈Ωlog[x(i)](6) log[L(\lambda, \mu, \sigma)] = log[{N \choose c_1 c_2 \ldots c_k n}] + \sum_{j=1}^k c_j log[F(T_j^*)] + \sum_{i \in \Omega} log\{f[y_{(i)}]\} + (\lambda - 1) \sum_{i \in \Omega} log[x_{(i)}] \;\;\;\;\;\; (6)

where ff and FF denote the probability density function (pdf) and cumulative distribution function (cdf) of the population. That is,

f(t)=ϕ(t−μσ)(7) f(t) = \phi(\frac{t-\mu}{\sigma}) \;\;\;\;\;\; (7)

F(t)=Φ(t−μσ)(8) F(t) = \Phi(\frac{t-\mu}{\sigma}) \;\;\;\;\;\; (8)

where ϕ\phi and Φ\Phi denote the pdf and cdf of the standard normal distribution, respectively (Shumway et al., 1989). For left singly censored data, Equation (6) simplifies to:

log[L(λ,μ,σ)]=log[(Nc)]+clog[F(T*)]+∑i=c+1Nlog{f[y(i)]}+(λ−1)∑i=c+1Nlog[x(i)](9) log[L(\lambda, \mu, \sigma)] = log[{N \choose c}] + c log[F(T^*)] + \sum_{i = c+1}^N log\{f[y_{(i)}]\} + (\lambda - 1) \sum_{i = c+1}^N log[x_{(i)}] \;\;\;\;\;\; (9)

Similarly, for Type I right censored data, the likelihood function is given by:

log[L(λ,μ,σ)]=log[(Nc1c2…ckn)]+∑j=1kcjlog[1−F(Tj*)]+∑i∈Ωlog{f[y(i)]}+(λ−1)∑i∈Ωlog[x(i)](10) log[L(\lambda, \mu, \sigma)] = log[{N \choose c_1 c_2 \ldots c_k n}] + \sum_{j=1}^k c_j log[1 - F(T_j^*)] + \sum_{i \in \Omega} log\{f[y_{(i)}]\} + (\lambda - 1) \sum_{i \in \Omega} log[x_{(i)}] \;\;\;\;\;\; (10)

and for right singly censored data this simplifies to:

log[L(λ,μ,σ)]=log[(Nc)]+clog[1−F(T*)]+∑i=1nlog{f[y(i)]}+(λ−1)∑i=1nlog[x(i)](11) log[L(\lambda, \mu, \sigma)] = log[{N \choose c}] + c log[1 - F(T^*)] + \sum_{i = 1}^n log\{f[y_{(i)}]\} + (\lambda - 1) \sum_{i = 1}^n log[x_{(i)}] \;\;\;\;\;\; (11)

For a fixed value of λ\lambda, the log-likelihood function is maximized by replacing μ\mu and σ\sigma 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 λ\lambda using the MLEs for μ\mu and σ\sigma. When optimize=FALSE, the value of the objective is computed by using Equation (6) or (10), using the values of λ\lambda specified in the argument lambda, and using the MLEs of μ\mu and σ\sigma.