Test of Uniformity Based on Pearsons's Chi-Squared test

Share:

Description

Tests if a set of data points is uniformly distributed over a specified interval [a,b].

Usage

1
2
chisq.unif.test(x, bins=NULL, interval=c(0,1), min.bin.size=10, all.inside=TRUE, 
rightmost.closed=TRUE, ...)

Arguments

x

A numeric vector of data values.

bins

If specified, the number of bins to use to discretise the interval. Otherwise, the number of bins will be chosen automatically.

interval

A two-element vector giving the support of the uniform distribution. The default is c(0,1).

min.bin.size

The minimum number of data points to have in each bin. If bins cannot be chosen without violating this constraint, an error is generated. The default is 10. This parameter is ignored if bins is specified.

all.inside

Determines if data points outside the interval should be counted as belonging to the extremal bins. The default is TRUE.

rightmost.closed

Determines if data points that coinside withinterval[2] are counted as belonging to the last bin. This parameter only has an effect if all.inside is set to FALSE. The default is TRUE.

...

Additional parameters to be passed to chisq.test.

Details

This function tests the fit of a set of data points to a uniform distribution on [a,b] by partitioning [a,b] into bins bins, counting how many points fall in each bin and then testing that the points are equally distributed among the bins using Pearson's chi-squared test.

When bins is not specified, its value is selected using the following heuristic. Let n be the number of data points. If n>200, then bins is set to 20. Otherwise, bins is set to n/10. Next,while there is a bin containing fewer than min.bin.size points in the resulting partition, bins is decremented by one. This process stops either when bins is equal to 1 or every bin contains at least min.bin.size points.

Value

A list with class “htest” containing the following components:

statistic

the value of the test statistic.

parameter

A vector containing the degrees of freedom of the chi-squared test (df), the left end of the interval (a) and the right end of the interval (b).

p.value

the p-value of the test.

method

a character string indicating what type of test was performed.

data.name

a character string giving the name of the data.

bins

The number of bins used for the test.

min.bin.size

The minimum bin size.

interval

The interval used for the test.

Warning

The arguments all.inside and rightmost.closed are included for experimentation and should be altered with caution.

Author(s)

Andrew Hart and Servet Mart<ed>nez

See Also

chisq.test, findInterval, ks.unif.test

Examples

1
2
3
#Generate an IID uniform(0,1) sequence
u <- runif(1000)
chisq.unif.test(u)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.