它们不能被测量,但对可测量的变量产生影响,或者说通过这些变量体现出来。因子分析的任务是通过原变量提供的错综复杂的关系,寻找潜在的公共因子,当初始因子不好解释时,常对其作旋转变换。提取公共因子的方法很多,主成分是最常用的提取公共因子的方法之一。因此,很多应用者将主成分和因子分析看成一回事,这事片面的。
5-2
TITLE’因子分析’;
OPTION LINESIZE=120; DATA ex5_2; INPUT x1-x12; CARDS;
46 55 126 51 75.0 25 72 6.8 489 27 8 360 ..........
48 68 100 45 53.6 23 70 7.2 522 28 9 352 ;
/*从原始数据出发,进行因子分析*/
PROC FACTOR METHOD=P N=3 ROTATE=VARIMAX; RUN;
/*从协方差矩阵出发,进行因子分析*/
PROC FACTOR COV METHOD=P N=3 ROTATE=VARIMAX; RUN;
练习5.4
TITLE’因子分析与因子旋转’; DATA ex5_4(TYPE=CORR); _TYPE_=”CORR”;
INPUT _name_$ x1—x12; CARDS;
x1 1 x2 0.69
0 1 x3 0.590.65
6 5
1
x4 0.510.550.60
5 7 0 1
x5 0.420.390.380.25
1 7 6 5
1
x6 0.350.300.250.200.610 0 2 0 1 1
x7 0.370.340.320.250.640.61
6 9 9 8 2 1
1 x8 0.400.440.350.310.66
0.640.73
1 5 8 1 0.340.380.28x9
2 1 4
x10.320.370.320 5 7 4 x10.260.380.251 0 5 5 x10.160.200.142 5 0 6
;
0 0 2 8
0.240.400.660.431 7 0 5 0.280.350.400.396 9 7 2 0.250.320.370.402 1 0 8 0.140.160.230.305 2 6 3
0.47
1 8
0.380.46
1
5 0 0.370.400.38
1
9 6 4
0.280.270.210.39
1
5 8 3 8
/*方差最大正交旋转*/
PROC FACTOR METHOD=P N=4 ROTATE=VARIMAX RES; RUN;
/*斜交旋转*/
PROC FACTOR METHOD=P N=3 ROTATE=PROMAX RES; RUN; 6-1解:
不妨假设回归方程为:logitP????x。
?p0/1?p0?(1)ln(OR)?ln???logitP0?logitP1???(???)???
p/1?p?11???ln1可解释为优势比导数的对数值。 OR对例6.1,当x=0时,logitP0?lnp055?ln??,??1.0629 1?p019 当x=1时,logitp?lnp1128?ln????,???1.3107 1?p1164所以相应的logistic回归方程为logitP=1.0629-1.3107x (2)ln(OR)?ln??p1/1?p1???logitP?1?(???)?(???)?2?
p/1?p??1?1???lnOR可解释为优势比平方根的对数值。
当x=1时,logitp1?lnp155?ln???? 1?p119p?1128?ln????
1?p?1164当x=-1时,logitp?1?ln联列上面两式,解得:??0.4075,??0.6554
所以相应的logistic回归方程为logitP=0.4075+0.6554x 6-2 解:
Title ‘logistic回归’; Data ex6-2;
Input f y x1 x2 @@ ; x12=x1*x2;
lable x1=”吸烟否”; lable x2=”用药否”; cards;
14 1 2 0 ;
Proc logistic descending; Weight f;
Model y=x1 x2 x12; Run;
Proc sort ;by x2 ;
Proc logistic descending;
Weight f; Model y=x1; By x2; Run; 6 -3 解:
Data ex6-3; Do y= 0 to 1; Do cho 1 to 4; Do sbp 1 to 4; Input f @@; Output ; End; End; End; Cards;
2 3 8 11 117 121 119
209 ;
Data temp ; Set ex6-3;
1 1 1 1 3 4 6 6 47 22 68 43 7 1 22 0 3 2 7 12 85 98 67 99 1 0 1 0 0 3 11 11 43 20 46 33
8
12 Y=y-1 ;
s1=0; If sbp=2 then s1=1; s2=0; If sbp=3 then s2=1; s3=0; If sbp=4 then s2=1; c1=0; If cho=2 then c1=1; c2=0; If cho=3 then c2=1; c3=0; If cho=4 then c2=1; run;
Proc logistic descending; Weight f;
Model y=sbp cho ;; Run;
Proc logistic descending; Weight f;
Model y=s1-s3 c1-c3; Test1: test s2-s1=s1; Test2: test s3-s2=s2-s1; Test3: test c2-c1=c1; Test4: test c3-c2=c2-c1; Run; 6-4解: Data ex6-4;
Input id chd age agrp@@; Cards;
1
0 20
…
…
… …34
0
38
; Run;
Proc gplot; Plot chd *age; Run;
/*计算条件均数p*/ Proc sort out =temp; By agrp;
Proc univariate data =temp noprint; By agrp; Var chd;
Output out=temp2 N=n sum=n1 mean=p; Run;
Proc print data =temp2; Run;
data =temp3; set temp2;
1 35
3
0 38
3 68