做主成分回归一般分两步进行:
1.对X提取主成分,这个步骤其实就是对X做主成分分析;
2.做回归分析。因变量是y,自变量是从第一步中提取的主成分。
下面用SAS举例说明:
data a;
input y x1-x3;
cards;
8500 0.059 1000 13.27
……………………
6000 -0.045 1000 10.12
;
run;
/*下面对X做主成分,根据实际提取了2个主成分,并把结果存在数据集comp中*/
proc princomp out=comp n=2;
var x1-x3;
run;
/*下面是做回归分析:y=prin1 prin2 ; 可以先用proc print data=comp;run;打印comp来查看其数据结构*/
proc print data=comp;run;
proc reg data=comp;
model y=prin1 prin2;run;
把此例的结果也打印给你了:
Analysis of Variance
Sum of Mean
Source DF Squares Square F Value Pr > F
Model 2 590780796 295390398 14.40 <.0001
Error 33 676765991 20508060
Corrected Total 35 1267546787
Root MSE 4528.58260 R-Square 0.4661
Dependent Mean 9422.02778 Adj R-Sq 0.4337
Coeff Var 48.06378
Parameter Estimates
Parameter Standard
Variable DF Estimate Error t Value Pr > |t|
Intercept 1 9422.02778 754.76377 12.48 <.0001
Prin1 1 -2907.18605 631.20386 -4.61 <.0001
Prin2 1 2219.04222 805.24700 2.76 0.0095