* Power for chi-square test for GSS and comparing power for G^2 versus M^2 for ordinal data; * Power by sample size; data powerGsq; N=884; wGsq = 44.961; wMsq = 36.261; dfGsq=12; dfMsq=1; Gpower=1-cdf('CHISQUARE',21.0260698175,dfGsq,wGsq); Mpower=1-cdf('CHISQUARE',3.84145882069,dfMsq,wMsq); run; proc print;run; *What Power is ; data chiplot; df=12; w=44.961; do xsq=.00 to 100 by .01; xcentral = pdf('CHISQUARE',xsq,df); xnoncentral=pdf('CHISQUARE',xsq,df,w); if xsq>21.0260 then do; alpha=xcentral; power=xnoncentral; end; else do; alpha=.; power=.; end; output; end; run; goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate hpos=0 vpos=0 htext=2 ftext=swiss ctext= target= gaccess= gsfmode= ; goptions device=WIN ctext=black; axis1 color=black width=2.0 label=('Chi-Square Value') ; axis2 color=black width=2.0 label=(angle=90 'Probability Density') ; symbol1 value=none ci=black i=join; symbol2 value=none ci=black i=join;; symbol3 value=none ci=black i=join;; symbol4 value=none ci=black i=join;; pattern1 color=gray77 value=solid; pattern2 color=grayaa value=solid; pattern3 color=white; proc gplot data=WORK.CHIPLOT; plot (power alpha xcentral xnoncentral)* xsq / overlay haxis=axis1 vaxis=axis2 frame href=21.0260 areas=2; title1 'Null and Alternative Chi-Square Distributions'; title2 'df=12, omega=Gsq=44.961'; note move=(35,43) 'Null (central Chi-Square)'; note move=(75,25) 'Alternative (non-central Chi-Square)'; note move=(80,40) 'Light Grey = alpha'; note move=(80,38) 'Dark Grey = power'; run; *What Power is for Msq; data msqplot; df=1; w=36.261; do xsq=.01 to 50 by .01; xcentral = pdf('CHISQUARE',xsq,df); xnoncentral=pdf('CHISQUARE',xsq,df,w); if xsq>3.84145882069 then do; alpha=xcentral; power=xnoncentral; end; else do; alpha=.; power=.; end; output; end; run; goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate hpos=0 vpos=0 htext=2 ftext=swiss ctext= target= gaccess= gsfmode= ; goptions device=WIN ctext=black; axis1 color=black width=2.0 label=('Chi-Square Value') ; axis2 color=black width=2.0 label=(angle=90 'Probability Density') order=0 to 1.5 by .5; symbol1 value=none ci=black i=join; symbol2 value=none ci=black i=join;; symbol3 value=none ci=black i=join;; symbol4 value=none ci=black i=join;; pattern1 color=gray77 value=solid; pattern2 color=grayaa value=solid; pattern3 color=white; proc gplot data=WORK.msqPLOT; plot (power alpha xcentral xnoncentral)* xsq / overlay haxis=axis1 vaxis=axis2 frame href=3.841 areas=2; title1 'Null and Alternative Chi-Square Distributions'; title2 'df=1, omega= (Msq=) 36.261'; note move=(15,43) 'Null (central Chi-Square)'; note move=(75,10) 'Alternative (non-central Chi-Square)'; note move=(90,40) 'Light Grey = alpha'; note move=(90,38) 'Dark Grey = power'; run; * Power curves for Gsq and Msq for different N; * prob(X^2_12> 21.0260698175 )=.05; * Prob(X^2_1> 3.84145882069 )=.05; data curves; N=884; wGsq = 44.961/N; wMsq = 36.261/(N-1); dfGsq=12; dfMsq=1; do size=20 to 1000 by 1; wG=wGsq*size; wM=wMsq*(size-1); Gpower=1-cdf('CHISQUARE',21.0260698175,dfGsq,wG); Mpower=1-cdf('CHISQUARE',3.84145882069,dfMsq,wM); output; end; run; goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ; goptions device=WIN ctext=black; axis1 color=black width=2.0 label=('Sample Size') ; axis2 color=black width=2.0 label=(angle=90 'Power') order=0 to 1 by .2; symbol1 value=none ci=black i=join; symbol2 value=none ci=red i=join; legend1 position=(inside bottom right) frame cshadow=grey ; proc gplot data=curves; plot (Gpower Mpower)*size / legend=legend1 overlay haxis=axis1 vaxis=axis2 frame ; title 'Power Curves for G2 and M2 Based on GSS Example'; run;