gofTest {EnvStats}  R Documentation 
GoodnessofFit Test
Description
Perform a goodnessoffit test to determine whether a data set appears to come from a specified probability distribution or if two data sets appear to come from the same distribution.
Usage
gofTest(y, ...)
## S3 method for class 'formula'
gofTest(y, data = NULL, subset,
na.action = na.pass, ...)
## Default S3 method:
gofTest(y, x = NULL,
test = ifelse(is.null(x), "sw", "ks"),
distribution = "norm", est.arg.list = NULL,
alternative = "two.sided", n.classes = NULL,
cut.points = NULL, param.list = NULL,
estimate.params = ifelse(is.null(param.list), TRUE, FALSE),
n.param.est = NULL, correct = NULL, digits = .Options$digits,
exact = NULL, ws.method = "normal scores", warn = TRUE, keep.data = TRUE,
data.name = NULL, data.name.x = NULL, parent.of.data = NULL,
subset.expression = NULL, ...)
Arguments
y 
an object containing data for the goodnessoffit test. In the default
method, the argument 
data 
specifies an optional data frame, list or environment (or object coercible
by 
subset 
specifies an optional vector specifying a subset of observations to be used. 
na.action 
specifies a function which indicates what should happen when the data contain 
x 
numeric vector of values for the first sample in the case of a twosample
KolmogorovSmirnov goodnessoffit test ( 
test 
character string defining which goodnessoffit test to perform. Possible values are:
When the argument 
distribution 
a character string denoting the distribution abbreviation. See the help file for
When When When When When When 
est.arg.list 
a list of arguments to be passed to the function estimating the distribution parameters.
For example, if When When When When 
alternative 
for the case when 
n.classes 
for the case when 
cut.points 
for the case when 
param.list 
for the case when 
estimate.params 
for the case when 
n.param.est 
for the case when 
correct 
for the case when 
digits 
for the case when 
exact 
for the case when 
ws.method 
for the case when 
warn 
logical scalar indicating whether to print a warning message when
observations with 
keep.data 
logical scalar indicating whether to return the data used for the goodnessoffit test.
The default value is 
data.name 
character string indicating the name of the data used for argument 
data.name.x 
character string indicating the name of the data used for argument 
parent.of.data 
character string indicating the source of the data used for the goodnessoffit test. 
subset.expression 
character string indicating the expression used to subset the data. 
... 
additional arguments affecting the goodnessoffit test. 
Details

ShapiroWilk GoodnessofFit Test (
test="sw"
).The ShapiroWilk goodnessoffit test (Shapiro and Wilk, 1965; Royston, 1992a) is one of the most commonly used goodnessoffit tests for normality. You can use it to test the following hypothesized distributions: Normal, Lognormal, ThreeParameter Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta). In addition, you can also use it to test the null hypothesis of any continuous distribution that is available (see the help file for
Distribution.df
, and see explanation below).
ShapiroWilk WStatistic and PValue for Testing Normality
LetX
denote a random variable with cumulative distribution function (cdf)F
. Suppose we want to test the null hypothesis thatF
is the cdf of a normal (Gaussian) distribution with some arbitrary mean\mu
and standard deviation\sigma
against the alternative hypothesis thatF
is the cdf of some other distribution. The table below shows the random variable for whichF
is the assumed cdf, given the value of the argumentdistribution
.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)
"lnorm3"
ThreeParameter Lognormal log(X\gamma)
"zmnorm"
ZeroModified Normal X  X > 0
"zmlnorm"
ZeroModified Lognormal (Logspace) log(X)  X > 0
"zmlnormAlt"
ZeroModified Lognormal (Untransformed) log(X)  X > 0
Note that for the threeparameter lognormal distribution, the symbol
\gamma
denotes the threshold parameter.Let
\underline{x} = (x_1, x_2, \ldots, x_n)
denote the vector ofn
ordered observations assumed to come from a normal distribution.
The ShapiroWilk WStatistic
Shapiro and Wilk (1965) introduced the following statistic to test the null hypothesis thatF
is the cdf of a normal distribution:W = \frac{(\sum_{i=1}^n a_i x_i)^2}{\sum_{i=1}^n (x_i  \bar{x})^2} \;\;\;\;\;\; (1)
where the quantity
a_i
is thei
'th element of the vector\underline{a}
defined by:\underline{a} = \frac{\underline{m}^T V^{1}}{[\underline{m}^T V^{1} V^{1} \underline{m}]^{1/2}} \;\;\;\;\;\; (2)
where
T
denotes the transpose operator, and\underline{m}
is the vector of expected values andV
is the variancecovariance matrix of the order statistics of a random sample of sizen
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 \;\;\;\;\;\; (3)
It can be shown that the coefficients
\underline{a}
are antisymmetric, that is,a_i = a_{ni+1} \;\;\;\;\;\; (4)
and for odd
n
,a_{(n+1)/2} = 0 \;\;\;\;\;\; (5)
Now because
\bar{a} = \frac{1}{n} \sum_{i=1}^n a_i = 0 \;\;\;\;\;\ (6)
and
\sum_{i=1}^n (a_i  \bar{a})^2 = \sum_{i=1}^n a_i^2 = \underline{a}^T \underline{a} = 1 \;\;\;\;\;\; (7)
the
W
statistic in Equation (1) 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 \;\;\;\;\;\; (8)
where
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 ShapiroWilk
W
statistic is also simply the ratio of two estimators of variance, and can be rewritten asW = \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:
\hat{\sigma}_{BLUE} = \frac{\sum_{i=1}^n a_i x_i}{\sqrt{n1}} \;\;\;\;\;\; (11)
\hat{\sigma}_{MVUE}^2 = \frac{\sum_{i=1}^n (x_i  \bar{x})^2}{n1} \;\;\;\;\;\; (12)
Small values of
W
indicate the null hypothesis is probably not true. Shapiro and Wilk (1965) computed the values of the coefficients\underline{a}
and the percentage points forW
(based on smoothing the empirical null distribution ofW
) for sample sizes up to 50. Computation of theW
statistic for larger sample sizes can be cumbersome, since computation of the coefficients\underline{a}
requires storage of at leastn + [n(n+1)/2]
reals followed byn \times n
matrix inversion (Royston, 1992a).
The ShapiroFrancia W'Statistic
Shapiro and Francia (1972) introduced a modification of theW
test that depends only on the expected values of the order statistics (\underline{m}
) and not on the variancecovariance matrix (V
):W' = \frac{(\sum_{i=1}^n b_i x_i)^2}{\sum_{i=1}^n (x_i  \bar{x})^2} \;\;\;\;\;\; (13)
where the quantity
b_i
is thei
'th element of the vector\underline{b}
defined by:\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'
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\underline{x}
and the expected normal order statistics\underline{m}
: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'
based on a Monte Carlo simulation. It can be shown that the asymptotic null distributions ofW
andW'
are identical, but convergence is very slow (Verrill and Johnson, 1988).
The WeisbergBingham Approximation to the W'Statistic
Weisberg and Bingham (1975) introduced an approximation of the ShapiroFranciaW'
statistic that is easier to compute. They suggested using Blom scores (Blom, 1958, pp.68–75) to approximate the element of\underline{m}
:\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
c_i
is thei
'th element of the vector\underline{c}
defined by:\underline{c} = \frac{\underline{\tilde{m}}}{[\underline{\tilde{m}}^T \underline{\tilde{m}}]^{1/2}} \;\;\;\;\;\; (17)
and
\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\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 ShapiroWilk WTest
Royston (1992a) presents an approximation for the coefficients\underline{a}
necessary to compute the ShapiroWilkW
statistic, and also a transformation of theW
statistic that has approximately a standard normal distribution under the null hypothesis.Noting that, up to a constant, the components of
\underline{b}
in Equation (14) and\underline{c}
in Equation (17) differ from those of\underline{a}
in Equation (2) mainly in the first and last two components, Royston (1992a) used the approximation\underline{c}
as the basis for approximating\underline{a}
using polynomial (quintic) regression analysis. For4 \le n \le 1000
, the approximation gave the following equations for the last two (and hence first two) components of\underline{a}
:\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)
\tilde{a}_{n1} = c_{n1} + 0.042981 y  0.293762 y^2  1.752461 y^3 + 5.682633 y^4  3.582633 y^5 \;\;\;\;\;\; (20)
where
y = \sqrt{n} \;\;\;\;\;\; (21)
The other components are computed as:
\tilde{a}_i = \frac{\tilde{m}_i}{\sqrt{\eta}} \;\;\;\;\;\; (22)
for
i = 2, \ldots , n1
ifn \le 5
, ori = 3, \ldots, n2
ifn > 5
, where\eta = \frac{\underline{\tilde{m}}^T \underline{\tilde{m}}  2 \tilde{m}_n^2}{1  2 \tilde{a}_n^2} \;\;\;\;\;\; (23)
if
n \le 5
, and\eta = \frac{\underline{\tilde{m}}^T \underline{\tilde{m}}  2 \tilde{m}_n^2  2 \tilde{m}_{n1}^2}{1  2 \tilde{a}_n^2  2 \tilde{a}_{n1}^2} \;\;\;\;\;\; (24)
if
n > 5
.Royston (1992a) found his approximation to
\underline{a}
to be accurate to at least\pm 1
in the third decimal place over all values ofi
and selected values ofn
, and also found that critical percentage points ofW
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 pvalue associated with a particular value ofW
, Royston (1992a) approximated the distribution of(1W)
by a threeparameter lognormal distribution for4 \le n \le 11
, and the upper half of the distribution of(1W)
by a twoparameter lognormal distribution for12 \le n \le 2000
. Settingz = \frac{w  \mu}{\sigma} \;\;\;\;\;\; (25)
the pvalue associated with
W
is given by:p = 1  \Phi(z) \;\;\;\;\;\; (26)
For
4 \le n \le 11
, the quantities necessary to computez
are given by:w = log[\gamma  log(1  W)] \;\;\;\;\;\; (27)
\gamma = 2.273 + 0.459 n \;\;\;\;\;\; (28)
\mu = 0.5440  0.39978 n + 0.025054 n^2  0.000671 n^3 \;\;\;\;\;\; (29)
\sigma = exp(1.3822  0.77857 n + 0.062767 n^2  0.0020322 n^3) \;\;\;\;\;\; (30)
For
12 \le n \le 2000
, the quantities necessary to computez
are given by:w = log(1  W) \;\;\;\;\;\; (31)
\gamma = log(n) \;\;\;\;\;\; (32)
\mu = 1.5861  0.31082 y  0.083751 y^2 + 0.00038915 y^3 \;\;\;\;\;\; (33)
\sigma = exp(0.4803  0.082676 y + 0.0030302 y^2) \;\;\;\;\;\; (34)
For the last approximation when
12 \le n \le 2000
, Royston (1992a) claims this approximation is actually valid for sample sizes up ton = 5000
.
Modification for the ThreeParameter Lognormal Distribution
Whendistribution="lnorm3"
, the functiongofTest
assumes the vector\underline{x}
is a random sample from a threeparameter lognormal distribution. It estimates the threshold parameter via the zeroskewness method (seeelnorm3
), and then performs the ShapiroWilk goodnessoffit test for normality onlog(x\hat{\gamma})
where\hat{\gamma}
is the estimated threshold parmater. Because the threshold parameter has to be estimated, however, the pvalue associated with the computed zstatistic will tend to be conservative (larger than it should be under the null hypothesis). Royston (1992b) proposed the following transformation of the zstatistic:z' = \frac{z  \mu_z}{\sigma_z} \;\;\;\;\;\; (35)
where for
5 \le n \le 11
,\mu_z = 3.8267 + 2.8242 u  0.63673 u^2  0.020815 v \;\;\;\;\;\; (36)
\sigma_z = 4.9914 + 8.6724 u  4.27905 u^2 + 0.70350 u^3  0.013431 v \;\;\;\;\;\; (37)
and for
12 \le n \le 2000
,\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)
\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)
v = u (\hat{\sigma}  \hat{\sigma}^2) \;\;\;\;\;\; (41)
\hat{\sigma}^2 = \frac{1}{n1} \sum_{i=1}^n (y_i  \bar{y})^2 \;\;\;\;\;\; (42)
y_i = log(x_i  \hat{\gamma}) \;\;\;\;\;\; (43)
and
\gamma
denotes the threshold parameter. The pvalue associated with this test is then given by:p = 1  \Phi(z') \;\;\;\;\;\; (44)
Testing GoodnessofFit for Any Continuous Distribution
The functiongofTest
extends the ShapiroWilk test 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 functiongofTest
modifies the approach of Chen and Balakrishnan (1995) by using the same first 2 steps, and then applying the ShapiroWilk test:Let
\underline{x} = x_1, x_2, \ldots, x_n
denote the vector ofn
ordered observations. Compute cumulative probabilities for eachx_i
based on the cumulative distribution function for the hypothesized distribution. That is, computep_i = F(x_i, \hat{\theta})
whereF(x, \theta)
denotes the hypothesized cumulative distribution function with parameter(s)\theta
, and\hat{\theta}
denotes the estimated parameter(s).Compute standard normal deviates based on the computed cumulative probabilities:
y_i = \Phi^{1}(p_i)
Perform the ShapiroWilk goodnessoffit test on the
y_i
's.

ShapiroFrancia GoodnessofFit Test (
test="sf"
).The ShapiroFrancia goodnessoffit test (Shapiro and Francia, 1972; Weisberg and Bingham, 1975; Royston, 1992c) is also one of the most commonly used goodnessoffit tests for normality. You can use it to test the following hypothesized distributions: Normal, Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta). In addition, you can also use it to test the null hypothesis of any continuous distribution that is available (see the help file for
Distribution.df
). See the section Testing GoodnessofFit for Any Continuous Distribution above for an explanation of how this is done.
Royston's Transformation of the ShapiroFrancia W'Statistic to Normality
Equation (13) above gives the formula for the ShapiroFrancia W'statistic, and Equation (16) above gives the formula for WeisbergBingham approximation to the W'statistic (denoted\tilde{W}'
). Royston (1992c) presents an algorithm to transform the\tilde{W}'
statistic so that its null distribution is approximately a standard normal. For5 \le n \le 5000
, Royston (1992c) approximates the distribution of(1\tilde{W}')
by a lognormal distribution. Settingz = \frac{w\mu}{\sigma} \;\;\;\;\;\; (45)
the pvalue associated with
\tilde{W}'
is given by:p = 1  \Phi(z) \;\;\;\;\;\; (46)
The quantities necessary to compute
z
are given by:w = log(1  \tilde{W}') \;\;\;\;\;\; (47)
\nu = log(n) \;\;\;\;\;\; (48)
u = log(\nu)  \nu \;\;\;\;\;\; (49)
\mu = 1.2725 + 1.0521 u \;\;\;\;\;\; (50)
v = log(\nu) + \frac{2}{\nu} \;\;\;\;\;\; (51)
\sigma = 1.0308  0.26758 v \;\;\;\;\;\; (52)
Testing GoodnessofFit for Any Continuous Distribution
The functiongofTest
extends the ShapiroFrancia test 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 functiongofTest
modifies the approach of Chen and Balakrishnan (1995) by using the same first 2 steps, and then applying the ShapiroFrancia test:Let
\underline{x} = x_1, x_2, \ldots, x_n
denote the vector ofn
ordered observations. Compute cumulative probabilities for eachx_i
based on the cumulative distribution function for the hypothesized distribution. That is, computep_i = F(x_i, \hat{\theta})
whereF(x, \theta)
denotes the hypothesized cumulative distribution function with parameter(s)\theta
, and\hat{\theta}
denotes the estimated parameter(s).Compute standard normal deviates based on the computed cumulative probabilities:
y_i = \Phi^{1}(p_i)
Perform the ShapiroFrancia goodnessoffit test on the
y_i
's.

Probability Plot Correlation Coefficient (PPCC) GoodnessofFit Test (
test="ppcc"
).The PPPCC goodnessoffit test (Filliben, 1975; Looney and Gulledge, 1985) can be used to test the following hypothesized distributions: Normal, Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta). In addition, you can also use it to test the null hypothesis of any continuous distribution that is available (see the help file for
Distribution.df
). The functiongofTest
computes the PPCC test statistic using Blom plotting positions.Filliben (1975) proposed using the correlation coefficient
r
from a normal probability plot to perform a goodnessoffit test for normality, and he provided a table of critical values forr
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 help file for
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 ofr
based on Blom plotting positions.The function
gofTest
computes the PPCC test statisticr
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.

AndersonDarling GoodnessofFit Test (
test="ad"
).The AndersonDarling goodnessoffit test (Stephens, 1986a; Thode, 2002) can be used to test the following hypothesized distributions: Normal, Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta).
When
test="ad"
, the functiongofTest
calls the functionad.test
in the package nortest. Documentation from that package is as follows:The AndersonDarling test is an EDF omnibus test for the composite hypothesis of normality. The test statistic is:
A = n  \frac{1}{n} \sum_{i=1}^n [2i  1][ln(p_{(i)}) + ln(1  p_{(ni+1)})]
where
p_{(i)} = \Phi([x_{(i)}  \bar{x}]/s)
. Here,\Phi
is the cumulative distribution function of the standard normal distribution, and\bar{x}
ands
are mean and standard deviation of the data values. The pvalue is computed from the modified statisticZ = A (1.0 + 0.75/n + 2.25/n^2)
according to Table 4.9 in Stephens [(1986a)].

