文档库 最新最全的文档下载
当前位置:文档库 › partial residual

partial residual

/*2012.12.11*/
/*example 1;Partial residual plot*/
/*E(y|x)=beta0+beta1*g(x1)+beta2'*x2*/
/*Partial residual plots are designed to reveal the form of g;*/

/*generate random variables*/
data simulation;
seed=12345;
do i=1 to 100;
x1=RANNOR (seed );
x2=RANNOR (seed );
g=x1+10*x1*x1;
res= RAND('normal ', 0, 0.25);
y=g+x2+res;
output;
end;
run;

/*regression y to x1 x2*/
proc reg data=simulation;
model y=x1 x2;
plot y*x1;
/*r. residual of regression
p. the predicted value of y */
/*the dot . is needed*/
plot r.*p.;
/*generate a dataset called out which contains the residual of the regression */
output out=out r=residual;
/**/
run;
quit;

/*calcuate the e^+*/
data simulation1;
set out;
/*-4.67119 is the estimate of beta1 that is coefficient of x1 */
residua1_e=residual-4.67119*x1;
run;
/*plot e^+ against x1. Here we try to reveal the form of g */
proc gplot data=simulation1;
plot residua1_e*x1;
run;


data new;
set simulation;
x3=x1**2;
run;
/* the step above which helps generate the quadratic x1 is needed.
Because it's not allowed us to put x1*x2 in the model statement in the proc reg.ew
for example;
proc reg data=sumulation;
model y=x1 x1*x1;
run;
(wrong)
Alternative way is to choose the proc glm. In this process, you just put x1*x1 in the model statement.
for example;
proc glm data=sumulation;
model y=x1 x1*x1;
run;
(right)
But the results of the two process
is a little different.*/
proc reg data=new;
model y=x3 x2 / spec dw dwprob;
plot y*x3;
plot r.*p.;
run;
quit;
/*option spec: the SPEC test: a non-significant p-value indicates that
the error variances are not not indentical and the
error terms are not dependent. */
/*optio nDW computes a Durbin-Watson statistic */
/*option DWPROB computes a Durbin-Watson statistic and p-value */

proc reg data=new;
model y=x3 x2 x1/ spec dw dwprob;
plot y*x3;
plot r.*p.;
run;
quit;


相关文档
相关文档 最新文档