Example 28.5: Creating an Output Data Set Containing Chi-Square Statistics
This example uses the Color data from Example 28.1
to output the Pearson chi-square and the likelihood-ratio
chi-square statistics to a SAS data set. The following
statements create a two-way table of eye color versus hair
color.
proc freq data=Color order=data;
weight Count;
tables Eyes*Hair / chisq expected cellchi2 norow nocol;
output out=ChiSqData pchi lrchi n nmiss;
title 'Chi-Square Tests for 3 by 5 Table of Eye and Hair Color';
run;
proc print data=ChiSqData noobs;
title 'Chi-Square Statistics for Eye and Hair Color';
title2 'Output Data Set from the FREQ Procedure';
run;
The CHISQ option produces chi-square tests, the
EXPECTED option displays expected cell frequencies in the
table, and the CELLCHI2 option displays the cell
contribution to the chi-square. The NOROW and NOCOL options
suppress the display of row and column percents in the
table.
The OUTPUT statement creates the ChiSqData data set with
eight variables: the N option stores the number of
nonmissing observations, the NMISS option stores the
number of missing observations, and the PCHI and LRCHI options
store Pearson and likelihood-ratio chi-square statistics,
respectively, together with their degrees of freedom and
p-values.
The preceding statements produce Output 28.5.1 through
Output 28.5.2.
Output 28.5.1: Contingency Table
Chi-Square Tests for 3 by 5 Table of Eye and Hair Color |
Frequency Expected Cell Chi-Square Percent |
|
Table of Eyes by Hair |
Eyes(Eye Color |
Hair(Hair Color) |
Total |
fair |
red |
medium |
dark |
black |
blue |
69 66.425 0.0998 9.06 |
28 32.921 0.7357 3.67 |
68 63.22 0.3613 8.92 |
51 53.024 0.0772 6.69 |
6 6.4094 0.0262 0.79 |
222 29.13 |
green |
69 59.543 1.5019 9.06 |
38 29.51 2.4422 4.99 |
55 56.671 0.0492 7.22 |
37 47.53 2.3329 4.86 |
0 5.7454 5.7454 0.00 |
199 26.12 |
brown |
90 102.03 1.4187 11.81 |
47 50.568 0.2518 6.17 |
94 97.109 0.0995 12.34 |
94 81.446 1.935 12.34 |
16 9.8451 3.8478 2.10 |
341 44.75 |
Total |
228 29.92 |
113 14.83 |
217 28.48 |
182 23.88 |
22 2.89 |
762 100.00 |
|
|
Output 28.5.2: Chi-Square Statistics
Chi-Square Tests for 3 by 5 Table of Eye and Hair Color |
Statistics for Table of Eyes by Hair |
Statistic |
DF |
Value |
Prob |
Chi-Square |
8 |
20.9248 |
0.0073 |
Likelihood Ratio Chi-Square |
8 |
25.9733 |
0.0011 |
Mantel-Haenszel Chi-Square |
1 |
3.7838 |
0.0518 |
Phi Coefficient |
|
0.1657 |
|
Contingency Coefficient |
|
0.1635 |
|
Cramer's V |
|
0.1172 |
|
|
The contingency table in Output 28.5.1 displays eye and hair
color in the order in which they appear in the Color
data set. The Pearson chi-square statistic in Output 28.5.2
provides evidence of an association between eye and hair
color (p=0.0073).
The cell chi-square values show that most of
the association is due to more green-eyed children with fair
or red hair and fewer with dark or black hair. The
opposite occurs with the brown-eyed children.
Output 28.5.3: Output Data Set
Chi-Square Statistics for Eye and Hair Color |
Output Data Set from the FREQ Procedure |
N |
NMISS |
_PCHI_ |
DF_PCHI |
P_PCHI |
_LRCHI_ |
DF_LRCHI |
P_LRCHI |
762 |
0 |
20.9248 |
8 |
.007349898 |
25.9733 |
8 |
.001061424 |
|
The OUT= data set is displayed in Output 28.5.3. It
contains one observation with the sample size, the number of
missing values, and the chi-square statistics and
corresponding degrees of freedom and p-values as in
Output 28.5.2.
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.