### 20.5.4 Testing a distribution with the χ2 distribution

The chisquaret command will use the χ2 test to compare sample data to a specified distribution.

- chisquaret takes one mandatory argument and a sequence of optional arguments:
  - L, a list of sample data.
  - Optionally, distr. This can be one of
    - The name of a distribution (see Section 20.3.4 for a list of distributions and their parameters).
    - Another list of sample data.
    By default this will be the uniform distribution.
  - params, the parameters of the distribution distr or the symbol classes and optionally cmin and cdim, the minimum size and default size of a statistics class (by default, class_min and class_size, which themselves default to 0 and 1; see Section 2.5.8).
- chisquaret(L ⟨,distr ⟩) returns the result of the χ2 test between sample data and the named distribution or two sample data lists.

#### Examples

chisquaret([57,54])

Guessing data is the list of number of elements in each class, adequation to uniform distribution
Sample adequation to a finite discrete probability distribution
Chi2 test result 0.0810810810811,
reject adequation if superior to chisquare_icdf(1,0.95)=3.84145882069 or chisquare_icdf(1,1-alpha) if alpha!=5%

0.0810810810811 |  |  |  |  |  |  |  |  |  |

chisquaret([1,1,1,1,1,0,0,1,0,1,1],[.4,.6])

Sample adequation to a finite discrete probability distribution
Chi2 test result 0.742424242424,
reject adequation if superior to chisquare_icdf(1,0.95)=3.84145882069 or chisquare_icdf(1,1-alpha) if alpha!=5%

0.742424242424 |  |  |  |  |  |  |  |  |  |

chisquaret(ranv(1000,binomial,10,.5),binomial)

Binomial: estimating n and p from data 10 0.5055
Sample adequation to binomial(10,0.5055,.), Chi2 test result 7.77825189838,
reject adequation if superior to chisquare_icdf(7,0.95)=14.0671404493 or chisquare_icdf(7,1-alpha) if alpha!=5%

7.77825189838 |  |  |  |  |  |  |  |  |  |

chisquaret(ranv(1000,binomial,10,.5),binomial,11,.5)

Sample adequation to binomial(11,0.5,.), Chi2 test result 125.617374161,
reject adequation if superior to chisquare_icdf(10,0.95)=18.3070380533 or chisquare_icdf(10,1-alpha) if alpha!=5%

125.617374161 |  |  |  |  |  |  |  |  |  |

As an example using class_min and class_size:

L:=ranv(1000,normald,0,.2):; chisquaret(L,normald,classes,-2,.25)

or (setting class_min to −2 and class_size to −0.25 in the graphical configuration):

chisquaret(L,normald,classes)

Normal density, estimating mean and stddev from data -0.00345919752912 0.201708100832
Sample adequation to normald_cdf(-0.00345919752912,0.201708100832,.), Chi2 test result 2.11405080381,
reject adequation if superior to chisquare_icdf(4,0.95)=9.48772903678 or chisquare_icdf(4,1-alpha) if alpha!=5%

2.11405080381 |  |  |  |  |  |  |  |  |  |

In this last case, you are given the value of d2 of the statistic D2=∑j=1k (nj−ej)/ej, where k is the number of sample classes for classes(L,-2,0.25) (or classes(L)), nj is the size of the jth class, and ej= n pj where n is the size of L and pj is the probability of the jth class interval assuming a normal distribution with the mean and population standard deviation of L.