cancor (x, y, xcenter = TRUE, ycenter = TRUE)
x,y | two matrices of data. The number of rows (which represent observations) must be the same in each. Missing values (NAs) are not accepted. |
xcenter | controls the centering applied to the columns of x before computing the canonical analysis. If TRUE or if the argument is missing, column means are removed. If FALSE, no centering is done. If the argument is numeric, the numeric values are removed from the corresponding columns. |
ycenter | controls the centering of the columns of y analogously to xcenter for the columns of x. |
cor | vector of the correlations between the pairs of variables. |
xcoef | the matrix of linear combinations of the columns of x. The first column of xcoef is the linear combination of columns of x corresponding to the first canonical correlation, etc. The row names are the selected column names of x, that is: colnames(x)[qr(x)$pivot][1:qr(x)$rank] |
ycoef | matrix like xcoef, but originating from y, i.e., The first column of ycoef is the linear combination of columns of y corresponding to the first canonical correlation, etc.. The row names are the selected column names of y, that is: colnames(y)[qr(y)$pivot][1:qr(y)$rank] |
xcenter | vector of values subtracted from the columns of x. |
ycenter | vector of values subtracted from the columns of y. |
# canonical decomposition with column means swept out x <- Sdatasets::longley[, 1:3] y <- Sdatasets::longley[, 4:5] cancor(x, y)# canonical decomposition with column medians of x subtracted out, # y as is: cancor(x, y, apply(x, 2, median), FALSE)
soil <- Sdatasets::evap.x[,1:3] air <- Sdatasets::evap.x[,-1:-3] cc.airsoil <- cancor(air, soil) can.air <- air %*% cc.airsoil$xcoef can.soil <- soil %*% cc.airsoil$ycoef # plot(can.air[,1], can.soil[,1], xlab="first air canonical variable", # ylab="first soil canonical variable") # par(mfrow=c(2, 1)) # barplot(cc.airsoil$xcoef[,1], ylab="first air loadings", # names=dimnames(air)[[2]], density=20) # barplot(cc.airsoil$ycoef[,1], ylab="first soil loadings", # names=dimnames(soil)[[2]], density=20, space=1.4)