Original Program from program editor.
******************************************************************;
*** Two varieties of a particular moth species occur in two ***;
*** colors (brown and white). A biologist in North Carolina ***;
*** wants to know if the distribution of the two varieties ***;
*** differs with the area of the state. He collects ***;
*** individuals from each region of the state and note the ***;
*** number of each variety. ***;
******************************************************************;
options nocenter ps=256 ls=99 nodate nonumber nolabel;
title1 'Examples of Chi square tests';
title2 'Chi square test of independence';
data one;
input color $ area $ number;
cards; run;
White west 92
White central 12
White east 37
Brown west 8
Brown central 4
Brown east 18
;
proc print; title3 'Data listing';
run;
proc freq; title3 'Proc Freq without weight statement';
tables color*area;
run;
proc freq; title3 'Chi square analysis using Proc Freq';
weight number;
tables color*area / chisq expected cellchi2 norow nocol nopercent;
run;
****************************************************************************;
*** Testing for a Mendalian ration of 9 : 6 : 1 in a breeding experiment ***;
****************************************************************************;
options nocenter ps=60 ls=78 nodate nonumber;
title1 'Examples of Chi square tests';
title2 'Chi square goodness of fit test';
data GoodFit;
input color $ number;
cards; run;
red 153
pink 72
white 17
;
proc print data=GoodFit; title3 'Raw Data listing';
run;
proc freq data=GoodFit order=data; weight number;
title3 'Chi square analysis using Proc Freq';
tables color / chisq nocum testp=(0.5625 0.3750 0.0625);
run;
******************************************************************;
*** A sample of fishes from North Carolina swamp streams ***;
*** revealed 47 male Flier sunfish and 59 females. Test the ***;
*** hypothesis that the population contains equal numbers of ***;
*** males and females ***;
******************************************************************;
options nocenter ps=60 ls=78 nodate nonumber;
title1 'Examples of Chi square tests';
title2 'Chi square of equal proportions';
data EqualP;
input sex $ number;
cards; run;
Female 59
Male 47
;
proc print data=EqualP; title3 'Raw Data listing';
run;
proc freq data=EqualP; weight number;
title3 'Chi square analysis using Proc Freq';
tables sex / chisq expected cellchi2 binomial;
run;
Below is output from the SAS log (bold) and output from the SAS Output window.
1 ******************************************************************;
2 *** Two varieties of a particular moth species occur in two ***;
3 *** colors (brown and white). A biologist in North Carolina ***;
4 *** wants to know if the distribution of the two varieties ***;
5 *** differs with the area of the state. He collects ***;
6 *** individuals from each region of the state and note the ***;
7 *** number of each variety. ***;
8 ******************************************************************;
9
10 options nocenter ps=256 ls=99 nodate nonumber nolabel;
11 title1 'Examples of Chi square tests';
12 title2 'Chi square test of independence';
13 data one;
14 input color $ area $ number;
15 cards;
NOTE: The data set WORK.ONE has 6 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
15 ! run;
22 ;
23 proc print; title3 'Data listing';
24 run;
NOTE: There were 6 observations read from the data set WORK.ONE.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Examples of Chi square tests
Chi square test of independence
Data listing
Obs color area number
1 White west 92
2 White central 12
3 White east 37
4 Brown west 8
5 Brown central 4
6 Brown east 18
25
26 proc freq; title3 'Proc Freq without weight statement';
27 tables color*area;
28 run;
NOTE: There were 6 observations read from the data set WORK.ONE.
NOTE: The PROCEDURE FREQ printed page 2.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Examples of Chi square tests
Chi square test of independence
Proc Freq without weight statement
The FREQ Procedure
Table of color by area
color area
Frequency|
Percent |
Row Pct |
Col Pct |central |east |west | Total
---------+--------+--------+--------+
Brown | 1 | 1 | 1 | 3
| 16.67 | 16.67 | 16.67 | 50.00
| 33.33 | 33.33 | 33.33 |
| 50.00 | 50.00 | 50.00 |
---------+--------+--------+--------+
White | 1 | 1 | 1 | 3
| 16.67 | 16.67 | 16.67 | 50.00
| 33.33 | 33.33 | 33.33 |
| 50.00 | 50.00 | 50.00 |
---------+--------+--------+--------+
Total 2 2 2 6
33.33 33.33 33.33 100.00
30 proc freq; title3 'Chi square analysis using Proc Freq';
31 weight number;
32 tables color*area / chisq expected cellchi2 norow nocol nopercent;
33 run;
NOTE: There were 6 observations read from the data set WORK.ONE.
NOTE: The PROCEDURE FREQ printed page 3.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Examples of Chi square tests
Chi square test of independence
Chi square analysis using Proc Freq
The FREQ Procedure
Table of color by area
color area
Frequency |
Expected |
Cell Chi-Square|central |east |west | Total
---------------+--------+--------+--------+
Brown | 4 | 18 | 8 | 30
| 2.807 | 9.6491 | 17.544 |
| 0.507 | 7.2273 | 5.1919 |
---------------+--------+--------+--------+
White | 12 | 37 | 92 | 141
| 13.193 | 45.351 | 82.456 |
| 0.1079 | 1.5377 | 1.1047 |
---------------+--------+--------+--------+
Total 16 55 100 171
Statistics for Table of color by area
Statistic DF Value Prob
------------------------------------------------------
Chi-Square 2 15.6764 0.0004
Likelihood Ratio Chi-Square 2 15.5329 0.0004
Mantel-Haenszel Chi-Square 1 10.6004 0.0011
Phi Coefficient 0.3028
Contingency Coefficient 0.2898
Cramer's V 0.3028
Sample Size = 171
35
36 ****************************************************************************;
37 *** Testing for a Mendalian ration of 9 : 6 : 1 in a breeding experiment ***;
38 ****************************************************************************;
39 options nocenter ps=60 ls=78 nodate nonumber;
40 title1 'Examples of Chi square tests';
41 title2 'Chi square goodness of fit test';
42
43 data GoodFit;
44 input color $ number;
45 cards;
NOTE: The data set WORK.GOODFIT has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
45 ! run;
49 ;
50 proc print data=GoodFit; title3 'Raw Data listing';
51 run;
NOTE: There were 3 observations read from the data set WORK.GOODFIT.
NOTE: The PROCEDURE PRINT printed page 4.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Examples of Chi square tests
Chi square goodness of fit test
Raw Data listing
Obs color number
1 red 153
2 pink 72
3 white 17
52
53 proc freq data=GoodFit order=data; weight number;
54 title3 'Chi square analysis using Proc Freq';
55 tables color / chisq nocum testp=(0.5625 0.3750 0.0625);
56 run;
NOTE: There were 3 observations read from the data set WORK.GOODFIT.
NOTE: The PROCEDURE FREQ printed page 5.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Examples of Chi square tests
Chi square goodness of fit test
Chi square analysis using Proc Freq
The FREQ Procedure
Test
color Frequency Percent Percent
------------------------------------------
red 153 63.22 56.25
pink 72 29.75 37.50
white 17 7.02 6.25
Chi-Square Test
for Specified Proportions
-------------------------
Chi-Square 6.1983
DF 2
Pr > ChiSq 0.0451
Sample Size = 242
60
61 ******************************************************************;
62 *** A sample of fishes from North Carolina swamp streams ***;
63 *** revealed 47 male Flier sunfish and 59 females. Test the ***;
64 *** hypothesis that the population contains equal numbers of ***;
65 *** males and females ***;
66 ******************************************************************;
67 options nocenter ps=60 ls=78 nodate nonumber;
68 title1 'Examples of Chi square tests';
69 title2 'Chi square of equal proportions';
70
71 data EqualP;
72 input sex $ number;
73 cards;
NOTE: The data set WORK.EQUALP has 2 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
73 ! run;
76 ;
77 proc print data=EqualP; title3 'Raw Data listing';
78 run;
NOTE: There were 2 observations read from the data set WORK.EQUALP.
NOTE: The PROCEDURE PRINT printed page 6.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Examples of Chi square tests
Chi square of equal proportions
Raw Data listing
Obs sex number
1 Female 59
2 Male 47
80 proc freq data=EqualP; weight number;
81 title3 'Chi square analysis using Proc Freq';
82 tables sex / chisq expected cellchi2 binomial;
83 run;
NOTE: There were 2 observations read from the data set WORK.EQUALP.
NOTE: The PROCEDURE FREQ printed page 7.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
real time 0.75 seconds
cpu time 0.24 seconds
Examples of Chi square tests
Chi square of equal proportions
Chi square analysis using Proc Freq
The FREQ Procedure
Cumulative Cumulative
sex Frequency Percent Frequency Percent
-----------------------------------------------------------
Female 59 55.66 59 55.66
Male 47 44.34 106 100.00
Chi-Square Test
for Equal Proportions
---------------------
Chi-Square 1.3585
DF 1
Pr > ChiSq 0.2438
Binomial Proportion
for sex = Female
--------------------------------
Proportion 0.5566
ASE 0.0483
95% Lower Conf Limit 0.4620
95% Upper Conf Limit 0.6512
Exact Conf Limits
95% Lower Conf Limit 0.4569
95% Upper Conf Limit 0.6531
Test of H0: Proportion = 0.5
ASE under H0 0.0486
Z 1.1655
One-sided Pr > Z 0.1219
Two-sided Pr > |Z| 0.2438
Sample Size = 106