# first, do CCA with type="standard"
# A simple simulated example
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)
# Can run CCA with default settings, and can get e.g. 3 components
out <- CCA(x,z,type="standard",K=3)
print(out,verbose=TRUE) # To get less output, just print(out)
# Or can use CCA.permute to choose optimal parameter values
perm.out <- CCA.permute(x,z,type="standard",nperms=7,sumabss=seq(0.1,.75,len=12))
print(perm.out)
plot(perm.out)
out <- CCA(x,z,type="standard",K=1,sumabs=perm.out$bestsumabs, v=perm.out$v.init)
print(out)
# Now try CCA with a constraint that elements of u must be negative and
# elements of v must be positive:
perm.out <- CCA.permute(x,z,type="standard",nperms=7,
sumabss=seq(0.1,.75,len=12), uneg=TRUE, vpos=TRUE)
print(perm.out)
plot(perm.out)
out <- CCA(x,z,type="standard",K=1,sumabs=perm.out$bestsumabs,
v=perm.out$v.init, uneg=TRUE, vpos=TRUE)
print(out)
# Suppose we also have a quantitative outcome, y, and we want to find
# features in x and z that are correlated with each other and with the
# outcome:
y <- rnorm(nrow(x))
perm.out <- CCA.permute(x,z,type="standard",outcome="quantitative",y=y)
print(perm.out)
out<-CCA(x,z,type="standard",outcome="quantitative",y=y,sumabs=perm.out$bestsumabs)
print(out)
# now, do CCA with type="ordered"
# Example involving the breast cancer data: gene expression + CGH
set.seed(22)
data(breastdata)
attach(breastdata)
dna <- t(dna)
rna <- t(rna)
perm.out <- CCA.permute(rna,dna[,chrom==1],type="ordered",nperms=5)
# We run CCA using all gene exp. data, but CGH data on chrom 1 only.
print(perm.out)
plot(perm.out)
out <- CCA(rna,dna[,chrom==1], type="ordered",sumabsu=perm.out$bestsumabsu,
v=perm.out$v.init, lambda=perm.out$lambda, xnames=substr(genedesc,1,20),
znames=paste("Pos", sep="", nuc[chrom==1])) # Save time by inputting lambda and v
print(out) # could do print(out,verbose=TRUE)
print(genechr[out$u!=0]) # Cool! The genes associated w/ gain or loss
# on chrom 1 are located on chrom 1!!
par(mfrow=c(1,1))
PlotCGH(out$v, nuc=nuc[chrom==1], chrom=chrom[chrom==1],
main="Regions of gain/loss on Chrom 1 assoc'd with gene expression")
detach(breastdata)
Run the code above in your browser using DataLab