can_corr: Canonical correlation analysis

View source: R/can_cor.R

can_corrR Documentation

Canonical correlation analysis



Performs canonical correlation analysis with collinearity diagnostic, estimation of canonical loads, canonical scores, and hypothesis testing for correlation pairs.


  by = NULL,
  use = "cor",
  test = "Bartlett",
  prob = 0.05,
  center = TRUE,
  stdscores = FALSE,
  verbose = TRUE,
  collinearity = TRUE



The data to be analyzed. It can be a data frame (possible with grouped data passed from dplyr::group_by().


A comma-separated list of unquoted variable names that will compose the first (smallest) and second (highest) group of the correlation analysis, respectively. Select helpers are also allowed.


One variable (factor) to compute the function by. It is a shortcut to dplyr::group_by(). To compute the statistics by more than one grouping variable use that function.


The matrix to be used. Must be one of 'cor' for analysis using the correlation matrix (default) or 'cov' for analysis using the covariance matrix.


The test of significance of the relationship between the FG and SG. Must be one of the 'Bartlett' (default) or 'Rao'.


The probability of error assumed. Set to 0.05.


Should the data be centered to compute the scores?


Rescale scores to produce scores of unit variance?


Logical argument. If TRUE (default) then the results are shown in the console.


Logical argument. If TRUE (default) then a collinearity diagnostic is performed for each group of variables according to Olivoto et al.(2017).


If .data is a grouped data passed from dplyr::group_by() then the results will be returned into a list-column of data frames.

  • Matrix The correlation (or covariance) matrix of the variables

  • MFG, MSG The correlation (or covariance) matrix for the variables of the first group or second group, respectively.

  • MFG_SG The correlation (or covariance) matrix for the variables of the first group with the second group.

  • Coef_FG, Coef_SG Matrix of the canonical coefficients of the first group or second group, respectively.

  • Loads_FG, Loads_SG Matrix of the canonical loadings of the first group or second group, respectively.

  • Score_FG, Score_SG Canonical scores for the variables in FG and SG, respectively.

  • Crossload_FG, Crossload_FG Canonical cross-loadings for FG variables on the SG scores, and cross-loadings for SG variables on the FG scores, respectively.

  • SigTest A dataframe with the correlation of the canonical pairs and hypothesis testing results.

  • collinearity A list with the collinearity diagnostic for each group of variables.


Tiago Olivoto


Olivoto, T., V.Q. Souza, M. Nardino, I.R. Carvalho, M. Ferrari, A.J. Pelegrin, V.J. Szareski, and D. Schmidt. 2017. Multicollinearity in path analysis: a simple method to reduce its effects. Agron. J. 109:131-142. doi: 10.2134/agronj2016.04.0196



cc1 <- can_corr(data_ge2,
               FG = c(PH, EH, EP),
               SG = c(EL, ED, CL, CD, CW, KW, NR))

# Canonical correlations for each environment
cc3 <- data_ge2 %>%
       can_corr(FG = c(PH, EH, EP),
                SG = c(EL, ED, CL, CD, CW, KW, NR),
                by = ENV,
                verbose = FALSE)

metan documentation built on March 7, 2023, 5:34 p.m.