
Define a variance-covariance matrix for any named effect
Source:R/define_effect_cov_matrix.R
define_effect_cov_matrix.RdSingle entry point for storing all variance and covariance data in tidybreed.
Routes to trait_var_comp for genetic effects and to phenotype_var_comp for
phenotype-level effects.
Common effect_name values:
"gen_add"— additive genetic (co)variances (G matrix). Written totrait_var_comp. Used bydefine_additive_effects()when rescaling to target variance and as the sampling distribution for multi-trait draws."dominance","epistasis"— future genetic effects. Written totrait_var_comp. Row/column names are trait names."residual"— residual (co)variances (R matrix). Routed tophenotype_var_compwitheffect_name = "residual". Row/column names are phenotype names. Equivalent to callingdefine_residual_cov()withcondition_column = NULL. Use this for a multi-phenotype correlated residual matrix; for a single scalar residual useresidual_varindefine_phenotype()instead.Any named random effect (
"hys","litter","pen", …) — written tophenotype_var_comp. Must match theeffect_nameused indefine_effect_random(). Row/column names are phenotype names.
define_effect_cov_matrix() can be called before define_trait() or
define_effect_random() — no prior setup is required.
All n² pairs are stored. Previous entries for this effect_name × names
combination are replaced.
Arguments
- pop
A
tidybreed_popobject.- effect_name
Character. Label for the variance component, e.g.
"gen_add","residual","hys".- cov_matrix
A numeric square matrix. Must be symmetric within
tol. Row and column names are used as trait/phenotype names whentrait_namesis not supplied.- trait_names
Optional character vector of trait/phenotype names (length ==
nrow(cov_matrix)). Overrides the matrix'srownames/colnames.- tol
Numeric. Tolerance for symmetry check (default
1e-9).
Examples
if (FALSE) { # \dontrun{
# Additive genetic covariance matrix → trait_var_comp
G <- matrix(c(100, -20, -20, 50), 2, 2,
dimnames = list(c("ADG", "BF"), c("ADG", "BF")))
pop <- pop |>
define_effect_cov_matrix("gen_add", G)
# Residual → phenotype_var_comp (effect_name = "residual")
R <- matrix(c(30, 5, 5, 10), 2, 2,
dimnames = list(c("ADG", "BF"), c("ADG", "BF")))
pop <- pop |>
define_effect_cov_matrix("residual", R)
# Multi-phenotype HYS covariance → phenotype_var_comp (effect_name = "hys")
R_hys <- matrix(c(0.2, 0.05, 0.05, 0.3), 2, 2,
dimnames = list(c("ADG", "BF"), c("ADG", "BF")))
pop <- pop |>
define_effect_cov_matrix("hys", R_hys)
} # }