IMSL_N_PARAMETERS_ESTIMATED, intn_parameters (Input) The number of parameters estimated in computing the cumulative distribution function.
IMSL_CUTPOINTS, float**p_cutpoints (Output) The address of a pointer to the cutpoints array. On return, the pointer is initialized (through a memory allocation request to malloc), and the array is stored there. Typically, float*p_cutpoints is declared; &p_cutpoints is used as an argument to this function; and imsl_free(p_cutpoints) is used to free this array.
IMSL_CUTPOINTS_USER, floatcutpoints[] (Input or Output) Array with n_categories− 1 components containing the vector of cutpoints defining the cell intervals. The intervals defined by the cutpoints are such that the lower endpoint is not included, and the upper endpoint is included in any interval. If IMSL_CUTPOINTS_EQUAL is specified, equal probability cutpoints are computed and returned in cutpoints.
IMSL_CUTPOINTS_EQUAL If IMSL_CUTPOINTS_USER is specified, then equal probability cutpoints can still be used if, in addition, the IMSL_CUTPOINTS_EQUAL option is specified. If IMSL_CUTPOINTS_USER is not specified, equal probability cutpoints are used by default.
IMSL_CHI_SQUARED, float*chi_squared (Output) If specified, the chi-squared test statistic is returned in *chi_squared.
IMSL_DEGREES_OF_FREEDOM, float*df (Output) If specified, the degrees of freedom for the chi-squared goodness-of-fit test is returned in *df.
IMSL_FREQUENCIES, floatfrequencies[] (Input) Array with n_observations components containing the vector frequencies for the observations stored in x.
IMSL_BOUNDS, floatlower_bound, floatupper_bound (Input) If IMSL_BOUNDS is specified, then lower_bound is the lower bound of the range of the distribution, and upper_bound is the upper bound of this range. 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 the range of these bounds are ignored. Distributions conditional on a range can be specified when IMSL_BOUNDS is used. By convention, lower_bound is excluded from the first interval, but upper_bound is included in the last interval.
IMSL_CELL_COUNTS, float**p_cell_counts (Output) The address of a pointer to an array containing the cell counts. The cell counts are the observed frequencies in each of the n_categories cells. On return, the pointer is initialized (through a memory allocation request to malloc), and the array is stored there. Typically, float*p_cell_counts is declared; &p_cell_counts is used as an argument to this function; and imsl_free(p_cell_counts) is used to free this array.
IMSL_CELL_COUNTS_USER, floatcell_counts[] (Output) If specified, the n_categories cell counts are returned in the array cell_counts provided by the user.
IMSL_CELL_EXPECTED, float**p_cell_expected (Output) The address of a pointer to the cell expected values. The expected value of a cell is the expected count in the cell given that the hypothesized distribution is correct. On return, the pointer is initialized (through a memory allocation request to malloc), and the array is stored there. Typically, float*p_cell_expected is declared; &p_cell_expected is used as an argument to this function; and imsl_free(p_cell_expected) is used to free this array.
IMSL_CELL_EXPECTED_USER, floatcell_expected[] (Output) If specified, the n_categories cell expected values are returned in the array cell_expected provided by the user.
IMSL_CELL_CHI_SQUARED, float**p_cell_chi_squared (Output) The address of a pointer to an array of length n_categories containing the cell contributions to chi-squared. On return, the pointer is initialized (through a memory allocation request to malloc), and the array is stored there. Typically, float*p_cell_chi_squared is declared; &p_cell_chi_squared is used as an argument to this function; and imsl_free(p_cell_chi_squared) is used to free this array.
IMSL_CELL_CHI_SQUARED_USER, floatcell_chi_squared[] (Output) If specified, the cell contributions to chi-squared are returned in the array cell_chi_squared provided by the user.
IMSL_FCN_W_DATA, float user_proc_cdf (floaty, void*data), void*data, (Input) User supplied function that returns the hypothesized, cumulative distribution function at the point y, which also accepts a pointer to data that is supplied by the user. data is a pointer to the data to be passed to the user-supplied function. See Passing Data to User-Supplied Functions in the introduction to this manual for more details.
Description
The function imsl_f_chi_squared_test 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 via the user-defined function user_proc_cdf. Because the user is allowed to give a range for the observations, a test conditional upon the specified range is performed.
Argument n_categories gives the number of intervals into which the observations are to be divided. By default, equiprobable intervals are computed by imsl_f_chi_squared_test, but intervals that are not equiprobable can be specified (through the use of optional argument IMSL_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_f_chi_squared_test cannot determine the discrete elements in discrete distributions.
By default, the lower and upper endpoints of the first and last intervals are −∞ and +∞, respectively. If IMSL_BOUNDS is specified, the endpoints are defined by the user via the two arguments lower_bound and upper_bound.
A tally of counts is maintained for the observations in x as follows. If the cutpoints are specified by the user, the tally is made in the interval to which xi belongs using the endpoints specified by the user. If the cutpoints are determined by imsl_f_chi_squared_test, then the cumulative probability at xi, F(xi), is computed via the function user_proc_cdf. The tally for xi is made in interval number
and is the function that takes the greatest integer that is no larger than the argument of the function. Thus, if the computer time required to calculate the cumulative distribution function is large, user-specified cutpoints may be preferred 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.
On some platforms, imsl_f_chi_squared_test can evaluate the user-supplied function user_proc_cdf in parallel. This is done only if the function imsl_omp_options is called to flag user-defined functions as thread-safe. A function is thread-safe if there are no dependencies between calls. Such dependencies are usually the result of writing to global or static variables
Programming Notes
The user must supply a function user_proc_cdf with calling sequence user_proc_cdf(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 Special Functions can be used for user_proc_cdf, either directly, if the calling sequence is correct, or indirectly, if, for example, the sample means and standard deviations are to be used in computing the theoretical cumulative distribution function.
Examples
Example 1
This example illustrates the use of imsl_f_chi_squared_test on a randomly generated sample from the normal distribution. One-thousand randomly generated observations are tallied into 10 equiprobable intervals. The null hypothesis that the sample is from a normal distribution is specified by use of the imsl_f_normal_cdf (see Special Functions) as the hypothesized distribution function. In this example, the null hypothesis is not rejected.
imsl_f_write_matrix ("Cell Contributions to Chi-Squared", 1,
N_CATEGORIES, cell_chi_squared,
0);
}
Output
Chi Squared Statistics
chi-squared 13.18
degrees of freedom 9.00
p-value 0.15
Cut Points
1 2 3 4 5 6
-1.282 -0.842 -0.524 -0.253 -0.000 0.253
7 8 9
0.524 0.842 1.282
Cell Counts
1 2 3 4 5 6
106 109 89 92 83 87
7 8 9 10
110 104 121 99
Cell Contributions to Chi-Squared
1 2 3 4 5 6
0.36 0.81 1.21 0.64 2.89 1.69
7 8 9 10
1.00 0.16 4.41 0.01
Example 3
In this example, a discrete Poisson random sample of size 1000 with parameter θ = 5.0 is generated via function imsl_f_random_poisson. In the call to imsl_f_chi_squared_test, function imsl_f_poisson_cdf is used as function user_proc_cdf.
The function user_proc_cdf 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 one.
IMSL_INCORRECT_CDF_2
The function user_proc_cdf is not a cumulative distribution function. The probability of the range of the distribution is not positive.
IMSL_INCORRECT_CDF_3
The function user_proc_cdf 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.
IMSL_INCORRECT_CDF_4
The function user_proc_cdf is not a cumulative distribution function. Its evaluation at a cutpoint is inconsistent with either the evaluation at the lower or upper bound.
IMSL_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.
IMSL_STOP_USER_FCN
Request from user supplied function to stop algorithm. User flag = "#".