Cramervon Mises GoodnessofFit Test (
test="cvm"
).The Cramervon Mises goodnessoffit test (Stephens, 1986a; Thode, 2002) can be used to test the following hypothesized distributions: Normal, Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta).
When
test="cvm"
, the functiongofTest
calls the functioncvm.test
in the package nortest. Documentation from that package is as follows:The Cramervon Mises test is an EDF omnibus test for the composite hypothesis of normality. The test statistic is:
W = \frac{1}{12n} + \sum_{i=1}^n \left(p_{(i)}  \frac{2i1}{2n}\right)^2
where
p_{(i)} = \Phi([x_{(i)}  \bar{x}]/s)
. Here,\Phi
is the cumulative distribution function of the standard normal distribution, and\bar{x}
ands
are mean and standard deviation of the data values. The pvalue is computed from the modified statisticZ = W (1.0 + 0.75/n)
according to Table 4.9 in Stephens [(1986a)].

Lilliefors GoodnessofFit Test (
test="lillie"
).The Lilliefors goodnessoffit test (Stephens, 1974; Dallal and Wilkinson, 1986; Thode, 2002) can be used to test the following hypothesized distributions: Normal, Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta).
When
test="lillie"
, the functiongofTest
calls the functionlillie.test
in the package nortest. Documentation from that package is as follows:The Lilliefors (KolmogorovSmirnov) 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^\}
withD^+ = \max_{i = 1, \ldots, n} \{i/n  p_{(i)}\}, \;\; D^ = \max_{i = 1, \ldots, n} \{p_{(i)}  (i1)/n\}
where
p_{(i)} = \Phi([x_{(i)}  \bar{x}]/s)
. Here,\Phi
is the cumulative distribution function of the standard normal distribution, and\bar{x}
ands
are mean and standard deviation of the data values. The pvalue is computed from the DallalWilkinson (1986) formula, which is claimed to be only reliable when the pvalue is smaller than 0.1. If the DallalWilkinson pvalue turns out to be greater than 0.1, then the pvalue is computed from the distribution of the modified statisticZ = D (\sqrt{n}  0.01 + 0.85/\sqrt{n})
, see Stephens (1974), the actual pvalue formula being obtained by a simulation and approximation process.

