Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/gofTestCensored.R
Perform a goodnessoffit test to determine whether a data set appears to come from a normal distribution, lognormal distribution, or lognormal distribution (alternative parameterization) based on a sample of data that has been subjected to Type I or Type II censoring.
1 2 3 4  gofTestCensored(x, censored, censoring.side = "left", test = "sf",
distribution = "norm", est.arg.list = NULL,
prob.method = "hirschstedinger", plot.pos.con = 0.375,
keep.data = TRUE, data.name = NULL, censoring.name = NULL)

x 
numeric vector of observations.
Missing ( 
censored 
numeric or logical vector indicating which values of 
censoring.side 
character string indicating on which side the censoring occurs. The possible
values are 
test 
character string defining which goodnessoffit test to perform. Possible values are:
The ShapiroWilk test is only available for singly censored data. See the DETAILS section for more information. 
distribution 
a character string denoting the abbreviation of the assumed distribution.
Only continous distributions are allowed. See the help file for
The results for the goodnessoffit test are
identical for Also, the results for the goodnessoffit test are
identical for 
est.arg.list 
a list of arguments to be passed to the function estimating the distribution
parameters. For example, if 
prob.method 
character string indicating what method to use to compute the plotting positions
(empirical probabilities) when The 
plot.pos.con 
numeric scalar between 0 and 1 containing the value of the plotting position
constant to use when 
keep.data 
logical scalar indicating whether to return the original data. The
default value is 
data.name 
optional character string indicating the name for the data used for argument 
censoring.name 
optional character string indicating the name for the data used for argument 
Let \underline{x} = c(x_1, x_2, …, x_N) denote a vector of N
observations from from some distribution with cdf F.
Suppose we want to test the null hypothesis that
F is the cdf of a normal (Gaussian) distribution with
some arbitrary mean μ and standard deviation σ against the
alternative hypothesis that F is the cdf of some other distribution. The
table below shows the random variable for which F is the assumed cdf, given
the value of the argument distribution
.
Value of  Random Variable for  
distribution  Distribution Name  which F is the cdf 
"norm"  Normal  X 
"lnorm"  Lognormal (Logspace)  log(X) 
"lnormAlt"  Lognormal (Untransformed)  log(X) 
Assume n (0 < n < N) of these observations are known and c (c=Nn) of these observations are all censored below (leftcensored) or all censored above (rightcensored) at k fixed censoring levels
T_1, T_2, …, T_k; \; k ≥ 1 \;\;\;\;\;\; (1)
For the case when k ≥ 2, the data are said to be Type I multiply censored. For the case when k=1, set T = T_1. If the data are leftcensored and all n known observations are greater than or equal to T, or if the data are rightcensored and all n known observations are less than or equal to T, 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 c_j denote the number of observations censored below or above censoring level T_j for j = 1, 2, …, k, so that
∑_{i=1}^k c_j = c \;\;\;\;\;\; (2)
Let x_{(1)}, x_{(2)}, …, 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 rightcensored data, if a censored observation has the same value as an uncensored one, the uncensored observation should be placed first. For leftcensored 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)} does not necessarily represent the i'th “largest” observation from the (unknown) complete sample.
Note that for singly leftcensored data:
x_{(1)} = x_{(2)} = \cdots = x_{(c)} = T \;\;\;\;\;\; (3)
and for singly rightcensored data:
x_{(n+1)} = x_{(n+2)} = \cdots = x_{(N)} = T \;\;\;\;\;\; (4)
Finally, let Ω (omega) denote the set of n subscripts in the
“ordered” sample that correspond to uncensored observations.
ShapiroWilk GoodnessofFit Test for Singly Censored Data (test="sw"
)
Equation (8) in the help file for gofTest
shows that for the case of
complete ordered data \underline{x}, the ShapiroWilk
Wstatistic is the same as
the square of the sample productmoment correlation between the vectors
\underline{a} and \underline{x}:
W = r(\underline{a}, \underline{x})^2 \;\;\;\;\;\; (5)
where
r(\underline{x}, \underline{y}) = \frac{∑_{i=1}^N (x_i  \bar{x})(y_i  \bar{y})}{[∑_{i=1}^n (x_i  \bar{x})^2 ∑_{i=1}^n (y_i  \bar{y})^2]^{1/2}} \;\;\;\;\;\;\; (6)
and \underline{a} is defined by:
\underline{a} = \frac{\underline{m}^T V^{1}}{[\underline{m}^T V^{1} V^{1} \underline{m}]^{1/2}} \;\;\;\;\;\; (7)
where ^T denotes the transpose operator, and \underline{m} is the vector of expected values and V is the variancecovariance matrix of the order statistics of a random sample of size N from a standard normal distribution. That is, the values of \underline{a} are the expected values of the standard normal order statistics weighted by their variancecovariance matrix, and normalized so that
\underline{a}^T \underline{a} = 1 \;\;\;\;\;\; (8)
Computing ShapiroWilk WStatistic 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 ShapiroWilk
Wstatistic to:
W = r(\underline{a}_{Δ}, \underline{x}_{Δ})^2 \;\;\;\;\;\; (9)
where for left singlycensored data:
\underline{a}_{Δ} = (a_{c+1}, a_{c+2}, …, a_{N}) \;\;\;\;\;\; (10)
\underline{x}_{Δ} = (x_{(c+1)}, x_{(c+2)}, …, x_{(N)}) \;\;\;\;\;\; (11)
and for right singlycensored data:
\underline{a}_{Δ} = (a_1, a_2, …, a_n) \;\;\;\;\;\; (12)
\underline{x}_{Δ} = (x_{(1)}, x_{(2)}, …, x_{(n)}) \;\;\;\;\;\; (13)
Just like the function gofTest
,
when test="sw"
, the function gofTestCensored
uses Royston's (1992a)
approximation for the coefficients \underline{a} (see the help file for
gofTest
).
Computing PValues for the ShapiroWilk 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 Wstatistic 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 zstatistic computed from the Wstatistic. (The distribution of this zstatistic is assumed to be normal, but not necessarily a standard normal.) Denote these percentiles by Z_{0.90}, Z_{0.95}, and Z_{0.99}. The true mean and standard deviation of the zstatistic are estimated by the intercept and slope, respectively, from the linear regression of Z_{α} on Φ^{1}(α) for α = 0.9, 0.95, and 0.99, where Φ denotes the cumulative distribution function of the standard normal distribution. The pvalue associated with this test is then computed as:
p = 1  Φ(\frac{z  μ_z}{σ_z}) \;\;\;\;\;\; (14)
Note: Verrill and Johnson (1988) produced their tables based on Type II censoring.
Royston's (1993) approximation to the pvalue of these tests, however, should be
fairly accurate for Type I censored data as well.
Testing GoodnessofFit for Any Continuous Distribution
The function gofTestCensored
extends the ShapiroWilk test that
accounts for censoring to test for goodnessoffit for any continuous
distribution by using the idea of Chen and Balakrishnan (1995),
who proposed a general purpose approximate goodnessoffit test based on
the Cramervon Mises or AndersonDarling goodnessoffit 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 ShapiroWilk test that accounts for censoring:
Let \underline{x} = x_1, x_2, …, x_n denote the vector of
n ordered observations, ignoring censoring status.
Compute cumulative probabilities for each x_i based on the
cumulative distribution function for the hypothesized distribution. That is,
compute p_i = F(x_i, \hat{θ}), where F(x, θ) denotes the
hypothesized cumulative distribution function with parameter(s) θ,
and \hat{θ} 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
link{egammaAltCensored}
).
Compute standard normal deviates based on the computed cumulative
probabilities:
y_i = Φ^{1}(p_i)
Perform the ShapiroWilk goodnessoffit test (that accounts for censoring) on the y_i's.
ShapiroFrancia GoodnessofFit Test (test="sf"
)
Equation (15) in the help file for gofTest
shows that for the complete
ordered data \underline{x}, the ShapiroFrancia W'statistic is the
same as the squared Pearson correlation coefficient associated with a normal
probability plot.
Computing ShapiroFrancia 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
WeisbergBingham Approximation to the W'statistic to the case of singly
censored data:
\tilde{W}' = r(\underline{c}_{Δ}, \underline{x}_{Δ})^2 \;\;\;\;\;\; (14)
where for left singlycensored data:
\underline{c}_{Δ} = (c_{c+1}, c_{c+2}, …, c_{N}) \;\;\;\;\;\; (15)
\underline{x}_{Δ} = (x_{(c+1)}, x_{(c+2)}, …, x_{(N)}) \;\;\;\;\;\; (16)
and for right singlycensored data:
\underline{a}_{Δ} = (a_1, a_2, …, a_n) \;\;\;\;\;\; (17)
\underline{x}_{Δ} = (x_{(1)}, x_{(2)}, …, x_{(n)}) \;\;\;\;\;\; (18)
and \underline{c} is defined as:
\underline{c} = \frac{\underline{\tilde{m}}}{[\underline{\tilde{m}}' \underline{\tilde{m}}]^{1/2}} \;\;\;\;\;\; (19)
where
\tilde{m}_i = Φ^{1}(\frac{i  (3/8)}{n + (1/4)}) \;\;\;\;\;\; (20)
and Φ denotes the standard normal cdf. Note: Do not confuse the elements
of the vector \underline{c} with the scalar c which denotes the number
of censored observations. We use \underline{c} here to be consistent with the
notation in the help file for gofTest
.
Just like the function gofTest
,
when test="sf"
, the function gofTestCensored
uses Royston's (1992a)
approximation for the coefficients \underline{c} (see the help file for
gofTest
).
In general, the ShapiroFrancia test statistic can be extended to multiply censored data using Equation (14) with \underline{c}_{Δ} defined as the orderd values of c_i associated with uncensored observations, and \underline{x}_{Δ} defined as the ordered values of x_i associated with uncensored observations:
\underline{c}_{Δ} = \cup_{i \in Ω} \;\; c_{(i)} \;\;\;\;\;\; (21)
\underline{x}_{Δ} = \cup_{i \in Ω} \;\; 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 PValues for the ShapiroFrancia 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 \tilde{W}'statistic shown
in Equation (14) above for several sample sizes and percentages of censoring.
As for the ShapiroWilk 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 zstatistic computed from the \tilde{W}'statistic. (The distribution of this zstatistic is assumed to be normal, but not necessarily a standard normal.) Denote these percentiles by Z_{0.90}, Z_{0.95}, and Z_{0.99}. The true mean and standard deviation of the zstatistic are estimated by the intercept and slope, respectively, from the linear regression of Z_{α} on Φ^{1}(α) for α = 0.9, 0.95, and 0.99, where Φ denotes the cumulative distribution function of the standard normal distribution. The pvalue associated with this test is then computed as:
p = 1  Φ(\frac{z  μ_z}{σ_z}) \;\;\;\;\;\; (23)
Note: Verrill and Johnson (1988) produced their tables based on Type II censoring.
Royston's (1993) approximation to the pvalue 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 GoodnessofFit for Any Continuous Distribution
The function gofTestCensored
extends the ShapiroFrancia test that
accounts for censoring to test for goodnessoffit for any continuous
distribution by using the idea of Chen and Balakrishnan (1995),
who proposed a general purpose approximate goodnessoffit test based on
the Cramervon Mises or AndersonDarling goodnessoffit 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 ShapiroFrancia test that accounts for censoring:
Let \underline{x} = x_1, x_2, …, x_n denote the vector of
n ordered observations, ignoring censoring status.
Compute cumulative probabilities for each x_i based on the
cumulative distribution function for the hypothesized distribution. That is,
compute p_i = F(x_i, \hat{θ}) where F(x, θ) denotes the
hypothesized cumulative distribution function with parameter(s) θ,
and \hat{θ} 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
link{egammaAltCensored}
).
Compute standard normal deviates based on the computed cumulative
probabilities:
y_i = Φ^{1}(p_i)
Perform the ShapiroFrancia goodnessoffit test (that accounts for censoring) on the y_i's.
Probability Plot Correlation Coefficient (PPCC) GoodnessofFit 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 WeisbergBingham Approximation to the ShapiroFrancia W'test
(Weisberg and Bingham, 1975; Royston, 1993). Thus the PPCC goodnessoffit test
is equivalent to the ShapiroFrancia goodnessoffit test.
a list of class "gofCensored"
containing the results of the goodnessoffit
test. See the help files for gofCensored.object
for details.
The ShapiroWilk test (Shapiro and Wilk, 1965) and the ShapiroFrancia test (Shapiro and Francia, 1972) are probably the two most commonly used hypothesis tests to test departures from normality. The ShapiroWilk test is most powerful at detecting shorttailed (platykurtic) and skewed distributions, and least powerful against symmetric, moderately longtailed (leptokurtic) distributions. Conversely, the ShapiroFrancia test is more powerful against symmetric longtailed distributions and less powerful against shorttailed distributions (Royston, 1992b; 1993).
In practice, almost any goodnessoffit test will not reject the null hypothesis
if the number of observations is relatively small. Conversely, almost any goodnessoffit
test will reject the null hypothesis if the number of observations is very large,
since “real” data are never distributed according to any theoretical distribution
(Conover, 1980, p.367). For most cases, however, the distribution of “real” data
is close enough to some theoretical distribution that fairly accurate results may be
provided by assuming that particular theoretical distribution. One way to asses the
goodness of the fit is to use goodnessoffit tests. Another way is to look at
quantilequantile (QQ) plots (see qqPlotCensored
).
Steven P. Millard ([email protected])
Birnbaum, Z.W., and F.H. Tingey. (1951). OneSided Confidence Contours for Probability Distribution Functions. Annals of Mathematical Statistics 22, 592596.
Blom, G. (1958). Statistical Estimates and Transformed Beta Variables. John Wiley and Sons, New York.
Conover, W.J. (1980). Practical Nonparametric Statistics. Second Edition. John Wiley and Sons, New York.
Dallal, G.E., and L. Wilkinson. (1986). An Analytic Approximation to the Distribution of Lilliefor's Test for Normality. The American Statistician 40, 294296.
D'Agostino, R.B. (1970). Transformation to Normality of the Null Distribution of g1. Biometrika 57, 679681.
D'Agostino, R.B. (1971). An Omnibus Test of Normality for Moderate and Large Size Samples. Biometrika 58, 341348.
D'Agostino, R.B. (1986b). Tests for the Normal Distribution. In: D'Agostino, R.B., and M.A. Stephens, eds. Goodnessof Fit Techniques. Marcel Dekker, New York.
D'Agostino, R.B., and E.S. Pearson (1973). Tests for Departures from Normality. Empirical Results for the Distributions of b2 and √{b1}. Biometrika 60(3), 613622.
D'Agostino, R.B., and G.L. Tietjen (1973). Approaches to the Null Distribution of √{b1}. Biometrika 60(1), 169173.
Fisher, R.A. (1950). Statistical Methods for Research Workers. 11'th Edition. Hafner Publishing Company, New York, pp.99100.
Gibbons, R.D., D.K. Bhaumik, and S. Aryal. (2009). Statistical Methods for Groundwater Monitoring, Second Edition. John Wiley & Sons, Hoboken.
Kendall, M.G., and A. Stuart. (1991). The Advanced Theory of Statistics, Volume 2: Inference and Relationship. Fifth Edition. Oxford University Press, New York.
Royston, J.P. (1992a). Approximating the ShapiroWilk WTest for NonNormality. Statistics and Computing 2, 117119.
Royston, J.P. (1992b). Estimation, Reference Ranges and Goodness of Fit for the ThreeParameter LogNormal Distribution. Statistics in Medicine 11, 897912.
Royston, J.P. (1992c). A PocketCalculator Algorithm for the ShapiroFrancia Test of NonNormality: An Application to Medicine. Statistics in Medicine 12, 181184.
Royston, P. (1993). A Toolkit for Testing for NonNormality in Complete and Censored Samples. The Statistician 42, 3743.
Ryan, T., and B. Joiner. (1973). Normal Probability Plots and Tests for Normality. Technical Report, Pennsylvannia State University, Department of Statistics.
Shapiro, S.S., and R.S. Francia. (1972). An Approximate Analysis of Variance Test for Normality. Journal of the American Statistical Association 67(337), 215219.
Shapiro, S.S., and M.B. Wilk. (1965). An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591611.
Verrill, S., and R.A. Johnson. (1987). The Asymptotic Equivalence of Some Modified ShapiroWilk Statistics – Complete and Censored Sample Cases. The Annals of Statistics 15(1), 413419.
Verrill, S., and R.A. Johnson. (1988). Tables and LargeSample Distribution Theory for CensoredData Correlation Statistics for Testing Normality. Journal of the American Statistical Association 83, 11921197.
Weisberg, S., and C. Bingham. (1975). An Approximate Analysis of Variance Test for NonNormality Suitable for Machine Calculation. Technometrics 17, 133134.
gofTest
, gofCensored.object
,
print.gofCensored
, plot.gofCensored
,
shapiro.test
, Normal, Lognormal,
enormCensored
, elnormCensored
,
elnormAltCensored
, qqPlotCensored
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458  # Generate 30 observations from a gamma distribution with
# parameters mean=10 and cv=1 and then censor observations less than 5.
# Then test the hypothesis that these data came from a gamma
# distribution using the ShapiroWilk test.
#
# The pvalue for the complete data is p = 0.86, while
# the pvalue for the censored data is p = 0.52.
# (Note: the call to set.seed lets you reproduce this example.)
set.seed(598)
dat < sort(rgammaAlt(30, mean = 10, cv = 1))
dat
# [1] 0.5313509 1.4741833 1.9936208 2.7980636 3.4509840
# [6] 3.7987348 4.5542952 5.5207531 5.5253596 5.7177872
#[11] 5.7513827 9.1086375 9.8444090 10.6247123 10.9304922
#[16] 11.7925398 13.3432689 13.9562777 14.6029065 15.0563342
#[21] 15.8730642 16.0039936 16.6910715 17.0288922 17.8507891
#[26] 19.1105522 20.2657141 26.3815970 30.2912797 42.8726101
dat.censored < dat
censored < dat.censored < 5
dat.censored[censored] < 5
# Results for complete data:
#
gofTest(dat, test = "sw", dist = "gammaAlt")
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF Based on
# Chen & Balakrisnan (1995)
#
#Hypothesized Distribution: Gamma
#
#Estimated Parameter(s): mean = 12.4248552
# cv = 0.7901752
#
#Estimation Method: MLE
#
#Data: dat
#
#Sample Size: 30
#
#Test Statistic: W = 0.981471
#
#Test Statistic Parameter: n = 30
#
#Pvalue: 0.8631802
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
# Results for censored data:
#
gof.list < gofTestCensored(dat.censored, censored, test = "sw",
distribution = "gammaAlt")
gof.list
#Results of GoodnessofFit Test
#Based on Type I Censored Data
#
#
#Test Method: ShapiroWilk GOF
# (Singly Censored Data)
# Based on Chen & Balakrisnan (1995)
#
#Hypothesized Distribution: Gamma
#
#Censoring Side: left
#
#Censoring Level(s): 5
#
#Estimated Parameter(s): mean = 12.4911448
# cv = 0.7617343
#
#Estimation Method: MLE
#
#Data: dat.censored
#
#Censoring Variable: censored
#
#Sample Size: 30
#
#Percent Censored: 23.3%
#
#Test Statistic: W = 0.9613711
#
#Test Statistic Parameters: N = 30.0000000
# DELTA = 0.2333333
#
#Pvalue: 0.522329
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
# Plot the results for the censored data
#
dev.new()
plot(gof.list)
#==========
# Continue the above example, but now test the hypothesis that
# these data came from a lognormal distribution
# (alternative parameterization) using the ShapiroWilk test.
#
# The pvalue for the complete data is p = 0.056, while
# the pvalue for the censored data is p = 0.11.
# Results for complete data:
#
gofTest(dat, test = "sw", dist = "lnormAlt")
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF
#
#Hypothesized Distribution: Lognormal
#
#Estimated Parameter(s): mean = 13.757239
# cv = 1.148872
#
#Estimation Method: mvue
#
#Data: dat
#
#Sample Size: 30
#
#Test Statistic: W = 0.9322226
#
#Test Statistic Parameter: n = 30
#
#Pvalue: 0.05626823
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
# Results for censored data:
#
gof.list < gofTestCensored(dat.censored, censored, test = "sw",
distribution = "lnormAlt")
gof.list
#Results of GoodnessofFit Test
#Based on Type I Censored Data
#
#
#Test Method: ShapiroWilk GOF
# (Singly Censored Data)
#
#Hypothesized Distribution: Lognormal
#
#Censoring Side: left
#
#Censoring Level(s): 5
#
#Estimated Parameter(s): mean = 13.0382221
# cv = 0.9129512
#
#Estimation Method: MLE
#
#Data: dat.censored
#
#Censoring Variable: censored
#
#Sample Size: 30
#
#Percent Censored: 23.3%
#
#Test Statistic: W = 0.9292406
#
#Test Statistic Parameters: N = 30.0000000
# DELTA = 0.2333333
#
#Pvalue: 0.114511
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
# Plot the results for the censored data
#
dev.new()
plot(gof.list)
#
# Redo the above example, but specify the quasiminimum variance
# unbiased estimator of the mean. Note that the method of
# estimating the parameters has no effect on the goodnessoffit
# test (see the DETAILS section above).
gofTestCensored(dat.censored, censored, test = "sw",
distribution = "lnormAlt", est.arg.list = list(method = "qmvue"))
#Results of GoodnessofFit Test
#Based on Type I Censored Data
#
#
#Test Method: ShapiroWilk GOF
# (Singly Censored Data)
#
#Hypothesized Distribution: Lognormal
#
#Censoring Side: left
#
#Censoring Level(s): 5
#
#Estimated Parameter(s): mean = 12.8722749
# cv = 0.8712549
#
#Estimation Method: QuasiMVUE
#
#Data: dat.censored
#
#Censoring Variable: censored
#
#Sample Size: 30
#
#Percent Censored: 23.3%
#
#Test Statistic: W = 0.9292406
#
#Test Statistic Parameters: N = 30.0000000
# DELTA = 0.2333333
#
#Pvalue: 0.114511
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
#
# Clean up
rm(dat, dat.censored, censored, gof.list)
graphics.off()
#==========
# Check the assumption that the silver data stored in Helsel.Cohn.88.silver.df
# follows a lognormal distribution and plot the goodnessoffit test results.
# Note that the small pvalue and the shape of the QQ plot
# (an inverted Sshape) suggests that the log transformation is not quite strong
# enough to "bring in" the tails (i.e., the logtransformed silver data has tails
# that are slightly too long relative to a normal distribution).
# Helsel and Cohn (1988, p.2002) note that the gross outlier of 560 mg/L tends to
# make the shape of the data resemble a gamma distribution.
dum.list < with(Helsel.Cohn.88.silver.df,
gofTestCensored(Ag, Censored, test = "sf", dist = "lnorm"))
dum.list
#Results of GoodnessofFit Test
#Based on Type I Censored Data
#
#
#Test Method: ShapiroFrancia GOF
# (Multiply Censored Data)
#
#Hypothesized Distribution: Lognormal
#
#Censoring Side: left
#
#Censoring Level(s): 0.1 0.2 0.3 0.5 1.0 2.0 2.5 5.0
# 6.0 10.0 20.0 25.0
#
#Estimated Parameter(s): meanlog = 1.040572
# sdlog = 2.354847
#
#Estimation Method: MLE
#
#Data: Ag
#
#Censoring Variable: Censored
#
#Sample Size: 56
#
#Percent Censored: 60.7%
#
#Test Statistic: W = 0.8957198
#
#Test Statistic Parameters: N = 56.0000000
# DELTA = 0.6071429
#
#Pvalue: 0.03490314
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
dev.new()
plot(dum.list)
#
# Clean up
#
rm(dum.list)
graphics.off()
#==========
# Chapter 15 of USEPA (2009) gives several examples of looking
# at normal QQ plots and estimating the mean and standard deviation
# for manganese concentrations (ppb) in groundwater at five background wells.
# In EnvStats these data are stored in the data frame
# EPA.09.Ex.15.1.manganese.df.
# Here we will test whether the data appear to come from a normal
# distribution, then we will test to see whether they appear to come
# from a lognormal distribution.
#
# First look at the data:
#
EPA.09.Ex.15.1.manganese.df
# Sample Well Manganese.Orig.ppb Manganese.ppb Censored
#1 1 Well.1 <5 5.0 TRUE
#2 2 Well.1 12.1 12.1 FALSE
#3 3 Well.1 16.9 16.9 FALSE
#...
#23 3 Well.5 3.3 3.3 FALSE
#24 4 Well.5 8.4 8.4 FALSE
#25 5 Well.5 <2 2.0 TRUE
longToWide(EPA.09.Ex.15.1.manganese.df,
"Manganese.Orig.ppb", "Sample", "Well",
paste.row.name = TRUE)
# Well.1 Well.2 Well.3 Well.4 Well.5
#Sample.1 <5 <5 <5 6.3 17.9
#Sample.2 12.1 7.7 5.3 11.9 22.7
#Sample.3 16.9 53.6 12.6 10 3.3
#Sample.4 21.6 9.5 106.3 <2 8.4
#Sample.5 <2 45.9 34.5 77.2 <2
# Now test whether the data appear to come from
# a normal distribution. Note that these data
# are multiply censored, so we'll use the
# ShapiroFrancia test.
#
gof.normal < with(EPA.09.Ex.15.1.manganese.df,
gofTestCensored(Manganese.ppb, Censored, test = "sf"))
gof.normal
#Results of GoodnessofFit Test
#Based on Type I Censored Data
#
#
#Test Method: ShapiroFrancia GOF
# (Multiply Censored Data)
#
#Hypothesized Distribution: Normal
#
#Censoring Side: left
#
#Censoring Level(s): 2 5
#
#Estimated Parameter(s): mean = 15.23508
# sd = 30.62812
#
#Estimation Method: MLE
#
#Data: Manganese.ppb
#
#Censoring Variable: Censored
#
#Sample Size: 25
#
#Percent Censored: 24%
#
#Test Statistic: W = 0.8368016
#
#Test Statistic Parameters: N = 25.00
# DELTA = 0.24
#
#Pvalue: 0.004662658
#
#Alternative Hypothesis: True cdf does not equal the
# Normal Distribution.
# Plot the results:
#
dev.new()
plot(gof.normal)
#
# Now test to see whether the data appear to come from
# a lognormal distribuiton.
#
gof.lognormal < with(EPA.09.Ex.15.1.manganese.df,
gofTestCensored(Manganese.ppb, Censored, test = "sf",
distribution = "lnorm"))
gof.lognormal
#Results of GoodnessofFit Test
#Based on Type I Censored Data
#
#
#Test Method: ShapiroFrancia GOF
# (Multiply Censored Data)
#
#Hypothesized Distribution: Lognormal
#
#Censoring Side: left
#
#Censoring Level(s): 2 5
#
#Estimated Parameter(s): meanlog = 2.215905
# sdlog = 1.356291
#
#Estimation Method: MLE
#
#Data: Manganese.ppb
#
#Censoring Variable: Censored
#
#Sample Size: 25
#
#Percent Censored: 24%
#
#Test Statistic: W = 0.9864426
#
#Test Statistic Parameters: N = 25.00
# DELTA = 0.24
#
#Pvalue: 0.9767731
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
# Plot the results:
#
dev.new()
plot(gof.lognormal)
#
# Clean up
#
rm(gof.normal, gof.lognormal)
graphics.off()

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.