1.典型相关分析 R

test<-read.csv("D:\\data\\hongputao_l.csv",header=T)
test2<-scale(test[,1:10])
ca<-cancor(test2[,1:8],test2[,9:10])
#由ca分析结果可知典型变量应选1、2两对
U<-as.matrix(test2[, 1:8]) %*% ca$xcoef
V<-as.matrix(test2[, 9:10]) %*% ca$ycoef
plot(U[,1], V[,1], xlab="U1", ylab="V1")
plot(U[,2], V[,2], xlab="U2", ylab="V2")

#相关系数检验R程序
source("D:/data/R/corcoef.test.R")
corcoef.test(r=ca$cor,n=20,p=3,q=3)
> ca
$cor
[1] 0.9213551 0.5886030

$xcoef
                [,1]         [,2]         [,3]          [,4]
主成分1  0.163498177  0.079948250 -0.039715201  0.0158801038
X2       0.040681260  0.014842622  0.184701392 -0.0097196244
X3       0.075116846 -0.172302831  0.010676318  0.0150943148
X4      -0.018458341  0.008431296  0.012791371  0.1945832677
X5      -0.005089435 -0.016013333 -0.014198980  0.0007542678
X6       0.026995286 -0.026846990 -0.032739004  0.0031734533
X7       0.057372365  0.005033856 -0.009561037  0.0027595133
X8       0.006740071 -0.032979314 -0.033573241  0.0024787198
                 [,5]         [,6]          [,7]          [,8]
主成分1  0.0076888774 -0.020604651 -0.0549986881  0.0004009247
X2       0.0166091983  0.029483915 -0.0026492560 -0.0350001342
X3      -0.0123186358 -0.035120994 -0.0188409850  0.0323835548
X4       0.0004484457  0.002930929  0.0032809836 -0.0019793391
X5       0.1948450920 -0.002273650  0.0001750191  0.0026868876
X6      -0.0017595125  0.189389465 -0.0053759902  0.0054545766
X7       0.0009826550 -0.003860236  0.1871611541  0.0006461388
X8      -0.0024376501 -0.006095797 -0.0023874170 -0.1901219807

$ycoef
                [,1]        [,2]
主成分1.1 0.19129779 -0.04320525
得分2     0.04320498  0.19129785

 

posted on 2016-01-21 20:34  planet  阅读(741)  评论(0编辑  收藏  举报