/* InferenceForOneProportion.sas */ /* Inference for one proportion */ /* Confidence intervals and tests for one proportion */ /* ---------------------------------------------------------*/ /* examples from chapter 5 */ /* ---------------------------------------------------------*/ /* ---------------------------------------------------------*/ /* apple orchard example */ /* compare P(infested) to .20 */ data orchard; input case outcome : $ 11. count; /* the coding outcome : $ 11. indicates that we want to allocate 11 characters for outcome */ cards; 1 infested 35 1 notinfested 165 2 infested 26 2 notinfested 174 3 infested 45 3 notinfested 155 4 infested 54 4 notinfested 146 5 infested 52 5 notinfested 148 6 infested 45 6 notinfested 155 ; proc freq data=orchard order=data; tables outcome / alpha=.05 binomial(cl=wilson p=.2 level='infested'); weight count; by case; ods select OneWayFreqs Binomial BinomialCLs BinomialTest; output out=new1 binomial; title 'apple orchard example 95% confidence intervals for p'; title2 'alpha=.05, p_0=.2'; data new2; set new1; n=N; phat=_BIN_; lowerbound=L_W_BIN; upperbound=U_W_BIN; proc print data=new2; var case n phat lowerbound upperbound; /* ---------------------------------------------- */ /* acceptance sampling example */ /* Is there evidence that P(defective) > .06? */ data shipment; input case outcome : $ 12. count; /* the coding outcome : $ 12. indicates that we want to allocate 12 characters for outcome */ cards; 1 defective 16 1 notdefective 184 2 defective 20 2 notdefective 180 ; proc freq data=shipment order=data; tables outcome / alpha=.05 binomial(cl=wilson p=.06 level='defective'); weight count; by case; ods select OneWayFreqs Binomial BinomialCLs BinomialTest; output out=new3 binomial; title 'acceptance sampling example 95% confidence intervals for p'; title2 'alpha=.05, p_0=.06'; data new4; set new3; n=N; phat=_BIN_; lowerbound=L_W_BIN; upperbound=U_W_BIN; proc print data=new4; var case n phat lowerbound upperbound; /* ------------------------------------------ */ /* machine parts example */ /* Is there evidence that P(unacceptable) < .35? */ data batch; input case outcome : $ 12. count; /* the coding outcome : $ 12. indicates that we want to allocate 12 characters for outcome */ cards; 1 unacceptable 54 1 acceptable 146 ; proc freq data=batch order=data; tables outcome / alpha=.05 binomial(cl=wilson p=.35 level='unacceptable'); weight count; by case; ods select OneWayFreqs Binomial BinomialCLs BinomialTest; output out=new5 binomial; title 'machine parts example 95% confidence interval for p'; title2 'alpha=.05, p_0=.35'; data new6; set new5; n=N; phat=_BIN_; lowerbound=L_W_BIN; upperbound=U_W_BIN; proc print data=new6; var case n phat lowerbound upperbound; /* ------------------------------------------ */ /* Mendel pea flower color example */ /* Is there evidence that P(red) notequal to .75? */ data peas; input case outcome : $ 8. count; /* the coding outcome : $ 8. indicates that we want to allocate 8 characters for outcome */ cards; 1 red 705 1 white 224 ; proc freq data=peas order=data; tables outcome / alpha=.05 binomial(cl=wilson p=.75 level='red'); weight count; by case; ods select OneWayFreqs Binomial BinomialCLs BinomialTest; output out=new7 binomial; title 'Mendel pea flower color example 95% confidence interval for p'; title2 'alpha=.05, p_0=.75'; data new8; set new7; n=N; phat=_BIN_; lowerbound=L_W_BIN; upperbound=U_W_BIN; proc print data=new8; var case n phat lowerbound upperbound; run;