---
title: "A Post Hoc Analysis for Pearson's Chi-Squared Test for Count Data"
author: "Daniel Ebbert"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A Post Hoc Analysis for Pearson's Chi-Squared Test for Count Data}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(chisq.posthoc.test)
```

## Introduction

When computing Pearson's Chi-squared Test for Count Data the only result you get is that you know that there is a significant difference in the data and not which parts of the data are responsible for this. Here you see the example from the chisq.test documentation.

```{r chisq_test}
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(gender = c("F", "M"),
                    party = c("Democrat","Independent", "Republican"))
chisq.test(M)
```

## Standarized residuals

As a form of post hoc analysis the standarized residuals can be analysed. A rule of thumb is that standarized residuals of above two show significance.

```{r chisq_residuals}
chisq.results <- chisq.test(M)
chisq.results$stdres
```

## Post Hoc Analysis

However, the above two rule is a rule of thumb. These standarized residuals can be used to calculate p-values, which is what this package is designed for as shown in the following example.

```{r chisq_post_hoc}
chisq.posthoc.test(M,
                   method = "bonferroni")
```
