/*

file: preg-nitrofen-28jan04.doc

directory: \Classes\Spring ‘04\

contents: polynomial regression example

*/

libname class 'Z:\baileraj\Classes\Fall 2003\sta402\data’;

/* creates a permanent dataset with the nitrofen data */

data nitrofen;

infile 'M:\public.www\classes\sta402\SAS-programs\ch2-dat.txt'

firstobs=16 expandtabs missover pad ;

input @9 animal 2.

@17 conc 3.

@25 brood1 2.

@33 brood2 2.

@41 brood3 2.

@49 total 2.;

conc2 = conc*conc; * construct squared concentration;

conc_adj = conc – 160; * rescale concentration;

conc_adj2 = conc_adj*conc_adj;

label animal = animal ID number;

label conc = Nitrofen concentration;

label brood1 = number of young in first brood;

label brood2 = number of young in 2nd brood;

label brood3 = number of young in 3rd brood;

*label total = total young produced in three broods;

proc print data= nitrofen;

run;

options formdlim=”-“ nodate;

title “Response=Total Young and Predictors = nitrofen conc (scaled)”;

proc reg;

model total = conc conc2;

model total = conc_adj conc_adj2;

run;

OUTPUT

Response=Total Young and Predictors = nitrofen conc (scaled) 7

The REG Procedure

Model: MODEL1

Dependent Variable: total

Analysis of Variance

Sum of Mean

Source DF Squares Square F Value Pr > F

Model 2 4902.67799 2451.33900 157.27 <.0001

Error 47 732.60201 15.58728

Corrected Total 49 5635.28000

Root MSE 3.94807 R-Square 0.8700

Dependent Mean 22.88000 Adj R-Sq 0.8645

Coeff Var 17.25556

Parameter Estimates

Parameter Standard

Variable Label DF Estimate Error t Value Pr > |t|

Intercept Intercept 1 31.45773 1.17926 26.68 <.0001

conc Nitrofen concentration 1 0.03380 0.01794 1.88 0.0658

conc2 1 -0.00037868 0.00005558 -6.81 <.0001

------

Response=Total Young and Predictors = nitrofen conc (scaled) 8

The REG Procedure

Model: MODEL2

Dependent Variable: total

Analysis of Variance

Sum of Mean

Source DF Squares Square F Value Pr > F

Model 2 4902.67799 2451.33900 157.27 <.0001

Error 47 732.60201 15.58728

Corrected Total 49 5635.28000

Root MSE 3.94807 R-Square 0.8700

Dependent Mean 22.88000 Adj R-Sq 0.8645

Coeff Var 17.25556

Parameter Estimates

Parameter Standard

Variable Label DF Estimate Error t Value Pr > |t|

Intercept Intercept 1 27.17148 0.86967 31.24 <.0001

conc_adj 1 -0.08738 0.00513 -17.04 <.0001

conc_adj2 1 -0.00037868 0.00005558 -6.81 <.0001

Now some fancy graphs for illustration …

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig2.rtf';

/* SYMBOL = defines characteristics of plotted symbols */

procgplot data=class.nitrofen;

title h=1.5 'A plot of the number of C. dubia produced at different Nitrofen concentrations';

title2 h=1 '[mean +/- 2SD is plotted for each concentration]';

symbol1 interpol=STD2T /* plots +/- 2 SD from the mean at each conc */

/* T= add top and bottom to each 2 SD diff */

value=dot;

plot total*conc / hminor=1 /* hminor=# tick markets before x values */

haxis=0 to 350 by 50;

run;

ODS RTF CLOSE;

procmeans data= nitrofen;

class conc;

var total;

output out=nitromean mean=n_mean stddev=n_sd;

run;

procprint;

run;

Obs conc _TYPE_ _FREQ_ n_mean n_sd

1 . 0 50 22.88 10.7241

2 0 1 10 31.40 3.5963

3 80 1 10 31.50 3.2745

4 160 1 10 28.30 2.3594

5 235 1 10 17.20 5.9029

6 310 1 10 6.00 3.7118

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig3.rtf';

procgplot data=nitromean;

title h=1.5 'Plot of mean number of C. dubia young produced at different Nitrofen concentrations';

title2 h=1 '[bubble area proportional to std dev.]';

bubble n_mean*conc=n_sd / bsize=15; /* bsize helps resize bubble for display */

run;

ODS RTF CLOSE;

G3D figures

libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’;

data new; set class.nitrofen;

retain conc;

brood=1; young=brood1; output;

brood=2; young=brood2; output;

brood=3; young=brood3; output;

keep conc brood young;

data new2; set new;

jconc = conc + (10-20*ranuni(0));

jbrood = brood + (1-2*ranuni(0));

run;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig7.rtf';

proc g3d data=new2;

title h=1 ‘Scatter plot of # young by conc. and brood (jittered)’;

scatter jconc*jbrood=young / xticknum=2 yticknum=2;

run;

quit;

ODF RTF CLOSE;

proc means data=new;

class conc brood;

var young;

output out=new3 mean=ymean;

run;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig8.rtf';

proc g3d data=new3;

title h=1 'Surface plot of mean # young by conc. and brood';

plot conc*brood=ymean / xticknum=2 yticknum=2 tilt=80;

run;

quit;

ODS RTF CLOSE;