## The Chi-Squared Test of Independence – An Example in Both R and SAS

August 25, 2014 5 Comments

#### Introduction

The **chi-squared test of independence** is one of the most basic and common hypothesis tests in the statistical analysis of categorical data. Given 2 categorical random variables, and , the chi-squared test of independence determines whether or not there exists a statistical dependence between them. Formally, it is a hypothesis test with the following null and alternative hypotheses:

If you’re not familiar with **probabilistic independence** and how it manifests in **categorical random variables**, watch my video on calculating expected counts in contingency tables using **joint and marginal probabilities**. For your convenience, here is another video that gives a gentler and more practical understanding of calculating expected counts using **marginal proportions** and **marginal totals**.

Today, I will continue from those 2 videos and illustrate how the chi-squared test of independence can be implemented in both R and SAS with the same example.

## Recent Comments