本帖最后由 天空中的风 于 2015-12-18 21:06 编辑
我在运行R语言中PMA包的CCA函数时,算出来的典型载荷没有稀疏性,可是用PMA包中自带的命令就有,不知道怎么回事?
各位帮忙分析下原因。
代码如下:
v1<-matrix(c(rep(1,20),rep(-1,20),rep(0,260)),ncol=1)
v2<-matrix(c(rep(0,360),rep(1,20),rep(-1,20)),ncol=1)
set.seed(2013)
epsilon1<-rnorm(300,0,0.1)
epsilon2<-rnorm(400,0,0.1)
u<-rnorm(100,1,1)
X<-(v1+epsilon1)%*%u
Y<-(v2+epsilon2)%*%u
tx<-t(X)
ty<-t(Y)
library("PMA")
perm.out<-CCA.permute(tx,ty,typex="standard",typez="standard",penaltyxs=seq(.01,.5,len=50),penaltyzs=seq(.01,.5,len=50))
print(perm.out)
out<-CCA(tx,ty,typex="standard",typez="standard",K=1,penaltyx=perm.out$bestpenaltyx,penaltyz=perm.out$bestpenaltyz)
print(out)
其中penaltyxs与penlatyzs换成0.5到1之间也没有稀疏性结果,可是用包里自带的命令产生的数据
u <- matrix(c(rep(1,25),rep(0,75)),ncol=1)
v1 <- matrix(c(rep(1,50),rep(0,450)),ncol=1)
v2 <- matrix(c(rep(0,50),rep(1,50),rep(0,900)),ncol=1)
x <- u%*%t(v1) + matrix(rnorm(100*500),ncol=500)
z <- u%*%t(v2) + matrix(rnorm(100*1000),ncol=1000)
perm.out <- CCA.permute(x,z,typex="standard",typez="standard",nperms=7, penaltyxs=seq(.1,.7,len=10), penaltyzs=seq(.1,.7,len=10), uneg=TRUE, vpos=TRUE)
print(perm.out)
out <- CCA(x,z,typex="standard",typez="standard",K=1,penaltyx=perm.out$bestpenaltyx,penaltyz=perm.out$bestpenaltyz,
v=perm.out$v.init, uneg=TRUE, vpos=TRUE)
print(out)
这样显示的结果就有:
Num non-zeros u's: 72
Num non-zeros v's: 169
Type of x: standard
Type of z: standard
Penalty for x: L1 bound is 0.3
Penalty for z: L1 bound is 0.3
U's constrained to be negative
V's constrained to be positive
Cor(Xu,Zv): 0.9178954
试了好久都不知道原因。本人初次接触R语言,望各位大神帮忙。 |