data sales; input Period Units Sales; format sales dollar8.; label sales="Dollar Sales" units="Units Sold"; cards; 1 75 150 2 25 50 3 130 260 ; proc print; title "Sales example. Refer to page 3."; symbol1 i=rl v=dot; axis1 order=0 to 300 by 100 minor=none label=( position=middle angle=90); axis2 order=0 to 150 by 50 minor=none label=(position=middle); proc gplot; plot sales*units/vaxis=axis1 haxis=axis2 regeqn noframe; title "Functional relation example. Refer to Figure 1.1, page 3";run; data midyear; label YearEnd="Year-End Evaluation" MidYear="Mid-Year Evaluation"; input Yearend Midyear; cards; 59 60 70 69 72 76 78 81 81 81 83 82 83 88 93 91 91 93 93 96 ; symbol1 i=none v=dot color=green; axis1 order=50 to 100 by 10 offset=(5) minor=none; axis2 order=50 to 100 by 10 offset=(5) minor=none; proc gplot data=midyear; plot yearend*midyear/noframe haxis=axis1 vaxis=axis2; title "Statistical Relation betwen Mid-Year Performance and Year-end performance."; title2 "Refer to Figure 1.2a, page 4";run; symbol1 i=rl v=dot color=green; axis1 order=50 to 100 by 10 offset=(5) minor=none ; axis2 order=50 to 100 by 10 offset=(5) minor=none; proc gplot; plot yearend*midyear/noframe haxis=axis1 vaxis=axis2; title "Statistical Relation betwen Mid-Year Performance and Year-end performance. Refer to Figure 1.2b, page 4"; /*Data presented here are featured in chapters 8 and 11, in case you're curious*/ data steroid; input steroid age; cards; 27.1 23 22.1 19 21.9 25 10.7 12 1.4 8 18.8 12 14.7 11 5.7 8 18.6 17 20.4 18 9.2 9 23.4 21 10.5 10 19.7 25 11.8 9 24.6 17 3.4 9 22.8 23 21.1 13 24 14 21.8 16 23.5 17 19.4 21 25.6 24 12.8 13 20.8 14 20.6 18 ; axis1 order=0 to 30 by 5 minor=none label=( position=middle angle=90); axis2 order=5 to 25 by 5 minor=none label=( position=middle ); symbol i=rq c=red; proc gplot; plot steroid*age/ noframe haxis=axis2 vaxis=axis1; title "Example of Curvilinear Relation. Refer to Figure 1.3, page 5";run; %let location=C:\Documents and Settings\woodph\My Documents\glmwood\kutnersolutions\Chapter1; PROC IMPORT OUT= WORK.toluca DATAFILE= "&location\Chapter1.xls" DBMS=EXCEL REPLACE; SHEET="CH01TA01$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; proc print; title "Toluca Lot Size and Work Hours data. Refer to Table 1.1, page 19";run; /*Make centered versions of lotsize and workhours*/ data toluca;set toluca; clotsize=lotsize; cworkhrs=workhrs; proc standard data=toluca out=toluca mean=0;var clotsize cworkhrs; data toluca;set toluca; xy=clotsize*cworkhrs; x2=clotsize*clotsize; y2=cworkhrs*cworkhrs; label lotsize="(1), Lot-,Size" workhrs="(2), Work,Hours" clotsize="(3), X(i)-MeanX" CWorkhrs="(4), Y(i)-MeanY" xy="(5), (X(i)-MeanX)*(Y(i)-MeanY)" x2="(6), (X(i)-MeanX)*((X(i)-MeanX)" y2="(7), (Y(i)-MeanY)*(Y(i)-MeanY)"; proc print split=',' round ;sum lotsize workhrs clotsize cworkhrs xy x2 y2; title 'Data listing with centered vars, cross-products and squares. Refer to Table 1.1, page 19';run; axis1 split="," order=100 to 600 by 100 minor=none label=( position=middle angle=90); axis2 split="," order=0 to 150 by 50 minor=none label=( position=middle); symbol i=none c=red v=dot; data toluca;set toluca; label lotsize="Lot-Size" workhrs="Work Hours"; proc gplot; plot workhrs*lotsize/noframe vaxis=axis1 haxis=axis2; title "Scatter Plot Toluca Data. Refer to Figure 1.10a, page 20";run; symbol i=rl c=red v=dot; proc gplot; plot workhrs*lotsize/noframe vaxis=axis1 haxis=axis2; title "Scatter Plot Toluca Data. Refer to Figure 1.10b, page 20";run; proc corr cov sscp data=toluca;var lotsize workhrs; title "correlations, covariances and summary statistics Toluca data division by N-1 (default)";run; proc corr cov sscp data=toluca vardef=n; title "correlations, covariances and summary statistics Toluca data division by N";run; proc univariate; histogram workhrs lotsize/normal; inset mean stdmean median skewness std var n mode/ noframe; title "univariate plot of Toluca data";run; proc glm; model workhrs=lotsize; title "Toluca data regression as General Linear model using Proc GLM";run; proc reg; model workhrs=lotsize/stb; title "Toluca data regression as, well, regression, using Proc Reg";run; proc stepwise; model workhrs=lotsize; title "Toluca data regression using Proc Stepwise";run; proc calis aug ucov rdf=1 all vardef=n; lineqs workhrs=b1 lotsize + b0 intercept + e1, lotsize=mlot intercept + e2; std e1=errvar, e2=lotvar; title 'Toluca data regression as a structural equation model';run; proc glm; model workhrs=lotsize; output out=toluca p=Phrs r=rhours; data toluca;set toluca; run+1; sresid=rhours*rhours; label lotsize="(1),Lot,Size,X(i)" workhrs="(2),Work,Hours,Y(i)" phrs="(3),Estimated,Mean,Response,Ypred(i)" rhours="(4),Residual,Y(i)-Ypred(i)=e(i)" sresid="(5),Squared,Residual,(Y(i)-Ypred(i))##2=e(i)##2"; proc print split=',' round ;sum lotsize workhrs phrs rhours sresid;var run lotsize workhrs phrs rhours sresid; title "Fitted Values, Residuals and Squared Residuals. Refer to Table 1.2, page 22";run; proc reg; model workhrs=lotsize; plot (workhrs)*lotsize/hplots=2; title "Graphics also available in Proc Reg if desired. Refer to Figure 1.12, page 23";run; data ml; y=250;output; y=265;output; y=259;output; proc univariate; histogram y/noframe normal(mu=230 sigma=10) midpoints=230 240 250 260 270 280 290 300 310; title "Likelihood for population value of 230. Refer to Figure 1.13a, p. 27";run; proc univariate; histogram y/noframe normal(mu=259 sigma=10) midpoints=239 249 259 269 279 289 299 309 319; title "Likelihood for population value of 259. Refer to Figure 1.13b, p. 27";run; /* Or, if you want to draw the Likelihood function in SAS*/ data likedata; do mu=220 to 300; pi=arcos(-1); like=(1/(10*sqrt(1/pi)))*exp(-.5*((250-mu)/10)**2)* (1/(10*sqrt(1/pi)))*exp(-.5*((265-mu)/10)**2)* (1/(10*sqrt(1/pi)))*exp(-.5*((259-mu)/10)**2); output; end; axis1 order=.000 to .004 by .001 minor=none; axis2 order=220 to 300 by 10 minor=none; symbol i=join v=none; proc gplot; plot like*mu/noframe vaxis=axis1 haxis=axis2; title "Likelihood function estimation for Mean of Normal Population"; title2 "refere to Figure 1.14, page 29 (Note error in Y axis in book)";run;