chisq.detail.RdPrints out the details of the computations involved in a chi-squared test on a table. Includes the expected values and the chi-squared contribution of each cell.
chisq.detail(tab)This function prints out the input table along with the expected value for each cell under the null hypothesis. It also prints out the chi-squared contribution of each cell in the same pattern as the table. This shows the computations involved and one rule of thumb is to look for these values that are greater than 4 as a post-hoc analysis.
This function is used primarily for its side effect of printing the results, but does return invisibly a list with the following components:
A matrix of the observed values, same as tab.
A matrix of the expected values under the null hypothesis.
A matrix of the chi-squared contributions of each cell.
The chi-squared test statistic.
~put references to the literature/web site here ~ Moore, bps
chisq.test,loglin,
xtabs, table, prop.table,
CrossTable from the gmodels package.
chisq.detail(HairEyeColor[,,1])
#>
#>
#> observed
#> expected
#>
#> Brown Blue Hazel Green Total
#> Black 32 11 10 3 56
#> 19.67 20.27 9.43 6.62
#>
#> Brown 53 50 25 15 143
#> 50.23 51.77 24.09 16.91
#>
#> Red 10 10 7 7 34
#> 11.94 12.31 5.73 4.02
#>
#> Blond 3 30 5 8 46
#> 16.16 16.65 7.75 5.44
#>
#> Total 98 101 47 33 279
#>
#>
#> Cell Contributions
#> Brown Blue Hazel Green
#> Black 7.73 + 4.24 + 0.03 + 1.98 +
#> Brown 0.15 + 0.06 + 0.03 + 0.22 +
#> Red 0.32 + 0.43 + 0.28 + 2.21 +
#> Blond 10.71 + 10.70 + 0.98 + 1.20 = 41.28
#>
#> df = 9 P-value = 0
#>
chisq.detail(HairEyeColor[,,2])
#>
#>
#> observed
#> expected
#>
#> Brown Blue Hazel Green Total
#> Black 36 9 5 2 52
#> 20.27 18.94 7.64 5.15
#>
#> Brown 66 34 29 14 143
#> 55.74 52.08 21.02 14.16
#>
#> Red 16 7 7 7 37
#> 14.42 13.48 5.44 3.66
#>
#> Blond 4 64 5 8 81
#> 31.57 29.50 11.90 8.02
#>
#> Total 122 114 46 31 313
#>
#>
#> Cell Contributions
#> Brown Blue Hazel Green
#> Black 12.21 + 5.22 + 0.91 + 1.93 +
#> Brown 1.89 + 6.28 + 3.03 + 0.00 +
#> Red 0.17 + 3.11 + 0.45 + 3.04 +
#> Blond 24.08 + 40.34 + 4.00 + 0.00 = 106.66
#>
#> df = 9 P-value = 0
#>