课本课后题答案+真题答案 下载本文

目录

真题 .................................................................................................................................................. 2

1(d4.4) ................................................................................................................................. 2 2(d8.3) ................................................................................................................................. 4

(1) ................................................................................................................................. 4 (2) ................................................................................................................................. 5 (3) ................................................................................................................................. 6 3(d6.2) ............................................................................................................................... 10

(1) ............................................................................................................................... 10 (2) ............................................................................................................................... 11

第四章 回归 ................................................................................................................................... 12

4.1一元线性回归 ................................................................................................................... 12 4.2多元线性回归 ................................................................................................................... 13 4.3多元线性回归 ................................................................................................................... 14 4.4 变量选择.......................................................................................................................... 15 4.5曲线模型比较 ................................................................................................................... 19 4.6 ........................................................................................................................................... 20 4.7 ........................................................................................................................................... 21 第五章 方差分析 ........................................................................................................................... 21

5.1单因素方差分析() ............................................................................................................ 21 5.2双因素方差分析 ............................................................................................................... 21 5.3双因素及交互效应 ........................................................................................................... 22 5.4双因素及交互效应 ........................................................................................................... 22 5.5正交 .................................................................................................................................. 23 第六章判别分析 ............................................................................................................................. 24

6.6判别分析........................................................................................................................... 24 第七章 聚类 ................................................................................................................................... 25

7.2系统聚类........................................................................................................................... 25 7.3 K均值聚类 ........................................................................................................................ 25 第八章主成分 ................................................................................................................................. 26

8.3 ........................................................................................................................................... 26 第九章 因子分析 ........................................................................................................................... 29

9.3 bartlett检验 ..................................................................................................................... 29 9.4因子分析........................................................................................................................... 29

真题

1(d4.4)

(1)> (fm=lm(yX$y~yX$x1+yX$x2+yX$x3++yX$x4,data=yX)) Call:

lm(formula = yX$y ~ yX$x1 + yX$x2 + yX$x3 + +yX$x4, data = yX)

Coefficients:

(Intercept) yX$x1 yX$x2 yX$x3 yX$x4 23.5321088 -0.0033866 1.1641150 0.0002919 -0.0437416

(2)> summary(fm) #显著性检验 Call:

lm(formula = yX$y ~ yX$x1 + yX$x2 + yX$x3 + +yX$x4, data = yX)

Residuals:

Min 1Q Median 3Q Max -5.0229 -2.1354 0.3297 1.2639 6.9690

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) 23.5321088 4.5990714 5.117 2.47e-05 *** yX$x1 -0.0033866 0.0080749 -0.419 0.678 yX$x2 1.1641150 0.0404889 28.751 < 2e-16 *** yX$x3 0.0002919 0.0085527 0.034 0.973 yX$x4 -0.0437416 0.0092638 -4.722 7.00e-05 *** ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.79 on 26 degrees of freedom

Multiple R-squared: 0.9997, Adjusted R-squared: 0.9997 F-statistic: 2.289e+04 on 4 and 26 DF, p-value: < 2.2e-16

(3)> fm.step=step(fm,direction=\为逐步筛选法 Start: AIC=68.15

yX$y ~ yX$x1 + yX$x2 + yX$x3 + +yX$x4

Df Sum of Sq RSS AIC - yX$x3 1 0.0 202.3 66.156 - yX$x1 1 1.4 203.7 66.363

202.3 68.154 - yX$x4 1 173.5 375.8 85.351 - yX$x2 1 6433.1 6635.4 174.352

Step: AIC=66.16

yX$y ~ yX$x1 + yX$x2 + yX$x4

Df Sum of Sq RSS AIC - yX$x1 1 1.5 203.9 64.390 202.3 66.156 + yX$x3 1 0.0 202.3 68.154 - yX$x4 1 197.3 399.6 85.253 - yX$x2 1 7382.2 7584.5 176.496

Step: AIC=64.39 yX$y ~ yX$x2 + yX$x4

Df Sum of Sq RSS AIC 204 64.390 + yX$x1 1 2 202 66.156 + yX$x3 1 0 204 66.363 - yX$x4 1 549 753 102.888 - yX$x2 1 367655 367859 294.825 > summary(fm.step) Call:

lm(formula = yX$y ~ yX$x2 + yX$x4, data = yX)

Residuals:

Min 1Q Median 3Q Max -4.8635 -2.1616 0.1905 1.3270 6.9171

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) 24.948722 3.073218 8.118 7.73e-09 *** yX$x2 1.147962 0.005109 224.703 < 2e-16 *** yX$x4 -0.046824 0.005393 -8.683 1.97e-09 *** ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.698 on 28 degrees of freedom

Multiple R-squared: 0.9997, Adjusted R-squared: 0.9997 F-statistic: 4.893e+04 on 2 and 28 DF, p-value: < 2.2e-16

2(d8.3) (1)

> Z=scale(X)

> PCA=princomp(Z,cor=T) #特征值 > PCA Call:

princomp(x = Z, cor = T)

Standard deviations:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 1.9806181 1.3117388 0.4325494 0.3268294 0.2180022 0.1226861

6 variables and 35 observations. > summary(PCA,loadings=T) Importance of components:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Standard deviation 1.980618 1.3117388 0.43254941 0.32682941 0.218002240 Proportion of Variance 0.653808 0.2867764 0.03118317 0.01780291 0.007920829 Cumulative Proportion 0.653808 0.9405844 0.97176761 0.98957052 0.997491353 Comp.6 Standard deviation 0.122686106 Proportion of Variance 0.002508647 Cumulative Proportion 1.000000000

Loadings:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 x1 0.420 0.377 -0.512 0.502 0.407 x2 0.374 0.493 -0.247 0.118 -0.597 -0.431 x3 0.413 0.349 0.792 0.268 x4 0.452 -0.295 -0.596 -0.407 0.431 x5 0.391 -0.467 -0.196 -0.202 0.365 -0.645 x6 0.395 -0.433 0.765 -0.144 0.203 > library(mvstats)

> princomp.rank(PCA,m=2,plot=T) #对主成分结果PCA做排名,m=2指选择2个主成分,plot=T指做出第一主成分为横轴,第二主成分为纵轴的散点图,结果中的PC为综合得分 Comp.1 Comp.2 PC rank 上海 -5.29725256 3.638372278 -2.57285418 2 北京 -4.16811130 2.899163966 -2.01335731 3 广州 -3.19774590 0.869671023 -1.95762400 4 深圳 -6.91868259 -5.350185377 -6.44046071 1 天津 -0.60335401 1.148069177 -0.06935951 10

