Data Analysis with Chi Square Test of Independence: Life expectancy Against Income per Person Using SAS
Here I am using the GapMinder dataset and examine the effects of different categories of income per person on life expectancy using Chi Square Test of Independence.
In particular, I am interested to statistically establish the answer the below question:
Do categories of life expectancy (high/low) vary significantly among the various categories of income per person.
To approach this, I have chosen the below Hypothesis between my categorical explanatory variable (income per person, collapsed into three categories: Very Low, Low and High) and my categorical response variable (life expectancy, collapsed into two categories: High and Low):
H0 : Life expectancy among all categories of income per person are the same
Ha : Life expectancy among all categories of income per person are not the same
The Null Hypothesis (H0), if accepted, signifies that life expectancy across the different categories of income per person are same, and therefore there is no significant relationship between these two variables.
The Alternate Hypothesis (Ha), if accepted, signifies that life expectancy across the different categories of income per person are not same, and therefore there is evidence of significant relationship between these two variables.
Since my categorical variable, income per person, will have more than two categories, the alternate hypothesis, if accepted, will not be able to determine exactly which categories are significantly different from others. In that case, I will also need to perform Post Hoc test to determine the significantly different categories. For Chi Square, unfortunately there is no easy one-shot post hoc test, therefore, I will be running pairwise Chi Square on the different categories of the explanatory variable to determine which pairs show significant difference.
In order to keep Type 1 error under check, I will be applying Bonferroni’s Correction for the p-value while deciding whether or not to reject the null hypothesis. In my case, three categories of the explanatory variable would result in 3 separate pairwise test, so I’ll use threshold α = 0.05 / 3 = 0.017 for the post hoc test.
Here is the code snippet in SAS:
Program Output
Chi Square Test on all categories
Pairwise Post Hoc (income per person category 1 and 2)
Pairwise Post Hoc (income per person category 1 and 3)
Pairwise Post Hoc (income per person category 2 and 3)
Observations from Chi Square Output
1. The categorical variable icpp_cat (income per person categories) has five categories represented as:
a. 1: Very Low (0 to 1000)
b. 2: Low (1000 to 5000)
c. 3: High (more than 5000)
2. The categorical response variable le_cat (life expectancy) has two categories
a. 0 : Low (less than 60 years)
b. 1 : High (more than 60 years)
3. Out of the 213 available data points 186 were considered for analysis (23 values were missing)
4. The Chi Square process calculated p value < 0.0001 which is much less than the threshold of α = 0.05. Therefore, we have enough evidence to reject the null hypothesis (H0) and accept the alternate hypothesis (Ha).
5. As a result, Chi Square Test revealed that income per person (collapsed into 3 categories) and life expectancy are significantly associated.
6. However, it does not deterministically tell us which categories are different. That can be arrived at from the post hoc test.
Observations from Post Hoc Test
1. Post Hoc between icpp_cat 1 and 2 (Very Low and Low) produces p value < 0.0001 which is much less than α = 0.017 (with Bonferroni’s correction). So, we reject the null hypothesis that that they are same and conclude that these two categories show different life expectancy.
2. Post Hoc between icpp_cat 1 and 3 (Very Low and High) produces p value < 0.0001 which is much less than α = 0.017 (with Bonferroni’s correction). So, we reject the null hypothesis that that they are same and conclude that these two categories show different life expectancy.
3. Post Hoc between icpp_cat 2 and 3 (Low and High) produces p value = 0.8331 which is much higher than α = 0.017 (with Bonferroni’s correction). So, we cannot reject the null hypothesis and conclude that these two categories show same life expectancy.
In summary, the post hoc test reveals income per person categories 2 and 3 (Low and High) are not significantly different in terms of life expectancy. However, category 1 (Very Low) is significantly different from categories 2 and 3 and have a much lower life expectancy.

















