Previous Up Next

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.

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 (njej)/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.


Previous Up Next