重庆 0.40020118 1.631765336 0.77569494 26 杭州 -1.56816240 -0.466491554 -1.23227204 5 成都 -0.01635354 0.431212063 0.12010553 14 青岛 -0.03988226 0.182883868 0.02803729 12 宁波 -1.10859279 -0.191149505 -0.82887189 6 武汉 0.62182665 0.672410374 0.63724921 22 大连 -0.19876398 0.257239761 -0.05973220 11 沈阳 0.71596493 0.337101786 0.60045268 20 南京 -0.17761969 -0.287234941 -0.21104047 8 哈尔滨 0.87997328 0.252444658 0.68864498 25 济南 0.31809720 -0.206004728 0.15830284 15 石家庄 0.48447263 -0.139992584 0.29407833 16 福州 0.02035238 -0.622003894 -0.17549676 9 长春 0.75431107 0.002039725 0.52494974 18 郑州 0.88431778 -0.009187092 0.61189551 21 西安 1.11851447 0.159487402 0.82611502 27 长沙 0.62696414 -0.255374452 0.35794637 17 昆明 0.88894841 -0.289896045 0.52952845 19 厦门 -0.17561404 -0.892846301 -0.39429225 7 南昌 1.40039421 -0.208252362 0.90993113 28 太原 1.43425828 -0.191451775 0.93859268 30 合肥 1.15066319 -0.467599182 0.65726833 24 兰州 1.43697464 -0.223998294 0.93055768 29 南宁 1.17937136 -0.542078826 0.65451538 23 乌鲁木齐 1.51674331 -0.131505802 1.01420574 31 贵阳 1.55998998 -0.091002624 1.05661594 32 呼和浩特 1.63126248 -0.182599956 1.07823077 34 海口 0.73834511 -1.304992537 0.11534830 13 银川 1.70099057 -0.371802187 1.06901314 33 西宁 2.00719784 -0.056211398 1.37808137 35

(2)

> Y=predict(PCA)

> Z=scale(Y) #对数据做标准化处理 > D=dist(Z) #计算距离矩阵

