Previous Up Next

7.5.4  Testing a distribution with the χ2 distribution: chisquaret

The chisquaret command will use the χ2 test to compare sample data to a specified distribution. You need to provide chisquaret with the following arguments:

  1. A list of sample data.
  2. The name of a distribution, or another list of sample data. If this is omitted, a uniform distribution will be used.
  3. The parameters of the distribution, if a name is given as the previous argument, or the parameter class followed by class_min and class_dim (or the default values will be used).

The chisquaret command will return the result of the χ2 test between the sample data and the named distribution or the two sample data.

For example, if you enter

chisquaret([57,54])

you will get

  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

If you enter

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

you will get

   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

If you enter

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

you will get

   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

and if you enter

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

you will get

   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

For an example using class_min and class_dim, let

L := ranv(1000,normald,0,.2)

If you then enter

chisquaret(L,normald,classes,-2,.25)

or equivalently set class_min to −2 and class_dim to −0.25 in the graphical configuration and enter

chisquaret(L,normald,classes)

you will get

   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