here is a Haskell program that calculates the chi-squared test statistic from a list of integers on standard input delimited by whitespace, testing the hypothesis that the input integers are number of occurrences of independent and identically distributed (IID) samples from a discrete uniform distribution. the mathematical heavy lifting is done by the statistics Haskell package.
suppose we roll a d3 die 51 times and get 10, 11, and 30 as the number of occurrences of each face, "observations" in the language of chi-squared tests. the "expected outcome" is 51/3 = (17, 17, 17). the probability of a result as skewed as our observation or worse coming from a fair die is 0.00056959. our die is probably not fair.
$ echo '10 11 30' | ./chi-square-uniform
n 3
sum 51
chi^2 14.941176470588236
mkPValue 5.69593143522451e-4
instead, consider 33 rolls distributed (10, 11, 12):
$ echo '10 11 12' | ./chi-square-uniform
n 3
sum 33
chi^2 0.18181818181818182
mkPValue 0.9131007162822623
the hypothesis of fair die is not rejected.
No comments:
Post a Comment