> hc=hclust(D,\聚类法

> cbind(hc$merge,hc$height) #显示聚类过程,-表示原样品,+表示新类

> plot(hc) #画聚类图

> rect.hclust(hc,k=3) #对聚类结果画框,k=3表示分3类

石家庄 大连 昆明 ; 成都,杭州,南京 ; 深圳,北京,上海

(3)

> FA1=factpc(Z,2,rotation=\ #主成分法 方差最大法旋转

Factor Analysis for Princomp in Varimax:

> FA1 $Vars

Vars Vars.Prop Vars.Cum Factor1 2.823 47.05 47.05 Factor2 2.821 47.01 94.06

$loadings

Factor1 Factor2 [1,] 0.2386 0.9378 [2,] 0.0673 0.9812 [3,] 0.2547 0.9022 [4,] 0.9068 0.3589 [5,] 0.9813 0.1140 [6,] 0.9546 0.1512

$scores

Factor1 Factor2 上海 -0.067456 3.79709 北京 -0.072373 3.00703 广州 0.663840 1.58698 深圳 5.276916 -0.41035 天津 -0.397311 0.82245 重庆 -1.007469 0.72658 杭州 0.799780 0.30360 成都 -0.223248 0.23496 青岛 -0.083085 0.11124 宁波 0.491771 0.28832 武汉 -0.576000 0.13870 大连 -0.066642 0.20664 沈阳 -0.431066 -0.07264 南京 0.215070 -0.09020 哈尔滨 -0.443843 -0.17532 济南 -0.002576 -0.22138 石家庄 -0.096202 -0.24481 福州 0.323165 -0.33778 长春 -0.266622 -0.26422 郑州 -0.306426 -0.31592

西安 -0.478449 -0.30863 长沙 -0.085087 -0.35626 昆明 -0.158979 -0.46675 厦门 0.535988 -0.41281 南昌 -0.382382 -0.60324 太原 -0.403225 -0.60623 合肥 -0.156737 -0.65326 兰州 -0.386897 -0.62448 南宁 -0.127289 -0.70295 乌鲁木齐 -0.464098 -0.60337 贵阳 -0.500832 -0.59706 呼和浩特 -0.477277 -0.67081 海口 0.433128 -0.95334 银川 -0.401344 -0.79590 西宁 -0.676739 -0.73586

$Rank

F Ri 上海 1.864161 2 北京 1.466805 3 广州 1.125254 4 深圳 2.434248 1 天津 0.212364 7 重庆 -0.140739 15 杭州 0.551775 5 成都 0.005776 12 青岛 0.014043 11 宁波 0.390078 6 武汉 -0.218772 17 大连 0.069953 8 沈阳 -0.251914 19 南京 0.062486 9 哈尔滨 -0.309629 22 济南 -0.111941 14 石家庄 -0.170481 16 福州 -0.007193 13 长春 -0.265424 21 郑州 -0.311171 23 西安 -0.393570 25 长沙 -0.220627 18 昆明 -0.312814 24 厦门 0.061749 10 南昌 -0.492776 28 太原 -0.504691 29

合肥 -0.404915 26 兰州 -0.505648 30 南宁 -0.415020 27 乌鲁木齐 -0.533712 31 贵阳 -0.548928 32 呼和浩特 -0.574011 33 海口 -0.259872 20 银川 -0.598557 34 西宁 -0.706288 35

$common

[1] 0.9363 0.9674 0.8788 0.9510 0.9759 0.9341

> factanal.rank(FA1,plot=T) $Fs

Factor1 Factor2 上海 -0.067456 3.79709 北京 -0.072373 3.00703 广州 0.663840 1.58698 深圳 5.276916 -0.41035 天津 -0.397311 0.82245 重庆 -1.007469 0.72658 杭州 0.799780 0.30360 成都 -0.223248 0.23496 青岛 -0.083085 0.11124 宁波 0.491771 0.28832 武汉 -0.576000 0.13870 大连 -0.066642 0.20664 沈阳 -0.431066 -0.07264 南京 0.215070 -0.09020 哈尔滨 -0.443843 -0.17532 济南 -0.002576 -0.22138 石家庄 -0.096202 -0.24481 福州 0.323165 -0.33778 长春 -0.266622 -0.26422 郑州 -0.306426 -0.31592 西安 -0.478449 -0.30863 长沙 -0.085087 -0.35626 昆明 -0.158979 -0.46675 厦门 0.535988 -0.41281 南昌 -0.382382 -0.60324 太原 -0.403225 -0.60623 合肥 -0.156737 -0.65326 兰州 -0.386897 -0.62448

南宁 -0.127289 -0.70295 乌鲁木齐 -0.464098 -0.60337 贵阳 -0.500832 -0.59706 呼和浩特 -0.477277 -0.67081 海口 0.433128 -0.95334 银川 -0.401344 -0.79590 西宁 -0.676739 -0.73586 $Ri

F rank 上海 1.864161 2 北京 1.466805 3 广州 1.125254 4 深圳 2.434248 1 天津 0.212364 7 重庆 -0.140739 15 杭州 0.551775 5 成都 0.005776 12 青岛 0.014043 11 宁波 0.390078 6 武汉 -0.218772 17 大连 0.069953 8 沈阳 -0.251914 19 南京 0.062486 9 哈尔滨 -0.309629 22 济南 -0.111941 14 石家庄 -0.170481 16 福州 -0.007193 13 长春 -0.265424 21 郑州 -0.311171 23 西安 -0.393570 25 长沙 -0.220627 18 昆明 -0.312814 24 厦门 0.061749 10 南昌 -0.492776 28 太原 -0.504691 29 合肥 -0.404915 26 兰州 -0.505648 30 南宁 -0.415020 27 乌鲁木齐 -0.533712 31 贵阳 -0.548928 32 呼和浩特 -0.574011 33 海口 -0.259872 20 银川 -0.598557 34

西宁 -0.706288 35

3(d6.2) (1)

> library(MASS)

> ld2=lda(x$G~.,data=x);ld2 ##贝叶斯 Call:

lda(x$G ~ ., data = x)

Prior probabilities of groups: 1 2 0.4839 0.5161

Group means: x1 x2 1 93.73 187.9 2 79.75 141.4

Coefficients of linear discriminants: LD1 x1 -0.08511 x2 -0.02074

> Zld2=predict(ld2)

> data.frame(x$G,Zld2$class,round(Zld2$x,3)) x.G Zld2.class LD1 1 1 2 0.317 2 1 1 -0.734 3 1 1 -1.710 4 1 1 -0.877 5 1 1 -1.804 6 1 2 0.678 7 1 2 0.387 8 1 1 -0.651 9 1 1 -2.517 10 1 1 -2.310 11 1 1 -1.853 12 1 1 -1.813 13 1 1 -0.962 14 1 1 -0.311 15 1 1 -2.517 16 2 2 2.295

17 2 1 -0.804 18 2 1 -0.195 19 2 2 1.653 20 2 2 0.387 21 2 2 0.014 22 2 2 1.860 23 2 2 1.735 24 2 2 1.383 25 2 1 -0.069 26 2 2 0.972 27 2 2 0.865 28 2 2 1.797 29 2 2 2.005 30 2 2 0.876 31 2 2 1.902 > newG=Zld2$class > tab3=table(x$G,newG)

> sum(diag(prop.table(tab3))) [1] 0.8065

(2)

> yx=read.table(\

> glm.sol<-glm(yx$G~yx$x1+yx$x2, family=binomial, data=yx) > summary(glm.sol) Call:

glm(formula = yx$G ~ yx$x1 + yx$x2, family = binomial, data = yx)

Deviance Residuals:

Min 1Q Median 3Q Max -1.860 -0.409 -0.111 0.350 1.795

Coefficients:

Estimate Std. Error z value Pr(>|z|) (Intercept) -21.7747 7.9009 -2.76 0.0059 ** yx$x1 0.1614 0.0616 2.62 0.0088 ** yx$x2 0.0473 0.0214 2.21 0.0271 * ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 42.943 on 30 degrees of freedom

Residual deviance: 20.397 on 28 degrees of freedom AIC: 26.4

Number of Fisher Scoring iterations: 6

第四章 回归

4.1一元线性回归

(1)

> x=c(825,215,1070,550,480,920,1350,325,670,1215) > y=c(3.5,1,4,2,1,3,4.5,1.5,3,5) > plot(x,y) (2)cor(x,y)

(3)> lxy=function(x,y){n=length(x);sum(x*y)-sum(x)*sum(y)/n} > b=lxy(x,y)/lxy(x,x) > a=mean(y)-b*mean(x) > c(a=a,b=b)

a b 0.118129074 0.003585132 (4)> SST=lxy(y,y) > SSR=b*lxy(x,y) > SSE=SST-SSR > MSR=SSR/1 > MSE=SSE/(n-2) > F=MSR/MSE

> c(SST=SST,SSR=SSR,SSE=SSE,MSR=MSR,MSE=MSE,F=MSR/MSE)

SST SSR SSE MSR MSE 18.5250000 16.6816213 1.8433787 16.6816213 0.4608447 36.1979253

(5)> yx=X=data.frame(x,y)

> fm=lm(y~x,data=yx) #一元线性回归 > fm Call:

lm(formula = y ~ x, data = yx)

Coefficients:

(Intercept) x

F 0.118129 0.003585

> summary(fm) #显著性检验 Call:

lm(formula = y ~ x, data = yx)

Residuals:

Min 1Q Median 3Q Max -0.83899 -0.33483 0.07842 0.37228 0.52594

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) 0.1181291 0.3551477 0.333 0.748 x 0.0035851 0.0004214 8.509 2.79e-05 *** ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.48 on 8 degrees of freedom

Multiple R-squared: 0.9005, Adjusted R-squared: 0.8881 F-statistic: 72.4 on 1 and 8 DF, p-value: 2.795e-05 (6)> anova(fm) #方差分析 Analysis of Variance Table

Response: y

Df Sum Sq Mean Sq F value Pr(>F) x 1 16.6816 16.6816 72.396 2.795e-05 *** Residuals 8 1.8434 0.2304 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (8)> new<-data.frame(x=1000) #预测

> lm.pred<-predict(fm,new,interval=\> lm.pred

fit lwr upr 1 3.703262 2.51949 4.887033

4.2多元线性回归

(1)> yX=read.table(\ #多元线性回归 > (fm=lm(x3~x1+x2,data=yX)) Call:

lm(formula = x3 ~ x1 + x2, data = yX)

Coefficients:

(Intercept) x1 x2 -22.7450 0.1511 1.2166

(2)> summary(fm) #显著性检验 Call:

lm(formula = x3 ~ x1 + x2, data = yX)

Residuals:

1 2 3 4 5 6 -1.1335 -3.9430 -0.6517 15.6699 -0.5939 2.7178 -16.2745

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) -22.7450 30.6939 -0.741 0.492 x1 0.1511 0.1132 1.335 0.239 x2 1.2166 1.3094 0.929 0.395

Residual standard error: 10.52 on 5 degrees of freedom

Multiple R-squared: 0.4338, Adjusted R-squared: 0.2073 F-statistic: 1.915 on 2 and 5 DF, p-value: 0.2412 (3)

> library(mvstats) > corr.test(yX) corr test:

x1 x2 x3 x1 0.0000 0.440 0.1320 x2 0.8268 0.000 0.2269 x3 1.7425 1.346 0.0000

lower is t value,upper is p value > R2=summary(fm)$r.sq > R=sqrt(R2) > R

[1] 0.6586

4.3多元线性回归

> x=read.table(\> (fm=lm(y~x1+x2,data=x)) Call:

lm(formula = y ~ x1 + x2, data = x)

Coefficients:

(Intercept) x1 x2

7 8 4.2089 #复相关系数 -5213 8509 182

> summary(fm) Call:

lm(formula = y ~ x1 + x2, data = x)

Residuals:

1 2 3 4 5 6 7 8 1617 207 1282 -704 -2215 -770 -311 893

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) -5213 12704 -0.41 0.699 x1 8509 2722 3.13 0.026 * x2 182 284 0.64 0.550 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1500 on 5 degrees of freedom

Multiple R-squared: 0.668, Adjusted R-squared: 0.535 F-statistic: 5.02 on 2 and 5 DF, p-value: 0.0637

> new<-data.frame(x1=3,x2=24,x3=50)

> lm.pred<-predict(fm,new,interval=\> lm.pred

fit lwr upr 1 24671 20497 28845

4.4 变量选择

(1)> yX=read.table(\ #多元线性回归 > library(mvstats) #相关系数 > corr.test(yX) corr test:

y x1 x2 x3 y 0.000 0.0954 0.0164 0.0180 x1 1.890 0.0000 0.7560 0.2542 x2 3.027 0.3215 0.0000 0.1014 x3 2.965 1.2285 1.8504 0.0000

lower is t value,upper is p value

> pairs(yX) #矩阵散点图 (2)

> (fm=lm(y~x1+x2+x3,data=yX))

Call:

lm(formula = y ~ x1 + x2 + x3, data = yX)

Coefficients:

(Intercept) x1 x2 x3

-348.28 3.75 7.10 12.45 (3)拟合优度检验

> R2=summary(fm)$r.sq #复相关系数 > R2

[1] 0.8055

(4)> summary(fm) #显著性检验 Call:

lm(formula = y ~ x1 + x2 + x3, data = yX)

Residuals:

Min 1Q Median 3Q Max -25.20 -17.03 2.63 11.68 33.23

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) -348.28 176.46 -1.97 0.096 .

x1 3.75 1.93 1.94 0.100 x2 7.10 2.88 2.47 0.049 * x3 12.45 10.57 1.18 0.284 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 23.4 on 6 degrees of freedom

Multiple R-squared: 0.806, Adjusted R-squared: 0.708 F-statistic: 8.28 on 3 and 6 DF, p-value: 0.0149

(5)

(fm=lm(y~x2,data=yX)) Call:

lm(formula = y ~ x2, data = yX)

Coefficients:

(Intercept) x2 -159.93 9.69

> summary(fm) #显著性检验

Call:

lm(formula = y ~ x2, data = yX)

Residuals:

Min 1Q Median 3Q Max -56.07 -18.79 5.81 25.50 32.38

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) -159.93 129.71 -1.23 0.253 x2 9.69 3.20 3.03 0.016 * ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 31.4 on 8 degrees of freedom

Multiple R-squared: 0.534, Adjusted R-squared: 0.476 F-statistic: 9.16 on 1 and 8 DF, p-value: 0.0164

(5)> (fm=lm(y~x2,data=yX)) Call:

lm(formula = y ~ x2, data = yX)

Coefficients:

(Intercept) x2 -159.93 9.69

> summary(fm) #显著性检验 Call:

lm(formula = y ~ x2, data = yX)

Residuals:

Min 1Q Median 3Q Max -56.07 -18.79 5.81 25.50 32.38

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) -159.93 129.71 -1.23 0.253 x2 9.69 3.20 3.03 0.016 * ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 31.4 on 8 degrees of freedom

Multiple R-squared: 0.534, Adjusted R-squared: 0.476

F-statistic: 9.16 on 1 and 8 DF, p-value: 0.0164

> anova(fm) #方差分析 Analysis of Variance Table

Response: y

Df Sum Sq Mean Sq F value Pr(>F) x2 1 9049 9049 9.16 0.016 * Residuals 8 7903 988 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (6)

全局择优法 > library(leaps)

> varsel=regsubsets(y~ x1+ x2+ x3,data=yX) > result=summary(varsel) >

data.frame(result$outmat,RSS=result$rss,R2=result$rsq,adjR2=result$adjr2,Cp=result$cp,BIC=result$bic)

x1 x2 x3 RSS R2 adjR2 Cp BIC 1 ( 1 ) * 7903 0.5338 0.4755 8.382 -3.026 2 ( 1 ) * * 4059 0.7605 0.6921 3.387 -7.386 3 ( 1 ) * * * 3297 0.8055 0.7083 4.000 -7.163 逐步回归法

> fm=lm(yX$y~ yX$x1+ yX$ x2+ yX$x3)

> fm.step=step(fm,direction=\为向前引入法 Start: AIC=65.98

yX$y ~ yX$x1 + yX$x2 + yX$x3

> fm.step=step(fm,direction=\为向后引入法 Start: AIC=65.98

yX$y ~ yX$x1 + yX$x2 + yX$x3

Df Sum of Sq RSS AIC 3297 66.0 - yX$x3 1 762 4059 66.1 - yX$x1 1 2072 5369 68.9 - yX$x2 1 3340 6637 71.0

> fm.step=step(fm,direction=\为逐步筛选法 Start: AIC=65.98

yX$y ~ yX$x1 + yX$x2 + yX$x3

Df Sum of Sq RSS AIC 3297 66.0

- yX$x3 1 762 4059 66.1 - yX$x1 1 2072 5369 68.9 - yX$x2 1 3340 6637 71.0

4.5曲线模型比较

> yx=read.table(\> plot(yx$x,yx$y)

> lm.1=lm(y~x);summary(lm.1)$coef #直线回归 Estimate Std. Error t value Pr(>|t|) (Intercept) 0.118129 0.3551477 0.3326 7.480e-01 x 0.003585 0.0004214 8.5086 2.795e-05 > summary(lm.1)$r.sq [1] 0.9005 >

> x1=x;x2=x^2 #二次多项式回归 > lm.2=lm(y~x1+x2);summary(lm.2)$coef

Estimate Std. Error t value Pr(>|t|) (Intercept) -4.824e-02 7.664e-01 -0.06294 0.9516

x1 4.127e-03 2.216e-03 1.86250 0.1048 x2 -3.465e-07 1.389e-06 -0.24953 0.8101 > summary(lm.2)$r.sq [1] 0.9014 >

> lm.log=lm(y~log(x));summary(lm.log)$coef #对数 Estimate Std. Error t value Pr(>|t|) (Intercept) -11.528 2.2373 -5.153 0.0008713 log(x) 2.213 0.3431 6.451 0.0001982 > summary(lm.log)$r.sq [1] 0.8387 >

> lm.exp=lm(log(y)~x);summary(lm.exp)$coef #指数 Estimate Std. Error t value Pr(>|t|) (Intercept) -0.191752 0.1899414 -1.010 0.3422743 x 0.001439 0.0002254 6.386 0.0002123 > summary(lm.exp)$r.sq [1] 0.836 >

> lm.pow=lm(log(y)~log(x));summary(lm.pow)$coef #幂函数 Estimate Std. Error t value Pr(>|t|) (Intercept) -5.0990 0.9208 -5.538 0.0005489 log(x) 0.9241 0.1412 6.545 0.0001795 > summary(lm.pow)$r.sq [1] 0.8426

4.6

(1)> lm.1=lm(y~.,data=yx) > lm.1 Call:

lm(formula = y ~ ., data = yx)

Coefficients:

(Intercept) x1 x2 x3 6.081e+03 1.172e-01 -2.245e-02 9.096e-04

> summary(lm.1) Call:

lm(formula = y ~ ., data = yx)

Residuals:

Min 1Q Median 3Q Max -418.99 -181.65 28.37 68.02 660.67

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) 6.081e+03 9.566e+03 0.636 0.538 x1 1.172e-01 2.673e-01 0.438 0.670 x2 -2.245e-02 3.321e-02 -0.676 0.513 x3 9.096e-04 8.659e-04 1.050 0.316

Residual standard error: 301.7 on 11 degrees of freedom

Multiple R-squared: 0.9133, Adjusted R-squared: 0.8896 F-statistic: 38.62 on 3 and 11 DF, p-value: 3.92e-06 (2)

> lm.2=lm(log(y)~a*log(x1)+b*log(x2)+c*log(x3/x2)+d)

Error in nls(log(y) ~ a * log(x1) + b * log(x2) + c * log(x3/x2) + d, :

'data'里的参数没有被设定初始值: x3

> lm.2=nls(log(y)~a*log(x1)+b*log(x2)+c*log(x3/x2)+d,start=list(a=1,b=1,c=1,d=3)) Error in nls(log(y) ~ a * log(x1) + b * log(x2) + c * log(x3/x2) + d, : 'data'里的参数没有被设定初始值: x3

> lm.2=nls(log(y)~a*log(x1)+b*log(x2)+c*log(x3/x2)+d,start=list(a=1,b=1,c=1,d=100)) Error in nls(log(y) ~ a * log(x1) + b * log(x2) + c * log(x3/x2) + d, : 'data'里的参数没有被设定初始值: x3

4.7

> yx=read.table(\> plot(yx$PCEXP,yx$EXPDUR)

> s=nls(EXPDUR~a*(PCEXP^b),start=list(a=600,b=0.1))

Error in nls(EXPDUR ~ a * (PCEXP^b), start = list(a = 600, b = 0.1)) : 'data'里的参数没有被设定初始值: EXPDUR, PCEXP

第五章 方差分析

5.1单因素方差分析()

> X=read.table(\>

> #单因素方差分析

> z=aov(X$x ~ factor(X$y), data=X) > summary(z)

Df Sum Sq Mean Sq F value Pr(>F) factor(X$y) 2 1721.9 860.9 49.07 1.67e-06 *** Residuals 12 210.5 17.5 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

5.2双因素方差分析

> z=anova(lm(X$x ~factor(X$A)+factor(X$B), data=X)) > summary(z)

Df Sum Sq Mean Sq F value Min. :3 Min. : 13.91 Min. : 1.546 Min. : 29.55 1st Qu.:3 1st Qu.: 75.49 1st Qu.: 23.617 1st Qu.: 51.68 Median :3 Median :137.06 Median : 45.688 Median : 73.81

Mean :5 Mean :232.86 Mean : 76.590 Mean : 73.81 3rd Qu.:6 3rd Qu.:342.34 3rd Qu.:114.112 3rd Qu.: 95.93

Max. :9 Max. :547.61 Max. :182.537 Max. :118.06 NA's :1 Pr(>F) Min. :2.00e-07 1st Qu.:1.37e-05 Median :2.73e-05 Mean :2.73e-05

3rd Qu.:4.09e-05 Max. :5.45e-05 NA's :1 > z

Analysis of Variance Table

Response: X$x

Df Sum Sq Mean Sq F value Pr(>F) factor(X$A) 3 547.61 182.537 118.06 1.520e-07 *** factor(X$B) 3 137.07 45.688 29.55 5.449e-05 *** Residuals 9 13.92 1.546 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 >

5.3双因素及交互效应

> X=read.table(\> z =aov(x ~ A+B, data=X) > summary(z)

Df Sum Sq Mean Sq F value Pr(>F) A 1 208.33 208.33 47.27 7.27e-05 *** B 1 75.00 75.00 17.02 0.00258 ** Residuals 9 39.67 4.41 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > z2 =aov(x~ A*B, data=X) #考虑交互作用 > summary(z2)

Df Sum Sq Mean Sq F value Pr(>F) A 1 208.33 208.33 53.191 8.44e-05 *** B 1 75.00 75.00 19.149 0.00236 ** A:B 1 8.33 8.33 2.128 0.18278 Residuals 8 31.33 3.92 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

5.4双因素及交互效应

> X=read.table(\> z =aov(x ~ A+B, data=X) > summary(z)

Df Sum Sq Mean Sq F value Pr(>F) A 1 1.000 1.0000 3.773 0.0656 .

B 1 1.587 1.5870 5.987 0.0233 * Residuals 21 5.566 0.2651 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > z2 =aov(x~ A*B, data=X) #考虑交互作用 > summary(z2)

Df Sum Sq Mean Sq F value Pr(>F) A 1 1.000 1.0000 3.594 0.0725 . B 1 1.587 1.5870 5.704 0.0269 * A:B 1 0.002 0.0020 0.007 0.9333 Residuals 20 5.564 0.2782 ---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

5.5正交

> X=read.table(\

> fm=lm(x~A+B+A*B+C,data=X);fm #正交 Call:

lm(formula = x ~ A + B + A * B + C, data = X)

Coefficients:

(Intercept) A B C 153.18 13.57 26.57 -2.60

> anova(fm)

Analysis of Variance Table

Response: x

Df Sum Sq Mean Sq F value Pr(>F) A 1 468.2 468.17 0.2790 0.6253 B 1 104.2 104.17 0.0621 0.8155 C 1 54.0 54.00 0.0322 0.8664 A:B 1 313.6 313.60 0.1869 0.6878 Residuals 4 6712.3 1678.07

A:B -11.20 第六章判别分析

6.6判别分析

x=read.table(\ library(MASS)

ld=lda(G~.,data=x,prior = c(1,1,1)/3);ld #线性判别 0.98 Zld=predict(ld) ##判别

data.frame(x$G,Zld$class,round(Zld$x,3)) newG=Zld$class

tab1=table(x$G,newG)

sum(diag(prop.table(tab1)))

qd=qda(G~.,data=x,prior=c(1,1,1)/3);qd #二次判别0.98 Zqd=predict(qd) newG=Zqd$class tab2=table(x$G,newG)

sum(diag(prop.table(tab2)))

ld2=lda(G~.,data=x);ld2 ##贝叶斯0.98 Zld2=predict(ld2)

data.frame(x$G,Zld2$class,round(Zld2$x,3)) newG=Zld2$class tab3=table(x$G,newG)

sum(diag(prop.table(tab3)))

library(mvstats) #距离判别(异方差)0.96 D=discrim.dist(cbind(x$x1, x$x2, x$x3),as.factor(x$G)) tab4=table(D$G,D$newG) sum(diag(prop.table(tab4)))

#距离判别(等方差) D=discrim.dist(cbind(x$x1, x$x2, x$x3),as.factor(x$G),var.equal=T) tab5=table(D$G,D$newG) sum(diag(prop.table(tab5)))

#预测 new<-data.frame(x1=131,x2=-2)

predict(qd,new,interval=\

0.8467 第七章 聚类

7.2系统聚类

Hclust法

X=read.table(\ #读取数据 > Z=scale(X) #对数据做标准化处理 > D=dist(Z) #计算距离矩阵

> hc=hclust(D,\#ward聚类法

> cbind(hc$merge,hc$height) #显示聚类过程,-表示原样品,+表示新类 > plot(hc) #画聚类图

> rect.hclust(hc,k=3) #对聚类结果画框,k=3表示分3类

H.clust法

> X=read.table(\ #读取数据 > library(mvstats)#载入函数包mvstats

> H.clust(X,\ #欧氏距离 最短距离法 H.clust(X,\#欧氏距离 最长距离法 H.clust(X,\#欧氏距离 中间距离法 H.clust(X,\#欧氏距离 类平均法 H.clust(X,\ #欧氏距离 重心法 H.clust(X,\ #欧式距离 ward法

7.3 K均值聚类

> x1=matrix(rnorm(1000,mean=0,sd=0.3),ncol=20) #均值为0,标准差为0.3的100*20的正态随机矩阵

x2=matrix(rnorm(1000,mean=1,sd=0.3),ncol=20) #均值为1,标准差为0.3的100*20的正态随机矩阵

> x=rbind(x1,x2) #按行合并为200*20的矩阵

> H.clust(x,\ #可先用系统聚类法看聚类结果 > cl<-kmeans(x,2) #用k均值法分类,存为cl,x为数据,2为分类个数 > cl

> pch1=rep(\ #生成100个“1” > pch2=rep(\ #生成100个“2”

> plot(x,col=cl$clust,pch=c(pch1,pch2),cex=0.7) #画散点图,x表示数据,col表示颜色,col= cl$clust表示按分类的类别个数确定颜色,pch为点的形状,pch=c(pch1,pch2)表示按照上两句生成的pch1和pch2做点的形状,cex为文字大小;

> points(cl$centers,col=3,pch=\ #在上述散点图中画中心点cl$centers,col=3为绿色,

pch为中心点的形状,cex是中心点的大小;

第八章主成分

8.3

> X=read.table(\> Z=scale(X)

> PCA=princomp(Z,cor=T) > PCA Call:

princomp(x = Z, cor = T)

Standard deviations:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 2.1715804 1.3719479 0.4333758 0.3271789 0.2193146 0.2121417 0.1184652

7 variables and 35 observations. > summary(PCA,loadings=T) Importance of components:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Standard deviation 2.1715804 1.3719479 0.43337577 0.32717889 0.219314628 Proportion of Variance 0.6736802 0.2688916 0.02683065 0.01529229 0.006871272 Cumulative Proportion 0.6736802 0.9425718 0.96940243 0.98469472 0.991565988 Comp.6 Comp.7 Standard deviation 0.212141665 0.118465179 Proportion of Variance 0.006429155 0.002004857 Cumulative Proportion 0.997995143 1.000000000

Loadings:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 x1 -0.410 -0.268 0.532 -0.321 0.499 -0.352 x2 -0.424 -0.252 -0.367 -0.769 -0.156 x3 -0.380 -0.388 0.267 0.102 0.630 0.471 x4 -0.403 -0.246 -0.771 -0.111 0.385 0.134 x5 -0.382 0.374 -0.602 0.416 -0.417 x6 -0.313 0.523

x7 -0.319 0.491 0.762 0.174 -0.191 > screeplot(PCA,type=\ #碎石图

> predict(PCA) #计算主成分得分

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5

上海 -6.87788274 -3.398169424 0.52291311 0.022581279 -0.46226953 北京 -5.25980318 -2.618230030 -1.46724696 0.235677042 0.32969990 广州 -3.36459218 -0.398037882 -0.45408677 -0.099874202 0.03457722 深圳 -6.35393923 6.156212902 0.16784336 -0.069604947 -0.15793478 天津 -0.83115959 -1.071310459 0.10528543 -0.264207371 0.02336946 重庆 0.07390786 -1.711822782 0.96676240 -0.077177106 0.31053336 杭州 -1.40570501 0.748877093 0.33725496 0.353000331 0.47976274 成都 0.03435130 -0.352243394 0.65979281 0.055407944 0.35352362 青岛 -0.03209509 -0.153035193 -0.11651710 -0.162406483 -0.38434372 宁波 -0.99553032 0.404783304 0.27954158 -0.652478550 0.57199231 武汉 0.56703197 -0.726327160 0.51874172 -0.186493944 0.02967364 大连 -0.17597584 -0.186870923 0.06681270 0.108494303 -0.08657494 沈阳 0.66073140 -0.441187907 0.35251165 0.098166184 -0.30237409 南京 -0.24272611 0.245112547 0.42520505 0.447357208 0.17385842 哈尔滨 0.88853669 -0.352217337 0.28869343 0.077783531 -0.22658662 济南 0.42544424 0.200713453 0.31619171 -0.048352122 0.02889606 石家庄 0.63341717 0.141198717 0.33791314 0.392768285 -0.08852391 福州 0.21015141 0.665908186 0.06527401 0.138410602 -0.15520820 长春 0.88412721 -0.037672137 0.18920289 0.280326609 -0.20400808 郑州 0.95436562 -0.082521926 0.10053633 0.116812518 0.05210342 西安 1.13367389 -0.301146183 0.04198153 -0.006649492 -0.05294141 长沙 0.76722706 0.217946274 0.10599501 -0.268563986 0.12468132 昆明 0.98089667 0.180545874 0.03443527 0.113342407 -0.15329218 厦门 0.04435567 0.955057129 -0.50288308 -0.834733163 -0.05821810 南昌 1.52007296 0.047349145 -0.13280153 -0.101951681 -0.23887441 太原 1.54588520 0.022400518 -0.27934276 -0.018057466 -0.02334993 合肥 1.30685767 0.338055360 -0.30787150 0.357034522 -0.03238981 兰州 1.56767864 0.062287567 -0.22111087 0.244219459 -0.03757529 南宁 1.34801298 0.408094680 -0.29743083 -0.166302068 0.11888019 乌鲁木齐 1.58469098 -0.069170472 -0.18582085 -0.857251667 -0.08287091 贵阳 1.63249654 -0.109469378 -0.26368129 -0.120261484 0.03205918 呼和浩特 1.75261494 -0.009311273 -0.30492024 -0.016471652 -0.01598844 海口 1.06699235 1.250753203 -0.48034492 0.847003525 0.14437471 银川 1.84766912 0.164284934 -0.43153674 0.113583729 -0.02414970 西宁 2.10821972 -0.190837023 -0.43729266 -0.051132096 -0.02051152 Comp.6 Comp.7 上海 -0.37567395 -0.173292307 北京 -0.15189702 0.211171973 广州 0.79586558 -0.224166815 深圳 -0.22674164 0.032189169 天津 0.19043844 0.005572845 重庆 -0.18616341 0.102917626 杭州 0.20558470 -0.030992179 成都 0.15143353 -0.052669269

青岛 0.31378074 -0.018662523 宁波 0.03404615 0.012025572 武汉 0.05222958 -0.002593006 大连 0.20660490 0.361186274 沈阳 0.04010763 -0.011820916 南京 -0.35423594 -0.043603288 哈尔滨 0.07436428 -0.003037734 济南 0.03799122 -0.050995466 石家庄 0.17765542 0.174788109 福州 0.17772670 -0.040500590 长春 0.23910909 0.069476722 郑州 -0.02109994 -0.116827694 西安 -0.08473393 0.029710470 长沙 -0.04207901 0.066644666 昆明 -0.08515355 0.188417974 厦门 0.04048155 0.105333445 南昌 -0.01187661 0.059335445 太原 -0.07621375 -0.123906597 合肥 -0.05994890 -0.007995920 兰州 -0.07090677 0.077805564 南宁 -0.14101603 -0.240376503 乌鲁木齐 -0.22711903 0.018119684 贵阳 -0.18562717 -0.053030882 呼和浩特 -0.10228456 -0.059971314 海口 -0.05983131 -0.100063952 银川 -0.13784221 -0.066385121 西宁 -0.13697480 -0.093803459 > library(mvstats)

> princomp.rank(PCA,m=2,plot=T) #对主成分结果PCA做排名,m=2指选择2个主成分,plot=T指做出第一主成分为横轴,第二主成分为纵轴的散点图,结果中的PC为综合得分 Comp.1 Comp.2 PC rank 上海 -6.87788274 -3.398169424 -5.88520970 1 北京 -5.25980318 -2.618230030 -4.50623005 2 广州 -3.36459218 -0.398037882 -2.51831026 4 深圳 -6.35393923 6.156212902 -2.78511341 3 天津 -0.83115959 -1.071310459 -0.89966848 5 重庆 0.07390786 -1.711822782 -0.43551533 8 杭州 -1.40570501 0.748877093 -0.79105795 6 成都 0.03435130 -0.352243394 -0.07593426 11 青岛 -0.03209509 -0.153035193 -0.06659620 12 宁波 -0.99553032 0.404783304 -0.59605673 7 武汉 0.56703197 -0.726327160 0.19806976 13 大连 -0.17597584 -0.186870923 -0.17908393 9 沈阳 0.66073140 -0.441187907 0.34638206 16

南京 -0.24272611 0.245112547 -0.10355824 10 哈尔滨 0.88853669 -0.352217337 0.53458136 19 济南 0.42544424 0.200713453 0.36133431 17 石家庄 0.63341717 0.141198717 0.49299986 18 福州 0.21015141 0.665908186 0.34016714 15 长春 0.88412721 -0.037672137 0.62116148 21 郑州 0.95436562 -0.082521926 0.65856818 22 西安 1.13367389 -0.301146183 0.72435649 23 长沙 0.76722706 0.217946274 0.61053133 20 昆明 0.98089667 0.180545874 0.75257710 24 厦门 0.04435567 0.955057129 0.30415546 14 南昌 1.52007296 0.047349145 1.09994260 27 太原 1.54588520 0.022400518 1.11127406 28 合肥 1.30685767 0.338055360 1.03048320 25 兰州 1.56767864 0.062287567 1.13822915 32 南宁 1.34801298 0.408094680 1.07987838 26 乌鲁木齐 1.58469098 -0.069170472 1.11288669 29 贵阳 1.63249654 -0.109469378 1.13555830 31 呼和浩特 1.75261494 -0.009311273 1.24998254 33 海口 1.06699235 1.250753203 1.11941461 30 银川 1.84766912 0.164284934 1.36744275 34 西宁 2.10821972 -0.190837023 1.45235775 35

第九章 因子分析

9.3 bartlett检验

> bartlett.test(X~A,data=lamp) Bartlett test of homogeneity of variances

data: X by A

Bartlett's K-squared = 5.8056, df = 3, p-value = 0.1215

从p值0.1215>0.05可得:接受原假设,认为各处理组的数据是等方差的。

9.4因子分析

> x=read.table(\(1)> cor(x)

> PCA=princomp(Z,cor=T) #特征值 > PCA Call:

princomp(x = Z, cor = T)

Standard deviations:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 2.1716 1.3719 0.4334 0.3272 0.2193 0.2121 0.1185

7 varia bles and 35 observations. (3)> princomp.rank(FA1,m=2,plot=T)

Factor1 Factor2 PC rank

深深房A -0.9138818 -0.03104 -0.48855 4 同人华塑 0.0003393 0.59491 0.28679 19 南开戈德 -0.9170108 0.29185 -0.33462 6 st昌源 0.2327717 -3.90141 -1.75896 1 山东巨力 -0.8954107 0.05649 -0.43681 5 一汽夏利 -0.3836836 -0.04236 -0.21925 8 闽东电力 -0.3886418 -0.82962 -0.60109 2 深本实b -0.3338595 0.25140 -0.05190 13 st啤酒花 -0.6603093 0.54024 -0.08192 10 云大科技 -0.6763295 -0.35002 -0.51912 3 中天科技 -0.1595595 0.03131 -0.06760 12 爱建股份 0.3795124 2.16416 1.23931 22 st轻骑 -0.7552049 0.14172 -0.32309 7 张裕A 3.3242777 0.17643 1.80773 23 阿继电器 -0.0348501 -0.06729 -0.05048 14 广州浪奇 -0.2953562 0.40181 0.04052 17 浙江震元 -0.0949556 0.02532 -0.03701 15 四环生物 2.2835306 -0.12689 1.12225 21 深宝安A 0.0737165 0.30705 0.18613 18 深发展A 0.8597350 0.30774 0.59380 20 数码网络 -0.5602640 0.20871 -0.18979 9 中色建设 -0.0508442 -0.02159 -0.03675 16 东北药 -0.0337214 -0.12892 -0.07959 11 (2)> FA0=factanal(x,6,rotation=\> FA0 Call:

factanal(x = x, factors = 6, rotation = \

Uniquenesses:

X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21

0.828 0.231 0.538 0.714 0.005 0.005 0.005 0.556 0.559 0.005 0.115 0.005 0.005 0.041 0.056

0.810 0.065 0.169 0.296 0.022 0.005

Loadings:

Factor1 Factor2 Factor3 Factor4 Factor5 Factor6

X1 0.125 -0.212 -0.308 X2 0.619 0.328 0.473 -0.200 -0.118 X3 0.296 0.278 0.454 0.277 X4 0.358 0.272 0.137 0.190 0.164 X5 0.813 0.178 -0.541 X6 0.802 0.336 -0.468 -0.127 X7 0.437 0.349 -0.722 0.390 X8 0.138 0.523 0.265 0.275 X9 0.453 -0.278 0.128 -0.335 -0.175 X10 0.669 -0.737 X11 0.127 0.443 0.536 -0.149 0.593 0.103 X12 0.744 0.394 0.506 0.177 X13 0.745 0.353 0.539 0.149 X14 0.306 0.830 0.410 X15 0.587 -0.728 0.143 0.178 0.124 X16 0.349 -0.133 -0.166 0.110 X17 0.265 0.814 0.123 0.431 X18 -0.106 -0.258 -0.401 -0.766 X19 -0.163 0.112 -0.281 0.763 X20 -0.668 0.724 X21 -0.641 0.760

Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 SS loadings 5.393 3.303 2.331 1.866 1.853 1.224 Proportion Var 0.257 0.157 0.111 0.089 0.088 0.058 Cumulative Var 0.257 0.414 0.525 0.614 0.702 0.760

Test of the hypothesis that 6 factors are sufficient.

The chi square statistic is 160.14 on 99 degrees of freedom. The p-value is 9.82e-05 > library(mvstats) > FA1=factpc(x,6) > FA1 $Vars

Vars Vars.Prop Vars.Cum Factor1 5.774 0.27497 27.50 Factor2 3.980 0.18951 46.45 Factor3 2.568 0.12230 58.68 Factor4 2.353 0.11205 69.88 Factor5 1.486 0.07076 76.96

Factor6 1.256 0.05981 82.94

$loadings

Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 X1 0.06123 -0.12784 0.08431 -0.106490 0.507578 0.428678 X2 0.57367 0.55750 0.24216 -0.171382 0.215937 0.065598 X3 0.32515 0.50968 -0.05487 -0.008307 0.414145 0.017968 X4 0.38940 0.44820 -0.02073 0.096850 -0.115383 0.123404 X5 0.68068 0.11649 0.41942 -0.055877 -0.160106 0.356871 X6 0.65221 0.06699 0.43590 0.340933 -0.386981 0.292380 X7 0.30927 -0.02019 0.36361 0.516838 -0.526854 0.097359 X8 0.19460 0.04392 -0.67534 0.466146 -0.025273 0.227640 X9 0.50315 -0.34107 0.56677 0.102965 -0.045344 -0.318164 X10 0.74670 -0.47215 -0.24045 -0.345729 -0.081529 0.079656 X11 0.08558 0.85048 -0.22376 -0.156481 -0.136126 -0.177803 X12 0.72801 0.61715 0.05517 0.047086 0.217944 -0.007108 X13 0.73381 0.59464 0.08302 -0.027193 0.233297 -0.045115 X14 0.46872 -0.17304 -0.41524 0.681711 0.087860 -0.204163 X15 0.74321 -0.46281 -0.35239 -0.254845 0.082766 -0.068711 X16 0.46016 -0.19371 0.35393 -0.197496 -0.007558 -0.686549 X17 0.41268 -0.04571 -0.47770 0.687728 0.080733 -0.204323 X18 -0.10536 -0.71247 0.31133 0.250429 0.322663 0.238292 X19 -0.07338 0.31332 -0.48550 -0.466192 -0.528048 0.092398 X20 -0.76788 0.48203 0.24640 0.310647 0.022708 -0.045188 X21 -0.71773 0.50250 0.24989 0.351082 0.097290 -0.101013

$scores

Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 深深房A -0.413757 -0.825578 0.178812 -0.160759 0.257104 0.12318 同人华塑 0.373306 -0.232509 -0.407657 0.745020 -0.003188 -1.65447 南开戈德 -0.365341 -0.849240 -0.300929 0.252863 0.820828 0.84597 st昌源 -3.216269 2.341087 1.158364 1.616815 0.507547 -0.51165 山东巨力 -0.166459 -0.970349 0.428410 -0.311449 0.630294 -0.55143 一汽夏利 0.005682 -0.471816 0.430590 -0.213537 0.472595 0.30609 闽东电力 -0.101020 -0.437254 1.630919 0.922418 -1.442581 0.90268 深本实b -0.204226 -0.253861 -0.484168 -0.397352 -0.101024 -0.21748 st啤酒花 -1.612681 0.335040 -3.082647 -1.271970 -0.040220 0.63537 云大科技 -0.719751 -0.338971 0.003001 -0.648286 -1.055890 0.68595 中天科技 0.207782 -0.336105 0.441854 -0.157125 -0.690022 0.22527 爱建股份 1.232821 -0.299769 -2.037261 3.463806 0.309697 -0.18376 st轻骑 0.211016 -1.057290 0.792725 -0.367650 0.499854 -2.84707 张裕A 2.083769 2.605825 0.219837 0.001915 -0.734240 1.09782 阿继电器 -0.059954 -0.003739 0.047509 -0.625651 -0.868769 -0.09150 广州浪奇 0.078306 -0.395996 -0.302897 0.045874 0.046583 0.30967

浙江震元 0.361388 -0.364025 0.654414 0.344559 -0.523193 0.79228 四环生物 1.236907 1.913960 0.255067 -1.116533 2.458109 -0.70767 深宝安A -0.050509 0.137387 -0.689275 -0.323976 -0.379238 -0.43154 深发展A 0.394602 0.784689 -0.646254 -1.145986 -1.798071 -1.15313 数码网络 0.105680 -0.744859 0.320710 -0.437165 2.241060 1.93030 中色建设 0.436663 -0.364432 0.824212 -0.140916 -0.023813 -0.01991 东北药 0.182044 -0.172196 0.564663 -0.074915 -0.583421 0.51504 > FA2=factpc(x,6,rotation=\

Factor Analysis for Princomp in Varimax:

> FA2 $Vars

Vars Vars.Prop Vars.Cum Factor1 4.243 20.203 20.20 Factor2 4.078 19.418 39.62 Factor3 2.576 12.266 51.89 Factor4 2.447 11.653 63.54 Factor5 2.202 10.484 74.02 Factor6 1.872 8.914 82.94

$loadings

Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 X1 0.14493 0.19159 -0.160828 -0.13109 -0.553211 -0.27043 X2 0.09531 0.84215 -0.153705 0.16450 0.021409 0.09697 X3 -0.04095 0.71003 0.098415 -0.14384 -0.039513 -0.05153 X4 0.01873 0.48490 0.112365 0.29032 0.216532 -0.10768 X5 0.33447 0.45550 -0.201793 0.65808 -0.121064 0.03360 X6 0.16362 0.27713 0.084167 0.92069 -0.074884 0.08606 X7 -0.08943 -0.06375 0.210930 0.83861 0.036223 0.14597 X8 0.14100 0.04463 0.708586 0.02680 0.102735 -0.47999 X9 0.23972 0.03987 -0.003760 0.41330 -0.277936 0.70531 X10 0.97209 0.05413 0.063776 0.10812 -0.019620 0.08241 X11 -0.23807 0.58047 -0.007797 -0.10990 0.664485 -0.08959 X12 0.12022 0.93266 0.165164 0.19165 0.085342 0.08993 X13 0.15416 0.93238 0.106952 0.15579 0.085196 0.14177 X14 0.19206 0.06885 0.928495 0.11679 -0.092672 0.10117 X15 0.93242 0.10067 0.240058 -0.06180 -0.057365 0.15158 X16 0.29410 0.12109 -0.049529 0.02860 0.046610 0.88224 X17 0.10943 0.11972 0.942781 0.07320 -0.005678 0.03595 X18 0.08247 -0.41286 0.018283 0.09119 -0.806628 0.05198 X19 0.20185 -0.03390 -0.199760 -0.08891 0.782318 -0.37716 X20 -0.96948 -0.07763 -0.112693 -0.07949 0.059837 -0.11515 X21 -0.97698 -0.01082 -0.053334 -0.10729 0.024093 -0.05888

$scores

Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 深深房A 0.15188 -0.676065 -0.27135 -0.24939 -0.61164 0.0424537 同人华塑 -0.03904 -0.150957 1.28658 -0.34725 0.40633 1.2987080 南开戈德 0.21467 -0.468926 0.19183 -0.38318 -1.16503 -0.7692311 st昌源 -4.46551 0.041063 -0.21328 -0.50851 0.09321 -0.2124695 山东巨力 0.27193 -0.493748 -0.25794 -0.55601 -0.77250 0.8130159 一汽夏利 0.20469 -0.066626 -0.39189 -0.05286 -0.75228 0.0452254 闽东电力 -0.58514 -0.839109 -0.50104 2.27138 -0.38787 0.0299644 深本实b 0.30350 -0.358381 -0.03214 -0.47929 0.32088 -0.0411652 st啤酒花 0.39769 -0.801856 0.10679 -2.32123 1.53588 -2.3831384 云大科技 0.12916 -0.981509 -0.90062 0.34865 0.51738 -0.6769425 中天科技 0.30255 -0.343603 -0.39036 0.71789 0.10487 0.1207971 爱建股份 0.01791 0.126657 4.13428 0.57902 -0.40057 -0.5323674 st轻骑 0.20794 -0.495100 0.13440 -0.99088 -0.09817 2.9972895 张裕A 0.18226 2.790341 -0.09718 1.73721 1.18997 -0.8139228 阿继电器 0.26907 -0.343164 -0.56645 0.24556 0.76285 0.0846480 广州浪奇 0.35812 -0.232499 0.17731 -0.01882 -0.20954 -0.3112073 浙江震元 0.18295 -0.199386 -0.20191 1.17034 -0.42426 -0.2187201 四环生物 0.04874 3.129470 -0.44380 -1.54470 -0.40977 0.7078564 深宝安A 0.23408 -0.144867 0.17218 -0.39694 0.81765 -0.0002455 深发展A 0.56003 0.008963 -0.35760 0.07359 2.50138 0.6010270 数码网络 0.62714 0.621199 -0.69468 -0.64102 -2.52181 -1.2554485 中色建设 0.26904 0.054601 -0.41145 0.50870 -0.43921 0.5720967 东北药 0.15634 -0.176497 -0.47169 0.83775 -0.05777 -0.0982237 F1:10,15,20,21, F2:2,3,4,12,13 F3:8,14,17 F4:5,6,7,

F5:1,11,18,19, F6:9,16