ZeroSkew GoodnessofFit Test (
test="skew"
).The Zeroskew goodnessoffit test (D'Agostino, 1970) can be used to test the following hypothesized distributions: Normal, Lognormal, ZeroModified Normal, or ZeroModified Lognormal (Delta).
When
test="skew"
, the functiongofTest
tests the null hypothesis that the skew of the distribution is 0:H_0: \sqrt{\beta}_1 = 0 \;\;\;\;\;\; (53)
where
\sqrt{\beta}_1 = \frac{\mu_3}{\mu_2^{3/2}} \;\;\;\;\;\; (54)
and the quantity
\mu_r
denotes ther
'th moment about the mean (also called ther
'th central moment). The quantity\sqrt{\beta_1}
is called the coefficient of skewness, and is estimated by:\sqrt{b}_1 = \frac{m_3}{m_2^{3/2}} \;\;\;\;\;\; (55)
where
m_r = \frac{1}{n} \sum_{i=1}^n (x_i  \bar{x})^r \;\;\;\;\;\; (56)
denotes the
r
'th sample central moment.The possible alternative hypotheses are:
H_a: \sqrt{\beta}_1 \ne 0 \;\;\;\;\;\; (57)
H_a: \sqrt{\beta}_1 < 0 \;\;\;\;\;\; (58)
H_a: \sqrt{\beta}_1 > 0 \;\;\;\;\;\; (59)
which correspond to
alternative="twosided"
,alternative="less"
, and
alternative="greater"
, respectively.To test the null hypothesis of zero skew, D'Agostino (1970) derived an approximation to the distribution of
\sqrt{b_1}
under the null hypothesis of zeroskew, assuming the observations comprise a random sample from a normal (Gaussian) distribution. Based on D'Agostino's approximation, the statisticZ
shown below is assumed to follow a standard normal distribution and is used to compute the pvalue associated with the test ofH_0
:Z = \delta \;\; log\{ \frac{Y}{\alpha} + [(\frac{Y}{\alpha})^2 + 1]^{1/2} \} \;\;\;\;\;\; (60)
where
Y = \sqrt{b_1} [\frac{(n+1)(n+3)}{6(n2)}]^{1/2} \;\;\;\;\;\; (61)
\beta_2 = \frac{3(n^2 + 27n  70)(n+1)(n+3)}{(n2)(n+5)(n+7)(n+9)} \;\;\;\;\;\; (62)
W^2 = 1 + \sqrt{2\beta_2  2} \;\;\;\;\;\; (63)
\delta = 1 / \sqrt{log(W)} \;\;\;\;\;\; (64)
\alpha = [2 / (W^2  1)]^{1/2} \;\;\;\;\;\; (65)
When the sample size
n
is at least 150, a simpler approximation may be used in whichY
in Equation (61) is assumed to follow a standard normal distribution and is used to compute the pvalue associated with the hypothesis test.

KolmogorovSmirnov GoodnessofFit Test (
test="ks"
).When
test="ks"
, the functiongofTest
calls the R functionks.test
to compute the test statistic and pvalue. Note that for the onesample case, the distribution parameters should be prespecified 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 KolmogorovSmirnov GoodnessofFit Test for Gamma (
test="proucl.ks.gamma"
).When
test="proucl.ks.gamma"
, the functiongofTest
calls the R functionks.test
to compute the KolmogorovSmirnov test statistic based on the maximum likelihood estimates of the shape and scale parameters (seeegamma
). The pvalue is computed based on the simulated critical values given inProUCL.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 AndersonDarling GoodnessofFit Test for Gamma (
test="proucl.ad.gamma"
).When
test="proucl.ad.gamma"
, the functiongofTest
computes the AndersonDarling test statistic (Stephens, 1986a, p.101) based on the maximum likelihood estimates of the shape and scale parameters (seeegamma
). The pvalue is computed based on the simulated critical values given inProUCL.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.

ChiSquared GoodnessofFit Test (
test="chisq"
).The method used by
gofTest
is a modification of what is used forchisq.test
. If the hypothesized distribution function is completely specified, the degrees of freedom arem1
wherem
denotes the number of classes. If any parameters are estimated, the degrees of freedom depend on the method of estimation. The functiongofTest
follows the convention of computing degrees of freedom asm1k
, wherek
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 betweenm1
andm1k
. Therefore, especially when the sample size is small, it is important to compare the test statistic to the chisquared distribution with bothm1
andm1k
degrees of freedom. See Kendall and Stuart (1991, Chapter 30) for a more complete discussion.The distribution theory of chisquare 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 pvalues with caution when expected cell counts are small.

WilkShapiro GoodnessofFit Test for Uniform [0, 1] Distribution (
test="ws"
).Wilk and Shapiro (1968) suggested this test in the context of jointly testing several independent samples for normality simultaneously. If
p_1, p_2, \ldots, p_n
denote the pvalues associated with the test for normality ofn
independent samples, then under the null hypothesis that alln
samples come from a normal distribution, the pvalues are a random sample ofn
observations from a Uniform [0,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 pvalues come from a Uniform [0, 1] distribution:
Test Based on Normal Scores. Under the null hypothesis, the normal scores
\Phi^{1}(p_1), \Phi^{1}(p_2), \ldots, \Phi^{1}(p_n)
are a random sample of
n
observations from a standard normal distribution. Wilk and Shapiro (1968) denote thei
'th normal score byG_i = \Phi^{1}(p_i) \;\;\;\;\;\; (66)
and note that under the null hypothesis, the quantity
G
defined asG = \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
n
independent samples did not come from a normal distribution and hence would be associated with smaller pvalues than expected under the null hypothesis, which translates to the alternative that the cdf for the distribution of the pvalues is greater than the cdf of a Uniform [0, 1] distribution (alternative="greater"
). In terms of the test statisticG
, this alternative hypothesis would tend to makeG
smaller than expected, so the pvalue is given by\Phi(G)
. For the onesided lower alternative that the cdf for the distribution of pvalues is less than the cdf for a Uniform [0, 1] distribution, the pvalue is given byp = 1  \Phi(G) \;\;\;\;\;\; (68)
.

Test Based on ChiSquare Scores. Under the null hypothesis, the chisquare scores
2 \, log(p_1), 2 \, log(p_2), \ldots, 2 \, log(p_n)
are a random sample of
n
observations from a chisquare distribution with 2 degrees of freedom (Fisher, 1950). Wilk and Shapiro (1968) denote thei
'th chisquare score byC_i = 2 \, log(p_i) \;\;\;\;\;\; (69)
and note that under the null hypothesis, the quantity
C
defined asC = \sum^n_{1}{C_i} \;\;\;\;\;\; (70)
has a chisquare distribution with
2n
degrees of freedom. Wilk and Shapiro (1968) were interested in the alternative hypothesis that some of then
independent samples did not come from a normal distribution and hence would be associated with smaller pvalues than expected under the null hypothesis, which translates to the alternative that the cdf for the distribution of the pvalues is greater than the cdf of a Uniform [0, 1] distribution (alternative="greater"
). In terms of the test statisticC
, this alternative hypothesis would tend to makeC
larger than expected, so the pvalue is given byp = 1  F_{2n}(C) \;\;\;\;\;\; (71)
where
F_2n
denotes the cumulative distribution function of the chisquare distribution with2n
degrees of freedom. For the onesided lower alternative that the cdf for the distribution of pvalues is less than the cdf for a Uniform [0, 1] distribution, the pvalue is given byp = F_{2n}(C) \;\;\;\;\;\; (72)

Value
a list of class "gof"
containing the results of the goodnessoffit test, unless
the twosample
KolmogorovSmirnov test is used, in which case the value is a list of
class "gofTwoSample"
. Objects of class "gof"
and "gofTwoSample"
have special printing and plotting methods. See the help files for gof.object
and gofTwoSample.object
for details.
Note
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 general, the ShapiroWilk and ShapiroFrancia tests outperform the AndersonDarling test, which in turn outperforms the Cramervon Mises test, which in turn outperforms the Lilliefors test (Stephens, 1986a; Razali and Wah, 2011; Romao et al., 2010).
The zeroskew goodnessoffit test for normality is one of several tests that have
been proposed to test the assumption of a normal distribution (D'Agostino, 1986b).
This test has been included mainly because it is called by elnorm3
.
Ususally, the ShapiroWilk or ShapiroFrancia test is preferred to this test, unless
the direction of the alternative to normality (e.g., positive skew) is known
(D'Agostino, 1986b, pp. 405–406).
Kolmogorov (1933) introduced a goodnessoffit test to test the hypothesis that a
random sample of n
observations x comes from a specific hypothesized distribution
with cumulative distribution function H
. This test is now usually called the
onesample KolmogorovSmirnov goodnessoffit test. Smirnov (1939) introduced a
goodnessoffit test to test the hypothesis that a random sample of n
observations x comes from the same distribution as a random sample of
m
observations y. This test is now usually called the twosample
KolmogorovSmirnov goodnessoffit test. Both tests are based on the maximum
vertical distance between two cumulative distribution functions. For the onesample problem
with a small sample size, the KolmogorovSmirnov test may be preferred over the chisquared
goodnessoffit test since the KStest is exact, while the chisquared test is based on
an asymptotic approximation.
The chisquared test, introduced by Pearson in 1900, is the oldest and best known goodnessoffit test. The idea is to reduce the goodnessoffit problem to a multinomial setting by comparing the observed cell counts with their expected values under the null hypothesis. Grouping the data sacrifices information, especially if the hypothesized distribution is continuous. On the other hand, chisquared tests can be be applied to any type of variable: continuous, discrete, or a combination of these.
The WilkShapiro (1968) tests for a Uniform [0, 1] distribution were introduced in the context
of testing whether several independent samples all come from normal distributions, with
possibly different means and variances. The function gofGroupTest
extends
this idea to allow you to test whether several independent samples come from the same
distribution (e.g., gamma, extreme value, etc.), with possibly different parameters.
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 qqPlot
).
Author(s)
Steven P. Millard (EnvStats@ProbStatInfo.com)
Juergen Gross and Uwe Ligges for the AndersonDarling, Carmervon Mises, and Lilliefors tests called from the package nortest.
References
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 \sqrt{b1}
.
Biometrika 60(3), 613622.
D'Agostino, R.B., and G.L. Tietjen (1973). Approaches to the Null Distribution of \sqrt{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.
Kim, P.J., and R.I. Jennrich. (1973). Tables of the Exact Sampling Distribution of the Two Sample KolmogorovSmirnov Criterion. In Harter, H.L., and D.B. Owen, eds. Selected Tables in Mathematical Statistics, Vol. 1. American Mathematical Society, Providence, Rhode Island, pp.79170.
Kolmogorov, A.N. (1933). Sulla determinazione empirica di una legge di distribuzione. Giornale dell' Istituto Italiano degle Attuari 4, 8391.
Marsaglia, G., W.W. Tsang, and J. Wang. (2003). Evaluating Kolmogorov's distribution. Journal of Statistical Software, 8(18). doi:10.18637/jss.v008.i18.
Moore, D.S. (1986). Tests of ChiSquared Type. In D'Agostino, R.B., and M.A. Stephens, eds. Goodnessof Fit Techniques. Marcel Dekker, New York, pp.6395.
Pomeranz, J. (1973). Exact Cumulative Distribution of the KolmogorovSmirnov Statistic for Small Samples (Algorithm 487). Collected Algorithms from ACM ??, ??????.
Razali, N.M., and Y.B. Wah. (2011). Power Comparisons of ShapiroWilk, KolmogorovSmirnov, Lilliefors, and AndersonDarling Tests. Journal of Statistical Modeling and Analytics 2(1), 21–33.
Romao, X., Delgado, R., and A. Costa. (2010). An Empirical Power Comparison of Univariate GoodnessofFit Tests for Normality. Journal of Statistical Computation and Simulation 80(5), 545–591.
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.
Smirnov, N.V. (1939). Estimate of Deviation Between Empirical Distribution Functions in Two Independent Samples. Bulletin Moscow University 2(2), 316.
Smirnov, N.V. (1948). Table for Estimating the Goodness of Fit of Empirical Distributions. Annals of Mathematical Statistics 19, 279281.
Stephens, M.A. (1970). Use of the KolmogorovSmirnov, Cramervon Mises and Related Statistics Without Extensive Tables. Journal of the Royal Statistical Society, Series B, 32, 115122.
Stephens, M.A. (1974). EDF Statistics for Goodness of Fit and Some Comparisons. Journal of the American Statistical Association 69, 730737.
Stephens, M.A. (1986a). Tests Based on EDF Statistics. In D'Agostino, R. B., and M.A. Stevens, eds. GoodnessofFit Techniques. Marcel Dekker, New York.
Thode Jr., H.C. (2002). Testing for Normality. Marcel Dekker, New York.
USEPA. (2015). ProUCL Version 5.1.002 Technical Guide. EPA/600/R07/041, October 2015. Office of Research and Development. U.S. Environmental Protection Agency, Washington, D.C.
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.
Wilk, M.B., and S.S. Shapiro. (1968). The Joint Assessment of Normality of Several Independent Samples. Technometrics, 10(4), 825839.
Zar, J.H. (2010). Biostatistical Analysis. Fifth Edition. PrenticeHall, Upper Saddle River, NJ.
See Also
rosnerTest
, gof.object
, print.gof
,
plot.gof
,
shapiro.test
, ks.test
, chisq.test
,
Normal, Lognormal, Lognormal3,
ZeroModified Normal, ZeroModified Lognormal (Delta),
enorm
, elnorm
, elnormAlt
,
elnorm3
, ezmnorm
, ezmlnorm
,
ezmlnormAlt
, qqPlot
.
Examples
# Generate 20 observations from a gamma distribution with
# parameters shape = 2 and scale = 3 then run various
# goodnessoffit tests.
# (Note: the call to set.seed lets you reproduce this example.)
set.seed(47)
dat < rgamma(20, shape = 2, scale = 3)
# ShapiroWilk generalized goodnessoffit test
#
gof.list < gofTest(dat, distribution = "gamma")
gof.list
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF Based on
# Chen & Balakrisnan (1995)
#
#Hypothesized Distribution: Gamma
#
#Estimated Parameter(s): shape = 1.909462
# scale = 4.056819
#
#Estimation Method: mle
#
#Data: dat
#
#Sample Size: 20
#
#Test Statistic: W = 0.9834958
#
#Test Statistic Parameter: n = 20
#
#Pvalue: 0.970903
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
dev.new()
plot(gof.list)
#
# Redo the example above, but use the biascorrected mle
gofTest(dat, distribution = "gamma",
est.arg.list = list(method = "bcmle"))
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF Based on
# Chen & Balakrisnan (1995)
#
#Hypothesized Distribution: Gamma
#
#Estimated Parameter(s): shape = 1.656376
# scale = 4.676680
#
#Estimation Method: bcmle
#
#Data: dat
#
#Sample Size: 20
#
#Test Statistic: W = 0.9834346
#
#Test Statistic Parameter: n = 20
#
#Pvalue: 0.9704046
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
#
# KomogorovSmirnov goodnessoffit test (prespecified parameters)
#
gofTest(dat, test = "ks", distribution = "gamma",
param.list = list(shape = 2, scale = 3))
#Results of GoodnessofFit Test
#
#
#Test Method: KolmogorovSmirnov GOF
#
#Hypothesized Distribution: Gamma(shape = 2, scale = 3)
#
#Data: dat
#
#Sample Size: 20
#
#Test Statistic: ks = 0.2313878
#
#Test Statistic Parameter: n = 20
#
#Pvalue: 0.2005083
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma(shape = 2, scale = 3)
# Distribution.
#
# ProUCL Version of KomogorovSmirnov goodnessoffit test
# for a Gamma Distribution (estimated parameters)
#
gofTest(dat, test = "proucl.ks.gamma", distribution = "gamma")
#Results of GoodnessofFit Test
#
#
#Test Method: ProUCL KolmogorovSmirnov Gamma GOF
#
#Hypothesized Distribution: Gamma
#
#Estimated Parameter(s): shape = 1.909462
# scale = 4.056819
#
#Estimation Method: MLE
#
#Data: dat
#
#Sample Size: 20
#
#Test Statistic: D = 0.0988692
#
#Test Statistic Parameter: n = 20
#
#Critical Values: D.0.01 = 0.228
# D.0.05 = 0.196
# D.0.10 = 0.180
#
#Pvalue: >= 0.10
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
#
# Chisquared goodnessoffit test (estimated parameters)
#
gofTest(dat, test = "chisq", distribution = "gamma", n.classes = 4)
#Results of GoodnessofFit Test
#
#
#Test Method: Chisquare GOF
#
#Hypothesized Distribution: Gamma
#
#Estimated Parameter(s): shape = 1.909462
# scale = 4.056819
#
#Estimation Method: mle
#
#Data: dat
#
#Sample Size: 20
#
#Test Statistic: Chisquare = 1.2
#
#Test Statistic Parameter: df = 1
#
#Pvalue: 0.2733217
#
#Alternative Hypothesis: True cdf does not equal the
# Gamma Distribution.
#
# Clean up
rm(dat, gof.list)
graphics.off()
#
# Example 102 of USEPA (2009, page 1014) gives an example of
# using the ShapiroWilk test to test the assumption of normality
# for nickel concentrations (ppb) in groundwater collected over
# 4 years. The data for this example are stored in
# EPA.09.Ex.10.1.nickel.df.
EPA.09.Ex.10.1.nickel.df
# Month Well Nickel.ppb
#1 1 Well.1 58.8
#2 3 Well.1 1.0
#3 6 Well.1 262.0
#4 8 Well.1 56.0
#5 10 Well.1 8.7
#6 1 Well.2 19.0
#7 3 Well.2 81.5
#8 6 Well.2 331.0
#9 8 Well.2 14.0
#10 10 Well.2 64.4
#11 1 Well.3 39.0
#12 3 Well.3 151.0
#13 6 Well.3 27.0
#14 8 Well.3 21.4
#15 10 Well.3 578.0
#16 1 Well.4 3.1
#17 3 Well.4 942.0
#18 6 Well.4 85.6
#19 8 Well.4 10.0
#20 10 Well.4 637.0
# Test for a normal distribution:
#
gof.list < gofTest(Nickel.ppb ~ 1, data = EPA.09.Ex.10.1.nickel.df)
gof.list
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF
#
#Hypothesized Distribution: Normal
#
#Estimated Parameter(s): mean = 169.5250
# sd = 259.7175
#
#Estimation Method: mvue
#
#Data: Nickel.ppb
#
#Data Source: EPA.09.Ex.10.1.nickel.df
#
#Sample Size: 20
#
#Test Statistic: W = 0.6788888
#
#Test Statistic Parameter: n = 20
#
#Pvalue: 2.17927e05
#
#Alternative Hypothesis: True cdf does not equal the
# Normal Distribution.
dev.new()
plot(gof.list)
#
# Test for a lognormal distribution:
#
gofTest(Nickel.ppb ~ 1, data = EPA.09.Ex.10.1.nickel.df,
dist = "lnorm")
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF
#
#Hypothesized Distribution: Lognormal
#
#Estimated Parameter(s): meanlog = 3.918529
# sdlog = 1.801404
#
#Estimation Method: mvue
#
#Data: Nickel.ppb
#
#Data Source: EPA.09.Ex.10.1.nickel.df
#
#Sample Size: 20
#
#Test Statistic: W = 0.978946
#
#Test Statistic Parameter: n = 20
#
#Pvalue: 0.9197735
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
#
# Test for a lognormal distribution, but use the
# Mean and CV parameterization:
#
gofTest(Nickel.ppb ~ 1, data = EPA.09.Ex.10.1.nickel.df,
dist = "lnormAlt")
#Results of GoodnessofFit Test
#
#
#Test Method: ShapiroWilk GOF
#
#Hypothesized Distribution: Lognormal
#
#Estimated Parameter(s): mean = 213.415628
# cv = 2.809377
#
#Estimation Method: mvue
#
#Data: Nickel.ppb
#
#Data Source: EPA.09.Ex.10.1.nickel.df
#
#Sample Size: 20
#
#Test Statistic: W = 0.978946
#
#Test Statistic Parameter: n = 20
#
#Pvalue: 0.9197735
#
#Alternative Hypothesis: True cdf does not equal the
# Lognormal Distribution.
#
# Clean up
rm(gof.list)
graphics.off()
#
# Generate 20 observations from a normal distribution with mean=3 and sd=2, and
# generate 10 observaions from a normal distribution with mean=2 and sd=2 then
# test whether these sets of observations come from the same distribution.
# (Note: the call to set.seed simply allows you to reproduce this example.)
set.seed(300)
dat1 < rnorm(20, mean = 3, sd = 2)
dat2 < rnorm(10, mean = 1, sd = 2)
gofTest(x = dat1, y = dat2, test = "ks")
#Results of GoodnessofFit Test
#
#
#Test Method: 2Sample KS GOF
#
#Hypothesized Distribution: Equal
#
#Data: x = dat1
# y = dat2
#
#Sample Sizes: n.x = 20
# n.y = 10
#
#Test Statistic: ks = 0.7
#
#Test Statistic Parameters: n = 20
# m = 10
#
#Pvalue: 0.001669561
#
#Alternative Hypothesis: The cdf of 'dat1' does not equal
# the cdf of 'dat2'.
#
# Clean up
rm(dat1, dat2)