Question

In: Statistics and Probability

data one; input NEA Fat; cards; -94 4.2 -57 3.0 -29 3.7 135 2.7 143 3.2...

data one;
input NEA Fat;
cards;
-94 4.2
-57 3.0
-29 3.7
135 2.7
143 3.2
151 3.6
245 2.4
355 1.3
392 3.8
473 1.7
486 1.6
535 2.2
571 1.0
580 0.4
620 2.3
690 1.1
;
title "The Reg Procedure";
proc sgplot data=one;
scatter x=NEA Y=Fat;
run;
proc sgplot data=one;
reg x=NEA y=Fat;
run;

This is my data for a scatterplot. I need to know how to plot the regression line by the NEA data.

Solutions

Expert Solution

Sol:

With proc reg we build linear regression of y on x

store the parameter estimates in esti

store in a macro variables estimates and call them in proc sgplot with inset

execute below code:

SAS Code:

ods graphics off;
proc reg data=one;
model Fat = NEA;
ods output ParameterEstimates=esti;
run;

data _null_;
set esti;
if _n_ = 1 then call symput('Intercpt', put(estimate, BEST6.));
else call symput('Slope', put(estimate, BEST6.));
run;
proc sgplot data=one noautolegend;
reg x=NEA y=Fat;
inset "Intercept = &Intercpt" "Slope = &Slope" /
border title="Parameter Estimates" position=topleft;
run;

Output:

The REG Procedure

Model: MODEL1

Dependent Variable: Fat

Number of Observations Read 16
Number of Observations Used 16
Analysis of Variance
Source DF Sum of
Squares
Mean
Square
F Value Pr > F
Model 1 11.79415 11.79415 21.55 0.0004
Error 14 7.66335 0.54738
Corrected Total 15 19.45750
Root MSE 0.73985 R-Square 0.6061
Dependent Mean 2.38750 Adj R-Sq 0.5780
Coeff Var 30.98860
Parameter Estimates
Variable DF Parameter
Estimate
Standard
Error
t Value Pr > |t|
Intercept 1 3.50512 0.30362 11.54 <.0001
NEA 1 -0.00344 0.00074141 -4.64 0.0004


Related Solutions

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT