| gofTestCensored | R Documentation |
Perform a goodness-of-fit 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.
gofTestCensored(x, censored, censoring.side = "left", test = "sf",
distribution = "norm", est.arg.list = NULL,
prob.method = "hirsch-stedinger", 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 goodness-of-fit test to perform. Possible values are:
The Shapiro-Wilk 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 goodness-of-fit test are
identical for Also, the results for the goodness-of-fit 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 |
Extended methods and derivations are available in
Distribution diagnostics, transformations, and probability plots: gofTestCensored.
Open the vignette locally with
vignette("distribution-diagnostics", package = "EnvStats").
a list of class "gofCensored" containing the results of the goodness-of-fit
test. See the help files for gofCensored.object for details.
The Shapiro-Wilk test (Shapiro and Wilk, 1965) and the Shapiro-Francia test (Shapiro and Francia, 1972) are probably the two most commonly used hypothesis tests to test departures from normality. The Shapiro-Wilk test is most powerful at detecting short-tailed (platykurtic) and skewed distributions, and least powerful against symmetric, moderately long-tailed (leptokurtic) distributions. Conversely, the Shapiro-Francia test is more powerful against symmetric long-tailed distributions and less powerful against short-tailed distributions (Royston, 1992b; 1993).
In practice, almost any goodness-of-fit test will not reject the null hypothesis
if the number of observations is relatively small. Conversely, almost any goodness-of-fit
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 goodness-of-fit tests. Another way is to look at
quantile-quantile (Q-Q) plots (see qqPlotCensored).
Steven P. Millard (EnvStats@ProbStatInfo.com)
Birnbaum, Z.W., and F.H. Tingey. (1951). One-Sided Confidence Contours for Probability Distribution Functions. Annals of Mathematical Statistics 22, 592-596.
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, 294-296.
D'Agostino, R.B. (1970). Transformation to Normality of the Null Distribution of g1.
Biometrika 57, 679-681.
D'Agostino, R.B. (1971). An Omnibus Test of Normality for Moderate and Large Size Samples. Biometrika 58, 341-348.
D'Agostino, R.B. (1986b). Tests for the Normal Distribution. In: D'Agostino, R.B., and M.A. Stephens, eds. Goodness-of 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 \sqrt{b1}.
Biometrika 60(3), 613-622.
D'Agostino, R.B., and G.L. Tietjen (1973). Approaches to the Null Distribution of \sqrt{b1}.
Biometrika 60(1), 169-173.
Fisher, R.A. (1950). Statistical Methods for Research Workers. 11'th Edition. Hafner Publishing Company, New York, pp.99-100.
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 Shapiro-Wilk W-Test for Non-Normality. Statistics and Computing 2, 117-119.
Royston, J.P. (1992b). Estimation, Reference Ranges and Goodness of Fit for the Three-Parameter Log-Normal Distribution. Statistics in Medicine 11, 897-912.
Royston, J.P. (1992c). A Pocket-Calculator Algorithm for the Shapiro-Francia Test of Non-Normality: An Application to Medicine. Statistics in Medicine 12, 181-184.
Royston, P. (1993). A Toolkit for Testing for Non-Normality in Complete and Censored Samples. The Statistician 42, 37-43.
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), 215-219.
Shapiro, S.S., and M.B. Wilk. (1965). An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591-611.
Verrill, S., and R.A. Johnson. (1987). The Asymptotic Equivalence of Some Modified Shapiro-Wilk Statistics – Complete and Censored Sample Cases. The Annals of Statistics 15(1), 413-419.
Verrill, S., and R.A. Johnson. (1988). Tables and Large-Sample Distribution Theory for Censored-Data Correlation Statistics for Testing Normality. Journal of the American Statistical Association 83, 1192-1197.
Weisberg, S., and C. Bingham. (1975). An Approximate Analysis of Variance Test for Non-Normality Suitable for Machine Calculation. Technometrics 17, 133-134.
gofTest, gofCensored.object,
print.gofCensored, plot.gofCensored,
shapiro.test, Normal, Lognormal,
enormCensored, elnormCensored,
elnormAltCensored, qqPlotCensored.
# 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 Shapiro-Wilk test.
#
# The p-value for the complete data is p = 0.86, while
# the p-value 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 Goodness-of-Fit Test
#-------------------------------
#
#Test Method: Shapiro-Wilk 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
#
#P-value: 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 Goodness-of-Fit Test
#Based on Type I Censored Data
#-------------------------------
#
#Test Method: Shapiro-Wilk 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
#
#P-value: 0.522329
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
# Plot the results for the censored data
#---------------------------------------
if (interactive()) 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 Shapiro-Wilk test.
#
# The p-value for the complete data is p = 0.056, while
# the p-value for the censored data is p = 0.11.
# Results for complete data:
#---------------------------
gofTest(dat, test = "sw", dist = "lnormAlt")
#Results of Goodness-of-Fit Test
#-------------------------------
#
#Test Method: Shapiro-Wilk 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
#
#P-value: 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 Goodness-of-Fit Test
#Based on Type I Censored Data
#-------------------------------
#
#Test Method: Shapiro-Wilk 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
#
#P-value: 0.114511
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
# Plot the results for the censored data
#---------------------------------------
if (interactive()) dev.new()
plot(gof.list)
#----------
# Redo the above example, but specify the quasi-minimum variance
# unbiased estimator of the mean. Note that the method of
# estimating the parameters has no effect on the goodness-of-fit
# test (see the DETAILS section above).
gofTestCensored(dat.censored, censored, test = "sw",
distribution = "lnormAlt", est.arg.list = list(method = "qmvue"))
#Results of Goodness-of-Fit Test
#Based on Type I Censored Data
#-------------------------------
#
#Test Method: Shapiro-Wilk 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: Quasi-MVUE
#
#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
#
#P-value: 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 goodness-of-fit test results.
# Note that the small p-value and the shape of the Q-Q plot
# (an inverted S-shape) suggests that the log transformation is not quite strong
# enough to "bring in" the tails (i.e., the log-transformed 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 Goodness-of-Fit Test
#Based on Type I Censored Data
#-------------------------------
#
#Test Method: Shapiro-Francia 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
#
#P-value: 0.03490314
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
if (interactive()) dev.new()
plot(dum.list)
#----------
# Clean up
#---------
rm(dum.list)
graphics.off()
#==========
# Chapter 15 of USEPA (2009) gives several examples of looking
# at normal Q-Q 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
# Shapiro-Francia test.
#----------------------------------------------
gof.normal <- with(EPA.09.Ex.15.1.manganese.df,
gofTestCensored(Manganese.ppb, Censored, test = "sf"))
gof.normal
#Results of Goodness-of-Fit Test
#Based on Type I Censored Data
#-------------------------------
#
#Test Method: Shapiro-Francia 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
#
#P-value: 0.004662658
#
#Alternative Hypothesis: True cdf does not equal the
# Normal Distribution.
# Plot the results:
#------------------
if (interactive()) 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 Goodness-of-Fit Test
#Based on Type I Censored Data
#-------------------------------
#
#Test Method: Shapiro-Francia 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
#
#P-value: 0.9767731
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
# Plot the results:
#------------------
if (interactive()) 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.