/* chisquare_gof2.sas */ /* chi-square GOF tests */ /* Second approach: more detailed output */ /* ------------------------------------------- */ data peaplant1; input type $ obsd expd; dev = obsd-expd; term = dev*dev/expd; cards; RY 315 312.75 WY 101 104.25 RG 108 104.25 WG 32 34.75 ; proc print data=peaplant1; var type obsd expd dev term; title 'pea plant seed shape and color'; proc means data=peaplant1 noprint; var term; output out=peaplant2 sum=X2; data peaplant3; set peaplant2; df = 3; p = 1 - probchi(X2,df); proc print data=peaplant3; var X2 p; run; /* ------------------------------------------- */ data maize1; input type $ obsd expd; dev = obsd-expd; term = dev*dev/expd; cards; green 773 731.813 golden 231 243.938 grst 238 243.938 grgost 59 81.313 ; proc print data=maize1; var type obsd expd dev term; title 'maize leaf type (all)'; proc means data=maize1 noprint; var term; output out=maize1a sum=X2; data maize1b; set maize1a; df = 3; p = 1 - probchi(X2,df); proc print data=maize1b; var X2 p; run; /* ------------------------------------------- */ data maize2; input type $ obsd expd; dev = obsd-expd; term = dev*dev/expd; X2 = sum(term); df = 2; p = 1 - probchi(X2,df); cards; green 773 745.2 golden 231 248.4 grst 238 248.4 ; proc print data=maize2; var type obsd expd dev term; title 'maize leaf type (omitting green-golden-striped)'; proc means data=maize2 noprint; var term; output out=maize2a sum=X2; data maize2b; set maize2a; df = 2; p = 1 - probchi(X2,df); proc print data=maize2b; var X2 p; run;