gofTwoSample.object {EnvStats}R Documentation

S3 Class "gofTwoSample"


Objects of S3 class "gofTwoSample" are returned by the EnvStats function gofTest when both the x and y arguments are supplied.


Objects of S3 class "gofTwoSample" are lists that contain information about the assumed distribution, the estimated or user-supplied distribution parameters, and the test statistic and p-value.


Required Components
The following components must be included in a legitimate list of class "gofTwoSample".


a character string with the value "Equal".


a numeric scalar with a names attribute containing the name and value of the goodness-of-fit statistic.


a numeric scalar containing the number of non-missing observations in the sample used for the goodness-of-fit test.


numeric vector with a names attribute containing the name(s) and value(s) of the parameter(s) associated with the test statistic given in the statistic component.


numeric scalar containing the p-value associated with the goodness-of-fit statistic.


character string indicating the alternative hypothesis.


character string indicating the name of the goodness-of-fit test.


a list of length 2 containing the numeric vectors actually used for the goodness-of-fit test (i.e., the original data but with any missing or infinite values removed).


a character vector of length 2 indicating the name of the data object used for the x argument and the name of the data object used for the y argument in the goodness-of-fit test.

Optional Component
The following component is included when the arguments x and/or y contain missing (NA), undefined (NaN) and/or infinite (Inf, -Inf) values.


numeric vector of length 2 indicating the number of missing (NA), undefined (NaN) and/or infinite (Inf, -Inf) values that were removed from the data in the x and y arguments prior to performing the goodness-of-fit test.


Generic functions that have methods for objects of class "gofTwoSample" include:
print, plot.


Since objects of class "gofTwoSample" are lists, you may extract their components with the $ and [[ operators.


Steven P. Millard (EnvStats@ProbStatInfo.com)

See Also

print.gofTwoSample, plot.gofTwoSample, Goodness-of-Fit Tests.


  # Create an object of class "gofTwoSample", then print it out. 

  # 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.)

  dat1 <- rnorm(20, mean = 3, sd = 2) 
  dat2 <- rnorm(10, mean = 1, sd = 2) 
  gofTest(x = dat1, y = dat2, test = "ks")

  #Results of Goodness-of-Fit Test
  #Test Method:                     2-Sample K-S 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
  #P-value:                         0.001669561
  #Alternative Hypothesis:          The cdf of 'dat1' does not equal
  #                                 the cdf of 'dat2'.

  # Clean up

  rm(dat1, dat2)

[Package EnvStats version 2.8.1 Index]