# Canonical correlation analysis of knee-hip curves
gaittime <- (1:20)/21
gaitrange <- c(0,1)
gaitbasis <- create.fourier.basis(gaitrange,21)
lambda <- 10^(-11.5)
harmaccelLfd <- vec2Lfd(c(0, 0, (2*pi)^2, 0))
gaitfd <- fda::fd(matrix(0,gaitbasis$nbasis,1), gaitbasis)
gaitfdPar <- fda::fdPar(gaitfd, harmaccelLfd, lambda)
gaitfd <- fda::smooth.basis(gaittime, gait, gaitfdPar)$fd
ccafdPar <- fda::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)
# compute a VARIMAX rotation of the canonical variables
ccafd <- varmx.cca.fd(ccafd0)
# plot the canonical weight functions
oldpar <- par(no.readonly= TRUE)
plot.cca.fd(ccafd)
par(oldpar)
Run the code above in your browser using DataLab