# Canonical correlation analysis of knee-hip curves
oldpar <- par(no.readonly=TRUE)
gaittime <- (1:20)/21
gaitrange <- c(0,1)
gaitbasis <- create.fourier.basis(gaitrange,21)
gaitnbasis <- gaitbasis$nbasis
lambda <- 10^(-11.5)
harmaccelLfd <- vec2Lfd(c(0, 0, (2*pi)^2, 0))
gaitfdPar <- fdPar(fd(matrix(0,gaitnbasis,1), gaitbasis), harmaccelLfd,
lambda)
gaitfd <- smooth.basis(gaittime, gait, gaitfdPar)$fd
ccafdPar <- fdPar(gaitfd, harmaccelLfd, 1e-8)
ccafd0 <- cca.fd(gaitfd[,1], gaitfd[,2], ncan=3, ccafdPar, ccafdPar)
# display the canonical correlations
round(ccafd0$ccacorr[1:6],3)
# plot the unrotated canonical weight functions
plot.cca.fd(ccafd0)
# compute a VARIMAX rotation of the canonical variables
ccafd1 <- varmx.cca.fd(ccafd0)
# plot the rotated canonical weight functions
plot.cca.fd(ccafd1)
par(oldpar)
Run the code above in your browser using DataLab