gofGroupTest(object, ...)
## S3 method for class 'formula':
gofGroupTest(object, data = NULL, subset,
na.action = na.pass, ...)
## S3 method for class 'default':
gofGroupTest(object, group, test = "sw",
distribution = "norm", est.arg.list = NULL, 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",
data.name = NULL, group.name = NULL, parent.of.data = NULL,
subset.expression = NULL, ...)
## S3 method for class 'data.frame':
gofGroupTest(object, ...)
## S3 method for class 'matrix':
gofGroupTest(object, ...)
## S3 method for class 'list':
gofGroupTest(object, ...)
distribution
. In the default method,
the argument object
must be a numeric vector.
When object
object
is a formula, data
specifies an optional data frame, list or
environment (or object coercible by as.data.frame
to a data frame) containing the
variables in the model. If not found in data
object
is a formula, subset
specifies an optional vector specifying
a subset of observations to be used.object
is a formula, na.action
specifies a function which indicates
what should happen when the data contain NA
s. The default is na.pass
.object
is a numeric vector, group
is a factor or character vector
indicating which group each observation belongs to. When object
is a matrix or data frame
this argument is ignored and the columns define"sw"
(Shapiro-Wilk; the default), "sf"
(Shapiro-Francia),
"ppcc"
(Probability Plot Correlation CoefficDistribution.df
for a list of distributions and their abbreviations.
The default value is distributio
test="sw"
and
distribution="gamma"
, setting est.arg.list=list(method="bcmle")
test="chisq"
, the number of cells into which the observations
within each group are to be allocated. If the argument cut.points
is supplied,
then n.classes
is set to length(cut.points
test="chisq"
, a vector of cutpoints that defines the cells for each
group of observations.
The element x[i]
is allocated to cell j
if
cut.points[j]
< x[i]
$\le$ test="ks"
or test="chisq"
,
a list with values for the parameters of the specified distribution. See the help file
for Distribution.df
for the namtest="ks"
or test="chisq"
,
a logical scalar indicating whether to perform the goodness-of-fit test based on
estimating the distribution parameters (estimate.params=TRUE
) or using the
usetest="ks"
or test="chisq"
,
an integer indicating the number of parameters estimated from the data.
If estimate.params=TRUE
, the default value is the number of parameters associated
with thtest="chisq"
, a logical scalar indicating whether to use the
continuity correction. The default value is correct=FALSE
unless
n.classes=2
..Options$digits
.test="ks"
, exact=NULL
by default, but can be set to
a logical scalar indicating whether an exact p-value should be computed.
See the help file for ks.test
data.name=deparse(substitute(object))
.group.name=deparse(substitute(group))
."gofGroup"
containing the results of the group goodness-of-fit test.
Objects of class "gofGroup"
have special printing and plotting methods.
See the help file for gofGroup.object
for details.gofGroupTest
performs a goodness-of-fit test for each group of
data by calling the function gofTest
. Using the p-values from these
goodness-of-fit tests, it then calls the function gofTest
with the
argument test="ws"
to test whether the p-values appear to come from a
Uniform [0,1] distribution.gofTest
, gofGroup.object
, print.gofGroup
,
plot.gofGroup
, qqPlot
.# Example 10-4 of USEPA (2009, page 10-20) gives an example of
# simultaneously testing the assumption of normality for nickel
# concentrations (ppb) in groundwater collected at 4 monitoring
# wells over 5 months. 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 at each well:
#--------------------------------------------
gofGroup.list <- gofGroupTest(Nickel.ppb ~ Well,
data = EPA.09.Ex.10.1.nickel.df)
gofGroup.list
#Results of Group Goodness-of-Fit Test
#-------------------------------------
#
#Test Method: Wilk-Shapiro GOF (Normal Scores)
#
#Hypothesized Distribution: Normal
#
#Data: Nickel.ppb
#
#Grouping Variable: Well
#
#Data Source: EPA.09.Ex.10.1.nickel.df
#
#Number of Groups: 4
#
#Sample Sizes: Well.1 = 5
# Well.2 = 5
# Well.3 = 5
# Well.4 = 5
#
#Test Statistic: z (G) = -3.658696
#
#P-values for
#Individual Tests: Well.1 = 0.03510747
# Well.2 = 0.02385344
# Well.3 = 0.01120775
# Well.4 = 0.10681461
#
#P-value for
#Group Test: 0.0001267509
#
#Alternative Hypothesis: At least one group
# does not come from a
# Normal Distribution.
dev.new()
plot(gofGroup.list)
#----------
# Test for a lognormal distribution at each well:
#-----------------------------------------------
gofGroupTest(Nickel.ppb ~ Well, data = EPA.09.Ex.10.1.nickel.df,
dist = "lnorm")
#Results of Group Goodness-of-Fit Test
#-------------------------------------
#
#Test Method: Wilk-Shapiro GOF (Normal Scores)
#
#Hypothesized Distribution: Lognormal
#
#Data: Nickel.ppb
#
#Grouping Variable: Well
#
#Data Source: EPA.09.Ex.10.1.nickel.df
#
#Number of Groups: 4
#
#Sample Sizes: Well.1 = 5
# Well.2 = 5
# Well.3 = 5
# Well.4 = 5
#
#Test Statistic: z (G) = 0.2401720
#
#P-values for
#Individual Tests: Well.1 = 0.6898164
# Well.2 = 0.6700394
# Well.3 = 0.3208299
# Well.4 = 0.5041375
#
#P-value for
#Group Test: 0.5949015
#
#Alternative Hypothesis: At least one group
# does not come from a
# Lognormal Distribution.
#----------
# Clean up
rm(gofGroup.list)
graphics.off()
Run the code above in your browser using DataLab