The FREQ Procedure

Example 3.5 Analysis of a 2x2 Contingency Table

This example computes chi-square tests and Fisher’s exact test to compare the probability of coronary heart disease for two types of diet. It also estimates the relative risks and computes exact confidence limits for the odds ratio.

The data set FatComp contains hypothetical data for a case-control study of high fat diet and the risk of coronary heart disease. The data are recorded as cell counts, where the variable Count contains the frequencies for each exposure and response combination. The data set is sorted in descending order by the variables Exposure and Response, so that the first cell of the 2 times 2 table contains the frequency of positive exposure and positive response. The FORMAT procedure creates formats to identify the type of exposure and response with character values.

proc format;
   value ExpFmt 1='High Cholesterol Diet'
                0='Low Cholesterol Diet';
   value RspFmt 1='Yes'
                0='No';
run;
data FatComp;
   input Exposure Response Count;
   label Response='Heart Disease';
   datalines;
0 0  6
0 1  2
1 0  4
1 1 11
;
proc sort data=FatComp;
   by descending Exposure descending Response;
run;

In the following PROC FREQ statements, ORDER=DATA option orders the contingency table values by their order in the input data set. The TABLES statement requests a two-way table of Exposure by Response. The CHISQ option produces several chi-square tests, and the RELRISK option produces relative risk measures. The EXACT statement requests the exact Pearson chi-square test and exact confidence limits for the odds ratio.

proc freq data=FatComp order=data;
   format Exposure ExpFmt. Response RspFmt.;
   tables Exposure*Response / chisq relrisk;
   exact pchi or;
   weight Count;
   title 'Case-Control Study of High Fat/Cholesterol Diet';
run;

The contingency table in Output 3.5.1 displays the variable values so that the first table cell contains the frequency for the first cell in the data set (the frequency of positive exposure and positive response).

Output 3.5.1: Contingency Table

Case-Control Study of High Fat/Cholesterol Diet

The FREQ Procedure

Frequency
Percent
Row Pct
Col Pct
Table of Exposure by Response
ExposureResponse(Heart Disease)
YesNoTotal
High Cholesterol Diet
11
47.83
73.33
84.62
4
17.39
26.67
40.00
15
65.22
 
 
Low Cholesterol Diet
2
8.70
25.00
15.38
6
26.09
75.00
60.00
8
34.78
 
 
Total
13
56.52
10
43.48
23
100.00


Output 3.5.2 displays the chi-square statistics. Because the expected counts in some of the table cells are small, PROC FREQ gives a warning that the asymptotic chi-square tests might not be appropriate. In this case, the exact tests are appropriate. The alternative hypothesis for this analysis states that coronary heart disease is more likely to be associated with a high fat diet, and therefore a one-sided test is appropriate. Fisher’s exact right-sided test analyzes whether the probability of heart disease in the high fat group exceeds the probability of heart disease in the low fat group; because this p-value is small, the alternative hypothesis is supported.

The odds ratio, displayed in Output 3.5.3, provides an estimate of the relative risk when an event is rare. This estimate indicates that the odds of heart disease is 8.25 times higher in the high fat diet group; however, the wide confidence limits indicate that this estimate has low precision.

Output 3.5.2: Chi-Square Statistics

StatisticDFValueProb
Chi-Square14.95970.0259
Likelihood Ratio Chi-Square15.09750.0240
Continuity Adj. Chi-Square13.18790.0742
Mantel-Haenszel Chi-Square14.74410.0294
Phi Coefficient 0.4644 
Contingency Coefficient 0.4212 
Cramer's V 0.4644 
WARNING: 50% of the cells have expected counts less than 5.
(Asymptotic) Chi-Square may not be a valid test.

Pearson Chi-Square Test
Chi-Square4.9597
DF1
Asymptotic Pr > ChiSq0.0259
Exact Pr >= ChiSq0.0393

Fisher's Exact Test
Cell (1,1) Frequency (F)11
Left-sided Pr <= F0.9967
Right-sided Pr >= F0.0367
  
Table Probability (P)0.0334
Two-sided Pr <= P0.0393


Output 3.5.3: Relative Risk

Odds Ratio and Relative Risks
StatisticValue95% Confidence Limits
Odds Ratio8.25001.153559.0029
Relative Risk (Column 1)2.93330.850210.1204
Relative Risk (Column 2)0.35560.14030.9009

Odds Ratio
Odds Ratio8.2500
  
Asymptotic Conf Limits 
95% Lower Conf Limit1.1535
95% Upper Conf Limit59.0029
  
Exact Conf Limits 
95% Lower Conf Limit0.8677
95% Upper Conf Limit105.5488


Last updated: April 16, 2025