
{{alias}}( x, y[, ...params][, opts] )
    Performs a chi-square goodness-of-fit test.

    For an array or typed array of integers `x`, a chi-square goodness-of-fit is
    computed for the null hypothesis that the values of `x` come from the
    discrete distribution specified by `y`. `y` can be an `array` of expected
    frequencies, an `array` of population probabilities that sum to one, or a
    string with the name of the discrete distribution to test against. In the
    latter case, the parameters of the distribution must be supplied as
    additional arguments after `y`. The function returns an object holding the
    calculated test statistic, the p-value of the test, as well as the test
    decision.

    By default, the p-value is computed using a chi-square distribution with
    `k - 1` degrees of freedom, where `k` is the number of levels of `x`. In
    case distribution parameters were estimated for the calculation of `y`, the
    degrees of freedom have to be corrected. The `ddof` option can be set to use
    `n - ddof - 1` degrees of freedom.

    The chi-square approximation may be incorrect if the observed or expected
    frequencies in each category are too small. It is common to require
    frequencies greater than five.

    Instead of relying on the chi-square approximation when calculating the
    p-value, Monte Carlo simulation can be used. To do so, set the `simulate`
    option. The simulation is carried out by resampling from the discrete
    distribution given by `y`. By default, `500` iterations are used for the
    simulation. To set a custom number of iterations, use the `iterations`
    option.

    Parameters
    ----------
    x: Array<number>
        Observation frequencies.

    y: Array<number>|string
         Array of expected values or probabilities or a string denoting the name
         of a distribution.

    params: ...number (optional)
        Distribution parameters passed to mean function.

    options: Object (optional)
        Options.

    options.alpha: number (optional)
        Number in the interval `[0,1]` giving the significance level of the
        hypothesis test. Default: `0.05`.

    options.ddof: number (optional)
        Nonnegative integer giving the "delta degrees of freedom" adjustment.
        Default: `0`.

    options.simulate: boolean (optional)
        Boolean indicating whether to compute p-values by Monte Carlo
        simulation. The simulation is carried out by resampling from the
        discrete distribution given by `p`. Default: `false`.

    options.iterations: number (optional)
        Positive integer specifying the number of Monte Carlo iterations.
        Default: `500`.

    Returns
    -------
    out: Object
        Test result object.

    out.alpha: number
        Used significance level.

    out.rejected: boolean
        Test decision.

    out.pValue: number
        p-value of the test.

    out.statistic: number
        Value of test statistic.

    out.df: number
        Degrees of freedom.

    out.method: string
        Name of test.

    out.print: function
        Function to print formatted output.

    Examples
    --------
    // Use probabilities for `y`:
    > var x = [ 89, 37, 30, 28, 2 ];
    > var p = [ 0.40, 0.20, 0.20, 0.15, 0.05 ];
    > var out = {{alias}}( x, p )
    { 'pValue': ~0.0406, 'statistic': ~9.9901, ... }
    > var table = out.print()
    Null hypothesis: population probabilities are equal to those in p
        pValue: 0.0406
        statistic: 9.9901
        degrees of freedom: 4
    Test Decision: Reject null in favor of alternative at 5% significance level

    // Set significance level:
    > out = {{alias}}( x, p, { 'alpha': 0.01 });
    > table = out.print()
    Chi-square goodness-of-fit test

    Null hypothesis: population probabilities are equal to those in p

        pValue: 0.0406
        statistic: 9.9901
        degrees of freedom: 4

    Test Decision: Fail to reject null in favor of alternative at 1%
    significance level

    // Calculate the p-value via Monte Carlo simulation:
    > var x = [ 89, 37, 30, 28, 2 ];
    > var p = [ 0.40, 0.20, 0.20, 0.15, 0.05 ];
    > var out = {{alias}}( x, p, { 'simulate': true, 'iterations': 1000 })
    {...}

    // Verify that data comes from Poisson distribution:
    > var lambda = 3.0;
    > var rpois = {{alias:@stdlib/random/base/poisson}}.factory( lambda );
    > var len = 400;
    > x = new Array( len );
    > for ( var i = 0; i < len; i++ ) { x[ i ] = rpois(); }
    // Generate frequency table:
    > var freqs = [];
    > for ( i = 0; i < len; i++ ) {
    ...     val = x[ i ];
    ...     freqs[ val ] === void 0 ? freqs[ val ] = 1 : freqs[ val ] += 1;
    ... }
    // Fill holes in array:
    > for ( i = 0; i < freqs.length; i++ ) {
    ...     if ( freqs[ i ] === void 0 ) { freqs[ i ] = 0; }
    ... }
    > out = {{alias}}( freqs, 'poisson', lambda );
    {...}

    See Also
    --------

