Multi-Level Genetic, Phenotypic, and Environmental Correlation Engine
compute_correlation.RdThe compute_correlation function calculates genotypic (\(r_g\)), phenotypic (\(r_p\)),
and environmental (\(r_e\)) correlation coefficient matrices across quantitative traits using
analysis of variance (ANOVA) and covariance (ANCOVA) partitions, with integrated significance flags.
Arguments
- data
A
data.framecontaining experimental phenotypic records withGenotypeandReplication(orRep) factors.- traits
A character vector specifying numeric trait columns to evaluate. Defaults to
NULLfor automatic detection.- reporting_level
An integer flag defining console trace settings:
0for silent execution and1for displaying summary matrices with significance codes. Defaults to1.
Value
Invisibly returns a structured named list of class "list" containing 9 correlation and significance matrices:
- genotypic_correlation
A
data.framematrix of genotypic correlation coefficients (\(r_g\)) between evaluated traits.- phenotypic_correlation
A
data.framematrix of phenotypic correlation coefficients (\(r_p\)) between evaluated traits.- environmental_correlation
A
data.framematrix of environmental correlation coefficients (\(r_e\)) between evaluated traits.- genotypic_significance
A
data.framematrix of genotypic correlations formatted with significance stars (***,**,*, orns).- phenotypic_significance
A
data.framematrix of phenotypic correlations formatted with significance stars.- environmental_significance
A
data.framematrix of environmental correlations formatted with significance stars.- genotypic_p_values
A
data.framematrix containing raw calculated two-tailed p-values for genotypic correlations.- phenotypic_p_values
A
data.framematrix containing raw calculated two-tailed p-values for phenotypic correlations.- environmental_p_values
A
data.framematrix containing raw calculated two-tailed p-values for environmental correlations.
If reporting_level >= 1, formatted correlation matrices with significance flags are printed directly to the console before returning the output object.
Details
The engine partitions variance and covariance components using mean squares (MS) and mean cross-products (MCP): $$r_g = \frac{Cov_g}{\sqrt{\sigma^2_{g1} \cdot \sigma^2_{g2}}}$$ $$r_p = \frac{Cov_p}{\sqrt{\sigma^2_{p1} \cdot \sigma^2_{p2}}}$$ $$r_e = \frac{Cov_e}{\sqrt{\sigma^2_{e1} \cdot \sigma^2_{e2}}}$$
Examples
# Load benchmark breeding dataset
data(gv_data, package = "AgriDataTools")
# Define trait columns
my_traits <- c("PH", "SL", "PL", "NOT", "NOSS", "TGW", "GYPM")
# Run multi-level correlation engine
corr_results <- compute_correlation(
data = gv_data,
traits = my_traits,
reporting_level = 1
)
#>
#> ================================================================================
#> MULTI-LEVEL CORRELATION ANALYSIS (Genotypic, Phenotypic & Environmental)
#> Significance Codes: *** p<=0.001, ** p<=0.01, * p<=0.05, ns = non-significant
#> ================================================================================
#>
#> --- GENOTYPIC CORRELATION MATRIX (rg) WITH SIGNIFICANCE ---
#> PH SL PL NOT NOSS TGW
#> PH 1.0000 -0.0514 ns 0.4349 ** -0.1045 ns 0.0294 ns 0.1641 ns
#> SL -0.0514 ns 1.0000 -0.0434 ns 0.2178 ns 0.2860 ns 0.2560 ns
#> PL 0.4349 ** -0.0434 ns 1.0000 -0.0579 ns 0.0360 ns 0.2335 ns
#> NOT -0.1045 ns 0.2178 ns -0.0579 ns 1.0000 0.1296 ns -0.3321 *
#> NOSS 0.0294 ns 0.2860 ns 0.0360 ns 0.1296 ns 1.0000 -0.0565 ns
#> TGW 0.1641 ns 0.2560 ns 0.2335 ns -0.3321 * -0.0565 ns 1.0000
#> GYPM 0.5398 *** 0.1275 ns 0.1992 ns 0.0431 ns 0.4647 ** 0.1400 ns
#> GYPM
#> PH 0.5398 ***
#> SL 0.1275 ns
#> PL 0.1992 ns
#> NOT 0.0431 ns
#> NOSS 0.4647 **
#> TGW 0.1400 ns
#> GYPM 1.0000
#>
#> --- PHENOTYPIC CORRELATION MATRIX (rp) WITH SIGNIFICANCE ---
#> PH SL PL NOT NOSS TGW
#> PH 1.0000 -0.0657 ns 0.4269 ** -0.0972 ns 0.0379 ns 0.1532 ns
#> SL -0.0657 ns 1.0000 -0.0536 ns 0.1964 ns 0.2265 ns 0.2114 ns
#> PL 0.4269 ** -0.0536 ns 1.0000 -0.0614 ns 0.0365 ns 0.2094 ns
#> NOT -0.0972 ns 0.1964 ns -0.0614 ns 1.0000 0.1137 ns -0.2949 ns
#> NOSS 0.0379 ns 0.2265 ns 0.0365 ns 0.1137 ns 1.0000 -0.0596 ns
#> TGW 0.1532 ns 0.2114 ns 0.2094 ns -0.2949 ns -0.0596 ns 1.0000
#> GYPM 0.5121 *** 0.1099 ns 0.1920 ns 0.0385 ns 0.4560 ** 0.1316 ns
#> GYPM
#> PH 0.5121 ***
#> SL 0.1099 ns
#> PL 0.1920 ns
#> NOT 0.0385 ns
#> NOSS 0.4560 **
#> TGW 0.1316 ns
#> GYPM 1.0000
#>
#> --- ENVIRONMENTAL CORRELATION MATRIX (re) WITH SIGNIFICANCE ---
#> PH SL PL NOT NOSS TGW
#> PH 1.0000 -0.1563 ns 0.3647 *** -0.0243 ns 0.1700 ns 0.0366 ns
#> SL -0.1563 ns 1.0000 -0.1098 ns 0.0803 ns -0.2644 * -0.0682 ns
#> PL 0.3647 *** -0.1098 ns 1.0000 -0.0936 ns 0.0502 ns -0.0130 ns
#> NOT -0.0243 ns 0.0803 ns -0.0936 ns 1.0000 -0.1382 ns 0.1410 ns
#> NOSS 0.1700 ns -0.2644 * 0.0502 ns -0.1382 ns 1.0000 -0.1168 ns
#> TGW 0.0366 ns -0.0682 ns -0.0130 ns 0.1410 ns -0.1168 ns 1.0000
#> GYPM 0.0432 ns -0.0902 ns 0.2054 ns -0.1057 ns 0.1246 ns -0.1229 ns
#> GYPM
#> PH 0.0432 ns
#> SL -0.0902 ns
#> PL 0.2054 ns
#> NOT -0.1057 ns
#> NOSS 0.1246 ns
#> TGW -0.1229 ns
#> GYPM 1.0000
#>
#> ================================================================================
#>