# calc_corr_ye: Calculate Expected Matrix of Correlations between Outcomes... In SimRepeat: Simulation of Correlated Systems of Equations with Multiple Variable Types

## Description

This function calculates the expected correlation matrix between Outcomes (Y) and Error Terms (E) in a correlated system of continuous variables. This system is generated with `nonnormsys` using the techniques of Headrick and Beasley (doi: 10.1081/SAC-120028431). These correlations are determined based on the beta (slope) coefficients calculated with `calc_betas`, the correlations between independent variables X_{(pj)} for a given outcome Y_p, for `p = 1, ..., M`, the correlations between error terms, and the variances. The result can be used to compare the simulated correlation matrix to the theoretical correlation matrix. If there are continuous mixture variables and the betas are specified in terms of non-mixture and mixture variables, then correlations in `corr.x` will be recalculated in terms of non-mixture or mixture variables using `rho_M1M2` and `rho_M1Y`. In this case, the dimensions of the matrices in `corr.x` should not match the number of columns of `betas`. If `error_type = "mix"`, the correlations in `corr.e` will also be recalculated and the function result will be in terms of mixture error terms. If `error_type = "non_mix"`, the function result will be in terms of non-mixture error terms. The vignette Theory and Equations for Correlated Systems of Continuous Variables gives the equations, and the vignette Correlated Systems of Statistical Equations with Non-Mixture and Mixture Continuous Variables gives examples. There are also vignettes in `SimCorrMix` which provide more details on continuous non-mixture and mixture variables.

## Usage

 ```1 2 3``` ```calc_corr_ye(betas = NULL, corr.x = list(), corr.e = NULL, vars = list(), mix_pis = list(), mix_mus = list(), mix_sigmas = list(), error_type = c("non_mix", "mix")) ```

## Arguments

 `betas` a matrix of the slope coefficients calculated with `calc_betas`, rows represent the outcomes `corr.x` list of length `M`, each component a list of length `M`; `corr.x[[p]][[q]]` is matrix of correlations for independent variables in equations p (X_{(pj)} for outcome Y_p) and q (X_{(qj)} for outcome Y_q); if p = q, `corr.x[[p]][[q]]` is a correlation matrix with `nrow(corr.x[[p]][[q]])` = # X_{(pj)} for outcome Y_p; if p != q, `corr.x[[p]][[q]]` is a non-symmetric matrix of correlations where rows correspond to covariates for Y_p so that `nrow(corr.x[[p]][[q]])` = # X_{(pj)} for outcome Y_p and columns correspond to covariates for Y_q so that `ncol(corr.x[[p]][[q]])` = # X_{(qj)} for outcome Y_q; order is 1st continuous non-mixture and 2nd components of continuous mixture variables `corr.e` correlation matrix for continuous non-mixture or components of mixture error terms `vars` a list of same length as `corr.x` of vectors of variances for X_{(pj)}, E; E term should be last; order should be the same as in `corr.x` `mix_pis` a list of same length as `corr.x`, where `mix_pis[[p]][[j]]` is a vector of mixing probabilities for X_{mix(pj)} that sum to 1, the j-th mixture covariate for outcome Y_p; the last element of `mix_pis[[p]]` is for E_p (if `error_type = "mix"`); if Y_p has no mixture variables, use `mix_pis[[p]] = NULL` `mix_mus` a list of same length as `corr.x`, where `mix_mus[[p]][[j]]` is a vector of means for X_{mix(pj)}, the j-th mixture covariate for outcome Y_p; the last element of `mix_mus[[p]]` is for E_p (if `error_type = "mix"`); if Y_p has no mixture variables, use `mix_mus[[p]] = NULL` `mix_sigmas` a list of same length as `corr.x`, where `mix_sigmas[[p]][[j]]` is a vector of standard deviations for X_{mix(pj)}, the j-th mixture covariate for outcome Y_p; the last element of `mix_sigmas[[p]]` is for E_p (if `error_type = "mix"`); if Y_p has no mixture variables, use `mix_sigmas[[p]] = NULL` `error_type` "non_mix" if all error terms have continuous non-mixture distributions, "mix" if all error terms have continuous mixture distributions, defaults to "non_mix"

## Value

`corr.ye` the matrix of correlations between Y and E

## References

Headrick TC, Beasley TM (2004). A Method for Simulating Correlated Non-Normal Systems of Linear Statistical Equations. Communications in Statistics - Simulation and Computation, 33(1). doi: 10.1081/SAC-120028431

`nonnormsys`, `calc_betas`, `rho_M1M2`, `rho_M1Y`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23``` ```# Example: system of three equations for 2 independent variables, where each # error term has unit variance, from Headrick & Beasley (2002) corr.yx <- list(matrix(c(0.4, 0.4), 1), matrix(c(0.5, 0.5), 1), matrix(c(0.6, 0.6), 1)) corr.x <- list() corr.x[[1]] <- corr.x[[2]] <- corr.x[[3]] <- list() corr.x[[1]][[1]] <- matrix(c(1, 0.1, 0.1, 1), 2, 2) corr.x[[1]][[2]] <- matrix(c(0.1974318, 0.1859656, 0.1879483, 0.1858601), 2, 2, byrow = TRUE) corr.x[[1]][[3]] <- matrix(c(0.2873190, 0.2589830, 0.2682057, 0.2589542), 2, 2, byrow = TRUE) corr.x[[2]][[1]] <- t(corr.x[[1]][[2]]) corr.x[[2]][[2]] <- matrix(c(1, 0.35, 0.35, 1), 2, 2) corr.x[[2]][[3]] <- matrix(c(0.5723303, 0.4883054, 0.5004441, 0.4841808), 2, 2, byrow = TRUE) corr.x[[3]][[1]] <- t(corr.x[[1]][[3]]) corr.x[[3]][[2]] <- t(corr.x[[2]][[3]]) corr.x[[3]][[3]] <- matrix(c(1, 0.7, 0.7, 1), 2, 2) corr.e <- matrix(0.4, nrow = 3, ncol = 3) diag(corr.e) <- 1 vars <- list(rep(1, 3), rep(1, 3), rep(1, 3)) betas <- calc_betas(corr.yx, corr.x, vars) calc_corr_ye(betas, corr.x, corr.e, vars) ```