Pollard homework 8

### Pollard homework sheet 8

#### Due: Thursday 5 November

(8.1)
Rearrange the data from Homework problem 6.2 into a 2-by-12 (or 12-by-2) table, containing the counts of summonses not delivered and counts of summonses (presumed) delivered for each month. (The total numbers of summonses mailed for each month should then be one of the marginal totals for the table.)

1. Carry out the chi-square test for no-association between month of delivery and fate of the summons (delivered or not).
2. Generate tables of ``expected'' values and the table of ``chi'' values.
3. What does the table of chi values suggest about the lack of fit of the no-association model? (The model asserts a constant probability, across months, for a summons to be delivered.)

(8.2)
For this problem you will simulate observations on a categorical variable, and calculate the X^2 statistic many times. The aim is to produce a histogram for the X^2 distribution, and maybe even compare it with the appropriate chi-square.

1. Put values 1,2, ..., k in column C1, for a k of your choosing. (I used k=4.) Put probabilities p1, p2,...,pk, of your choosing in column c2, making sure that they sum to one. Generate many samples of size n (I used n=100 for testing purposes, but you might like a larger n), from the discrete distribution defined by c1 and c2, then determine the counts in each category. Calculate the X^2 statistic for each of the many repetitions, and display them with a density histogram.

[The macro shown below seems to work reasonably well. You will need to adapt it to your purposes.]

2. Draw the density function for the chi-square distribution on k-1 degrees of freedom. [One way: Fill a column with numbers like 0, 0.1,0.2,0.3,...; use the calc menu to calculate the density at those points; use plot, with points connected, to draw a smooth curve.]
```gmacro
hw8
# c1 contains values for discrete distribution, c2 contains probabilities

# generate samples of size 100 from the discrete distribution
# do it 7 times, storing in c4-c10
Random 100 c4-c10;
Discrete C1 C2.

# get a tally of the counts, overwrite columns c4-c10
do k100 =1:7
let k99 = k100 + 3
stats ck99;
count ck99;
by ck99.

# calculate X^2, save values in c3
let c3(k100) = sum((ck99 - 100*c2)**2/(100*c2))

enddo
endmacro

```