Welcome to the Harris Geospatial product documentation center. Here you will find reference guides, help documents, and product libraries.


  >  Docs Center  >  IDL Reference  >  Advanced Math and Stats  >  IMSL_CHISQTEST

IMSL_CHISQTEST

IMSL_CHISQTEST

The IMSL_CHISQTEST function performs a chi-squared goodness-of-fit test.



Syntax


Result = IMSL_CHISQTEST(f, n_categories, x [, CELL_COUNTS=variable] [, CELL_EXPECTED=variable] [, CELL_CHISQ=variable] [, CHI_SQUARED=variable] [, CUTPOINTS=variable] [, DF=variable]
[, /DOUBLE] [, /EQUAL_CUTPOINTS] [, FREQUENCIES=variable] [, LOWER_BOUND=value] [, N_PARAMS_ESTIMATED=value] [, UPPER_BOUND=value] [, USED_CUTPOINTS=variable])

Return Value


The p-value for the goodness-of-fit chi-squared statistic.

Arguments


f

Scalar string specifying a user-supplied function. Function f accepts one scalar parameter and returns the hypothesized, cumulative distribution function at that point.

n_categories

Number of cells into which the observations are to be tallied.

x

One-dimensional array containing the vector of data elements for this test.

Keywords


CELL_COUNTS

Named variable into which the cell counts are stored. The cell counts are the observed frequencies in each of the n_categories cells.

CELL_EXPECTED

Named variable into which the cell expected values are stored. The expected value of a cell is the expected count in the cell given that the hypothesized distribution is correct.

CELL_CHISQ

Named variable into which an array of length n_categories containing the cell contributions to chi-squared are stored.

CHI_SQUARED

Named variable into which the chi-squared test statistic is stored.

CUTPOINTS

Specifies the named variable containing user-defined cutpoints to be used by IMSL_CHISQTEST. Keywords Cutpoints and Equal_Cutpoints cannot be used together.

DF

Named variable into which the degrees of freedom for the chi-squared goodness-of-fit test are stored.

DOUBLE

If present and nonzero, double precision is used.

EQUAL_CUTPOINTS

If present and nonzero, equal probability cutpoints are used. Keywords Equal_Cutpoints and Cutpoints cannot be used together.

FREQUENCIES

Named variable into which the array containing the vector frequencies for the observations stored in x is stored.

LOWER_BOUND

Lower bound of the range of the distribution. If Lower Bound = Upper Bound, a range on the whole real line is used (the default). If the lower and upper endpoints are different, points outside of the range of these bounds are ignored. Distributions conditional on a range can be specified when Lower_Bound and Upper_Bound are used. If Lower_Bound is specified, then Upper_Bound also must be specified. By convention, Lower_Bound is excluded from the first interval, but Upper_Bound is included in the last interval.

N_PARAMS_ESTIMATED

Number of parameters estimated in computing the cumulative distribution function.

UPPER_BOUND

Upper bound of the range of the distribution. If Lower Bound = Upper Bound, a range on the whole real line is used (the default). If the lower and upper endpoints are different, points outside of the range of these bounds are ignored. Distributions conditional on a range can be specified when Lower_Bound and Upper_Bound are used. If Upper_Bound is specified, then Lower_Bound also must be specified. By convention, Lower_Bound is excluded from the first interval, but Upper_Bound is included in the last interval.

USED_CUTPOINTS

Specifies the named variable into which the cutpoints to be used by IMSL_CHISQTEST are stored.

Discussion


The IMSL_CHISQTEST function performs a chi-squared goodness-of-fit test that a random sample of observations is distributed according to a specified theoretical cumulative distribution. The theoretical distribution, which may be continuous, discrete, or a mixture of discrete and continuous distributions, is specified by defined function f. Because you are allowed to give a range for the observations, a test that is conditional upon the specified range is performed.

Parameter n_categories gives the number of intervals into which the observations are to be divided. By default, equi-probable intervals are computed by IMSL_CHISQTEST, but intervals that are not equi-probable can be specified (through the use of keyword Cutpoints).

Regardless of the method used to obtain the cutpoints, the intervals are such that the lower endpoint is not included in the interval, while the upper endpoint is always included. If the cumulative distribution function has discrete elements, then user-provided cutpoints should always be used since IMSL_CHISQTEST cannot determine the discrete elements in discrete distributions.

By default, the lower and upper endpoints of the first and last intervals are –infinity and +infinity. The endpoints can be specified by using the keywords Lower_Bound and Upper_Bound.

A tally of counts is maintained for the observations in x as follows:

  • If the cutpoints are specified, the tally is made in the interval to which xi belongs using the endpoints specified.
  •  

  • If the cutpoints are determined by IMSL_CHISQTEST, then the cumulative probability at xi, F(xi), is computed by the function f.

The tally for xi is made in interval number:

where m = n categories and:

is the function that takes the greatest integer that is no larger than the parameter of the function. Thus, if the computer time required to calculate the cumulative distribution function is large, user-specified cutpoints may be preferred in order to reduce the total computing time.

If the expected count in any cell is less than 1, then a rule of thumb is that the chi-squared approximation may be suspect. A warning message to this effect is issued in this case, as well as when an expected value is less than 5.

Programming Notes

You must supply a function f with calling sequence F(y) that returns the value of the cumulative distribution function at any point y in the (optionally) specified range.

Many of the cumulative distribution functions in this reference manual can be used for f. It is, however, necessary to write a user-defined IDL Analyst function that calls the CDF, and then pass the name of this user-defined function for f.

Example


This example illustrates the use of IMSL_CHISQTEST on a randomly generated sample from the normal distribution. One-thousand randomly generated observations are tallied into 10 equi-probable intervals. In this example, the null hypothesis is not rejected.

.RUN  
; Define the hypothesized, cumulative distribution function.
FUNCTION user_cdf, k
   RETURN, IMSL_NORMALCDF(k)
END

IMSL_RANDOMOPT, Set = 123457
x = IMSL_RANDOM(1000, /Normal)
; Generate normal deviates.
p_value = IMSL_CHISQTEST(';user_cdf', 10, x)
; Perform chi-squared test.
PM, p_value

; Output the results.
0.154603

Errors


Warning Errors

STAT_EXPECTED_VAL_LESS_THAN_1—An expected value is less than 1.

STAT_EXPECTED_VAL_LESS_THAN_5—An expected value is less than 5.

Fatal Errors

STAT_ALL_OBSERVATIONS_MISSING—All observations contain missing values.

STAT_INCORRECT_CDF_1—Function f is not a cumulative distribution function. The value at the lower bound must be nonnegative, and the value at the upper bound must not be greater than 1.

STAT_INCORRECT_CDF_2—Function f is not a cumulative distribution function. The probability of the range of the distribution is not positive.

STAT_INCORRECT_CDF_3—Function f is not a cumulative distribution function. Its evaluation at an element in x is inconsistent with either the evaluation at the lower or upper bound.

STAT_INCORRECT_CDF_4—Function f is not a cumulative distribution function. Its evaluation at a cutpoint is inconsistent with either the evaluation at the lower or upper bound.

STAT_INCORRECT_CDF_5—An error has occurred when inverting the cumulative distribution function. This function must be continuous and defined over the whole real line.

Version History


6.4
Introduced



© 2018 Harris Geospatial Solutions, Inc. |  Privacy Policy
My Account    |    Store    |    Contact Us