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

Details

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.

Methods

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

Value

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

distribution

a character string with the value "Equal".

statistic

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

sample.size

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

parameters

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.

p.value

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

alternative

character string indicating the alternative hypothesis.

method

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

data

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

data.name

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.

bad.obs

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.

Note

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

Author

Steven P. Millard (EnvStats@ProbStatInfo.com)

Examples

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

  set.seed(300) 
  dat1 <- rnorm(20, mean = 3, sd = 2) 
  dat2 <- rnorm(10, mean = 1, sd = 2) 
  gofTest(x = dat1, y = dat2, test = "ks")
#> $distribution
#> [1] "Equal"
#> 
#> $statistic
#>  ks 
#> 0.7 
#> 
#> $sample.size
#> n.x n.y 
#>  20  10 
#> 
#> $parameters
#>  n  m 
#> 20 10 
#> 
#> $p.value
#> [1] 0.001669561
#> 
#> $alternative
#> [1] "The cdf of 'dat1' does not equal\n                                 the cdf of 'dat2'."
#> 
#> $method
#> [1] "2-Sample K-S GOF"
#> 
#> $data
#> $data$dat1
#>  [1] 5.7475818 4.7242137 3.9469782 4.4025256 2.8298895 6.1374042 4.6347839
#>  [8] 3.7895372 5.4253971 3.7101613 7.4325484 2.8189192 0.3669438 3.1330696
#> [15] 4.0243452 3.1000595 5.9347944 0.4209590 2.4846170 3.5861026
#> 
#> $data$dat2
#>  [1]  0.3251594  2.2665159  0.3736428  1.2697862 -1.2895102  0.3772036
#>  [7]  1.4698168  3.6773476  0.8012756  3.0737987
#> 
#> 
#> $data.name
#>      x      y 
#> "dat1" "dat2" 
#> 
#> $bad.obs
#> x y 
#> 0 0 
#> 
#> attr(,"class")
#> [1] "gofTwoSample"

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