Inference for Two-Way Tables
Most of the software packages (except Excel and TI calculators) want the data for the two-way table entered in the following format:
For a video that shows how to use Excel and the formulas with an example, see the Excel Video Technology Manual: Chi-Square Two-Way Test.
For a video that shows how to use JMP here with an example, see the JMP Video Technology Manual: Chi-Square Two-Way Test.
For more information and an example, see the Minitab Video Technology Manual: Chi-Square Two-Way Test.
For more information and an example, see the SPSS Video Technology Manual: Chi-Square Two-Way Test. The example with summarized data starts about 3:10 into the video (the preceding portion is for raw data).
For more information (and an example), see the Crunchit! Help Video: Chi-Square Two-Way Test.
For more information and an example, see the TI-83/-84 Video Technology Manual: Chi-Square Two-Way Test.
With raw data, use the table function to create a table:
> Table (datasetname) -> twoway.name
where “name” is a name you give the table.
Follow that with
> chisq.test(twoway.name)
With summarized data, use the command
> xtabs (Count ~ rowvar + colvar) -> twoway.name
where those are the variables to be treated as rows (or columns) of the output matrix).
Follow this with
> chisq.test(twoway.name)
In either case, to see the expected counts, use the command
> results$exp
For more information and an example, see the R Video Technology Manual: Chi-Square Two-Way Test.
Goodness of Fit
Place the cursor in an empty cell (say, B15) and sum the observed counts using the command
= sum(B1:Bn)
where n is the last row of counts.
Compute the expected counts by placing the cursor at the top of an empty column (say, D) using the command
=C1*B$15
Calculate the parts of the Chi-square statistic by placing the cursor at the top of a new column (say, E) using the command
=(B1-D1)^2/D1
Sum the parts for the statistic.
=sum(E1:En)
For a video that shows how to use JMP here with an example, see the JMP Video Technology Manual: Chi-Square GOF Test.
Minitab’s default is to provide two charts: the first is a bar graph of contributions to the chi-square statistic; the second compares observed and expected counts. If you do not want to see those, click “Graphs” and uncheck the boxes.
For more information and an example, see the Minitab Video Technology Manual: Chi-square GOF Test.
For more information (and an example), see the Crunchit! Help Video: Chi-Square Goodness of Fit Test.
Obtain the P-value: 2ndVARS8 gives the χ2CDF shell. Enter the test statistic value just obtained, infinity, and the degrees of freedom (categories – 1) separated by commas. Practically speaking, any “large” positive number will work as infinity. An example of the command with 4 categories is shown below.
χ2CDF(2.345,99999,3)
For more information and an example, see the TI Video Technology Manual: Chi-square GOF Test.
Use chisq.test(obs,p=probs) to perform the test. An example is shown below.
> act<-c(15,25,40,60)
> pr<-c(0.1,0.2,0.3,0.4)
> chisq.test(act,p=pr)
Chi-squared test for given probabilities
data: act
X-squared = 0.7738, df = 3, p-value = 0.8557
For more information and an example, see the R Video Technology Manual: Chi-square Goodness of Fit Test.