Tests if a set of data points is uniformly distributed over a specified interval [a,b].
chisq.unif.test(x, bins=NULL, interval=c(0,1), min.bin.size=10, all.inside=TRUE,
rightmost.closed=TRUE, ...)
A list with class “htest” containing the following components:
the value of the test statistic.
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).
the p-value of the test.
a character string indicating what type of test was performed.
a character string giving the name of the data.
The number of bins used for the test.
The minimum bin size.
The interval used for the test.
A numeric vector of data values.
If specified, the number of bins to use to discretise the interval. Otherwise, the number of bins will be chosen automatically.
A two-element vector giving the support of the uniform distribution. The
default is c(0,1)
.
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.
Determines if data points outside the interval should be counted as belonging to the extremal bins. The default is TRUE.
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
.
The arguments all.inside and rightmost.closed are included for experimentation and should be altered with caution.
Andrew Hart and Servet Martínez
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.
chisq.test
, findInterval
, ks.unif.test
#Generate an IID uniform(0,1) sequence
u <- runif(1000)
chisq.unif.test(u)
Run the code above in your browser using DataLab