"chi2gof": "\nchi2gof( x, y[, ...params][, opts] )\n Performs a chi-square goodness-of-fit test.\n\n For an array or typed array of integers `x`, a chi-square goodness-of-fit is\n computed for the null hypothesis that the values of `x` come from the\n discrete distribution specified by `y`. `y` can be an `array` of expected\n frequencies, an `array` of population probabilities that sum to one, or a\n string with the name of the discrete distribution to test against. In the\n latter case, the parameters of the distribution must be supplied as\n additional arguments after `y`. The function returns an object holding the\n calculated test statistic, the p-value of the test, as well as the test\n decision.\n\n By default, the p-value is computed using a chi-square distribution with\n `k - 1` degrees of freedom, where `k` is the number of levels of `x`. In\n case distribution parameters were estimated for the calculation of `y`, the\n degrees of freedom have to be corrected. The `ddof` option can be set to use\n `n - ddof - 1` degrees of freedom.\n\n The chi-square approximation may be incorrect if the observed or expected\n frequencies in each category are too small. It is common to require\n frequencies greater than five.\n\n Instead of relying on the chi-square approximation when calculating the\n p-value, Monte Carlo simulation can be used. To do so, set the `simulate`\n option. The simulation is carried out by resampling from the discrete\n distribution given by `y`. By default, `500` iterations are used for the\n simulation. To set a custom number of iterations, use the `iterations`\n option.\n\n Parameters\n ----------\n x: Array<number>\n Observation frequencies.\n\n y: Array<number>|string\n Array of expected values or probabilities or a string denoting the name\n of a distribution.\n\n params: ...number (optional)\n Distribution parameters passed to mean function.\n\n options: Object (optional)\n Options.\n\n options.alpha: number (optional)\n Number in the interval `[0,1]` giving the significance level of the\n hypothesis test. Default: `0.05`.\n\n options.ddof: number (optional)\n Nonnegative integer giving the \"delta degrees of freedom\" adjustment.\n Default: `0`.\n\n options.simulate: boolean (optional)\n Boolean indicating whether to compute p-values by Monte Carlo\n simulation. The simulation is carried out by resampling from the\n discrete distribution given by `p`. Default: `false`.\n\n options.iterations: number (optional)\n Positive integer specifying the number of Monte Carlo iterations.\n Default: `500`.\n\n Returns\n -------\n out: Object\n Test result object.\n\n out.alpha: number\n Used significance level.\n\n out.rejected: boolean\n Test decision.\n\n out.pValue: number\n P-value of the test.\n\n out.statistic: number\n Value of test statistic.\n\n out.df: number\n Degrees of freedom.\n\n out.method: string\n Name of test.\n\n out.print: function\n Function to print formatted output.\n\n Examples\n --------\n // Use probabilities for `y`:\n > var x = [ 89, 37, 30, 28, 2 ];\n > var p = [ 0.40, 0.20, 0.20, 0.15, 0.05 ];\n > var out = chi2gof( x, p )\n { 'pValue': ~0.0406, 'statistic': ~9.9901, ... }\n > var table = out.print()\n Null hypothesis: population probabilities are equal to those in p\n pValue: 0.0406\n statistic: 9.9901\n degrees of freedom: 4\n Test Decision: Reject null in favor of alternative at 5% significance level\n\n // Set significance level:\n > out = chi2gof( x, p, { 'alpha': 0.01 });\n > table = out.print()\n Chi-square goodness-of-fit test\n\n Null hypothesis: population probabilities are equal to those in p\n\n pValue: 0.0406\n statistic: 9.9901\n degrees of freedom: 4\n\n Test Decision: Fail to reject null in favor of alternative at 1%\n significance level\n\n // Calculate the p-value via Monte Carlo simulation:\n > var x = [ 89, 37, 30, 28, 2 ];\n > var p = [ 0.40, 0.20, 0.20, 0.15, 0.05 ];\n > var out = chi2gof( x, p, { 'simulate': true, 'iterations': 1000 })\n {...}\n\n // Verify that data comes from Poisson distribution:\n > var lambda = 3.0;\n > var rpois = base.random.poisson.factory( lambda );\n > var len = 400;\n > x = new Array( len );\n > for ( var i = 0; i < len; i++ ) { x[ i ] = rpois(); }\n // Generate frequency table:\n > var freqs = [];\n > for ( i = 0; i < len; i++ ) {\n ... val = x[ i ];\n ... freqs[ val ] === void 0 ? freqs[ val ] = 1 : freqs[ val ] += 1;\n ... }\n // Fill holes in array:\n > for ( i = 0; i < freqs.length; i++ ) {\n ... if ( freqs[ i ] === void 0 ) { freqs[ i ] = 0; }\n ... }\n > out = chi2gof( freqs, 'poisson', lambda );\n {...}\n\n",
0 commit comments