File: repl.txt

package info (click to toggle)
node-stdlib 0.0.96%2Bds1%2B~cs0.0.429-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 421,476 kB
  • sloc: javascript: 1,562,831; ansic: 109,702; lisp: 49,823; cpp: 27,224; python: 7,871; sh: 6,807; makefile: 6,089; fortran: 3,102; awk: 387
file content (133 lines) | stat: -rw-r--r-- 4,251 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

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

    A chi-square goodness-of-fit test is computed for the null hypothesis that
    the values of `x` come from the discrete probability distribution specified
    by `y`.

    The second argument can either be expected frequencies, population
    probabilities summing to one, or a discrete probability distribution name to
    test against.

    When providing a discrete probability distribution name, distribution
    parameters *must* be supplied as additional arguments.

    The function returns an object containing the test statistic, p-value, and
    decision.

    By default, the p-value is computed using a chi-square distribution with
    `k-1` degrees of freedom, where `k` is the length of `x`.

    If provided distribution arguments are estimated (e.g., via maximum
    likelihood estimation), the degrees of freedom should be corrected. Set the
    `ddof` option to use `k-1-n` degrees of freedom, where `n` is the degrees of
    freedom adjustment.

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

    Instead of relying on chi-square approximation to calculate the p-value, one
    can use Monte Carlo simulation. When the `simulate` option is `true`, the
    simulation is performed by re-sampling from the discrete probability
    distribution specified by `y`.

    Parameters
    ----------
    x: ndarray|Array<number>|TypedArray
        Observation frequencies.

    y: ndarray|Array<number>|TypedArray|string
        Expected frequencies, population probabilities, or a discrete
        probability distribution name.

    args: ...number (optional)
        Distribution parameters. Distribution parameters will be passed to a
        probability mass function (PMF) as arguments.

    options: Object (optional)
        Options.

    options.alpha: number (optional)
        Significance level of the hypothesis test. Must be on the interval
        [0,1]. Default: 0.05.

    options.ddof: number (optional)
        Delta degrees of freedom adjustment. Default: 0.

    options.simulate: boolean (optional)
        Boolean indicating whether to calculate p-values by Monte Carlo
        simulation. The simulation is performed by re-sampling from the discrete
        distribution specified by `y`. Default: false.

    options.iterations: number (optional)
        Number of Monte Carlo iterations. Default: 500.

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

    out.alpha: number
        Significance level.

    out.rejected: boolean
        Test decision.

    out.pValue: number
        Test p-value.

    out.statistic: number
        Test statistic.

    out.df: number|null
        Degrees of freedom.

    out.method: string
        Test name.

    out.toString: Function
        Prints formatted output.

    out.toJSON: Function
        Serializes results as JSON.

    Examples
    --------
    // Provide expected probabilities...
    > var x = [ 89, 37, 30, 28, 2 ];
    > var p = [ 0.40, 0.20, 0.20, 0.15, 0.05 ];
    > var out = {{alias}}( x, p );
    > var o = out.toJSON()
    { 'pValue': ~0.0406, 'statistic': ~9.9901, ... }
    > out.toString()

    // Set significance level...
    > var opts = { 'alpha': 0.01 };
    > out = {{alias}}( x, p, opts );
    > out.toString()

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

    // Verify that data comes from Poisson distribution...
    > var lambda = 3.0;
    > var rpois = {{alias:@stdlib/random/base/poisson}}.factory( lambda );
    > var len = 400;
    > x = [];
    > for ( var i = 0; i < len; i++ ) { x.push( rpois() ); };

    // Generate a frequency table...
    > var freqs = new {{alias:@stdlib/array/int32}}( len );
    > for ( i = 0; i < len; i++ ) { freqs[ x[ i ] ] += 1; };
    > out = {{alias}}( freqs, 'poisson', lambda );
    > out.toString()

    See Also
    --------