/* This is an example of the REG procedure in SAS */ /* This code will analyze data from a */ /* Simple Linear Regression (SLR) model */ /* The data given here are the drug amounts and reaction times */ /* from the example we studied in class */ /* I am calling the data set "STIMULUS". */ /* The predictor variable is DRUG_X. */ /* The response variable is TIME_Y. */ DATA STIMULUS; INPUT DRUG_X TIME_Y; CARDS; 1 1 2 1 3 2 4 2 5 4 ; /* The following PROC SGPLOT code will produce a scatterplot of these data */ /* with TIME_Y on the y-axis and DRUG_X on the x-axis */ PROC SGPLOT DATA=STIMULUS; SCATTER y=TIME_Y x=DRUG_X; RUN; /* Note that the scatterplot resembles the one on p.591 (figure 11.3). */ /* PROC REG will give us the least-squares regression line for these data */ /* DATA=STIMULUS tells SAS to use the STIMULUS data set */ /* MODEL TIME_Y=DRUG_X tells SAS that TIME_Y is the response variable */ /* and DRUG_X is the predictor variable */ /* The option CLB will give a CI for beta_1, */ /* and alpha=0.05 means that we want a 95% CI. */ PROC REG DATA=STIMULUS; MODEL TIME_Y=DRUG_X / CLB alpha=0.05; RUN; /* If you enter this program into the program editor, */ /* and choose "Run -> Submit", the (first page of) output should match the */ /* output in Figure 11.6a on page 518 of the textbook. */ /* The estimated values of the y-intercept and slope are given under */ /* "Parameter Estimates" */ /* We see that beta_0-hat is -0.1 and beta_1-hat is 0.7 */ /* so the estimated SLR model can be written as */ /* Y-hat = -0.1 + 0.7 X. */ /* Now this model can be used for predicting Reaction Time */ /* for any particular drug amount. */ /* Suppose we want to do a test for model usefulness by testing H_0: beta_1 = 0. */ /* The test statistic for this test is given under "t value", in the "DRUG_X" row. */ /* We see that t=3.66 for this test. The p-value (for the TWO-TAILED alternative) */ /* is given in the next column over, labeled "Pr > |t|". */ /* We see the P-value is 0.0354. So if our significance level alpha is .05, */ /* we would reject H_0 and conclude the model is useful. */ /* Our estimate of sigma (which we call s) is given next to "Root MSE". */ /* Note that in this example, s=0.60553. This matches what we found in class. */ /* To find the correlation coefficient r between these two variables */ /* we use PROC CORR: */ PROC CORR DATA=STIMULUS; VAR TIME_Y DRUG_X; RUN; /* We see that r = 0.90370. Do you see this on the output? */ /* Note that the coefficient of determination r^2 is simply the square of r. */ /* This value, 0.8167, was found next to "R-square" on the PROC REG output. */