STAT512 Analysis of Covariance Example 1: title3 "With Covariate the Age of the Individual"; data ancova; input age oxygen treatment $; cards; 31 17.05 aerobic 23 4.96 aerobic 27 10.40 aerobic 28 11.05 aerobic 22 0.26 aerobic 24 2.51 aerobic 23 -0.87 running 22 -10.74 running 22 -3.27 running 25 -1.97 running 27 7.50 running 20 -7.25 running ; proc print data = ancova; run; title4 "Model With an Interation"; proc glm data = ancova; class treatment; model oxygen = treatment age treatment*age / solution; output out=new p=pred r=resid; means treatment/hovtest=bf; *beware don't interpret it here if when we have an interaction just look at Brown Forsythe test; run; *do residual analysis as usual with resid and pred; proc capability data=new; var resid; qqplot; histogram; run; proc gplot data=new; plot resid*pred; run; title4 "Model Without an Interation"; proc glm data = ancova; class treatment; model oxygen = treatment age / solution; lsmeans treatment / pdiff stderr ; output out=new1 p=pred r=resid; means treatment/hovtest=bf; *beware don't interpret it here if when we have an interaction just look at Brown Forsythe test; run; *do residual analysis as usual with resid and pred; proc capability data=new1; var resid; qqplot; histogram; run; proc gplot data=new1; plot resid*pred; run; run; *Using regression with dummy variables use SS III ; title4 "Using Regression with dummy variables"; data dummy; set ancova; if treatment="aerobic" then trt_dummy=1; else trt_dummy=0; int=age*trt_dummy; run; proc reg data=dummy; model oxygen= age trt_dummy int; output out=new2 p=pred r=resid; run; *do residual analysis as usual with resid and pred; proc capability data=new2; var resid; qqplot; histogram; run; proc gplot data=new2; plot resid*pred; run; run; proc glm data=dummy; model oxygen= age trt_dummy trt_dummy*age; output out=new3 p=pred r=resid; means treatment/hovtest=bf; *beware don't interpret it here if when we have an interaction just look at Brown Forsythe test; run; *do residual analysis as usual with resid and pred; proc capability data=new3; var resid; qqplot; histogram; run; proc gplot data=new3; plot resid*pred; run; Example 2: data cars; input Price Mileage Make $; datalines; 17314.1 8221 Buick 17542.0 9135 Buick 16218.8 13196 Buick 16336.9 16342 Buick 16339.2 19832 Buick 15709.1 22236 Buick 15048.0 22964 Buick 14862.1 24021 Buick 15295.0 27325 Buick 21335.9 10237 Buick 12649.1 3629 Chevrolet 12314.6 4142 Chevrolet 11318.0 11156 Chevrolet 12409.9 11981 Chevrolet 11555.3 13404 Chevrolet 11700.1 15253 Chevrolet 11215.0 19945 Chevrolet 10145.0 23963 Chevrolet 9954.1 37345 Chevrolet 11918.5 7278 Chevrolet 25452.5 11892 Pontiac 23449.3 17273 Pontiac 23578.2 19148 Pontiac 22525.3 19521 Pontiac 21982.6 20472 Pontiac 22231.6 21929 Pontiac 22189.1 25651 Pontiac 21765.1 25794 Pontiac 21403.8 27168 Pontiac 21200.7 31197 Pontiac 26337.8 16068 SAAB 26775.0 16688 SAAB 25300.0 19569 SAAB 24896.6 21266 SAAB 25996.8 21433 SAAB 24801.6 26345 SAAB 24063.0 27674 SAAB 23249.8 27686 SAAB 19244.9 30387 SAAB 26841.1 10003 SAAB ; proc gplot data=cars; plot price*mileage=make; run; proc glm data=cars; class make; model price=make mileage make*mileage/solution; estimate "buick-chevy" make 1 -1 0 0 mileage 20000; estimate "buick-Pon" make 1 0 -1 0 mileage 20000; estimate "saab-Pon" make 0 -1 0 -1 mileage 20000; estimate "saab-chevy" make 0 -1 0 -1 mileage 20000; lsmeans make/adjust=tukey; output out=new r=resid p=pred; run; proc capability data=new; var resid; qqplot; histogram; run; proc gplot data=new; plot resid*pred; run; run;data dummy; set cars; if make="Buick" then x1=1; else x1=0; if make="Pontiac" then x2=1; else x2=0; if make="SAAB" then x3=1; else x3=0; x4=mileage; x5=x1*x4; x6=x2*x4; x7=x3*x4; run; proc reg data=dummy; model price = x1 x2 x3 x4 x5 x6 x7; run;