repl.txt (2029B)
1 2 {{alias}}( x[, options] ) 3 Performs a chi-square independence test. 4 5 For a two-way contingency table `x` (represented as a two-dimensional 6 `ndarray` or `array` of `arrays`), the null hypothesis that the joint 7 distribution of the cell counts is the product of the row and column 8 marginals is tested, i.e. whether the row and column variables are 9 independent. 10 11 The function returns an object containing the test statistic, p-value, and 12 decision. 13 14 Parameters 15 ---------- 16 x: (MatrixLike|Array<Array>) 17 Two-way table of cell counts. 18 19 options: Object (optional) 20 Options. 21 22 options.alpha: number (optional) 23 Significance level of the hypothesis test. Must be on the interval 24 [0,1]. Default: 0.05. 25 26 options.correct: boolean (optional) 27 Boolean indicating whether to use Yates' continuity correction when 28 provided a 2x2 contingency table. Default: true. 29 30 Returns 31 ------- 32 out: Object 33 Test result object. 34 35 out.alpha: number 36 Significance level. 37 38 out.rejected: boolean 39 Test decision. 40 41 out.pValue: number 42 Test p-value. 43 44 out.statistic: number 45 Test statistic. 46 47 out.df: number 48 Degrees of freedom. 49 50 out.expected: ndarray 51 Expected cell counts. 52 53 out.method: string 54 Test name. 55 56 out.print: Function 57 Function to print formatted output. 58 59 Examples 60 -------- 61 // Provide expected probabilities... 62 > var x = [ [ 20, 30 ], [ 30, 20 ] ]; 63 > var out = {{alias}}( x ) 64 { 'rejected': false, 'pValue': ~0.072, 'statistic': 3.24, ... } 65 > out.print() 66 67 // Set significance level... 68 > var opts = { 'alpha': 0.1 }; 69 > out = {{alias}}( x, opts ) 70 { 'rejected': true, 'pValue': ~0.072, 'statistic': 3.24, ... } 71 > out.print() 72 73 // Disable Yates' continuity correction (primarily used with small counts): 74 > opts = { 'correct': false }; 75 > out = {{alias}}( x, opts ) 76 {...} 77 78 See Also 79 -------- 80