# calc_betas: Calculate Beta Coefficients for Correlated Systems of... In SimRepeat: Simulation of Correlated Systems of Equations with Multiple Variable Types

## Description

This function calculates the beta (slope) coefficients used in `nonnormsys` by the techniques of Headrick and Beasley (doi: 10.1081/SAC-120028431). These coefficients are determined based on the correlations between independent variables X_{(pj)} for a given outcome Y_p, for `p = 1, ..., M`, the correlations between that outcome Y_p and the X_{(pj)} terms, and the variances. If there are continuous mixture variables and the matrices in `corr.yx` are specified in terms of correlations between outcomes and non-mixture and mixture variables, then the solutions are the slope coefficients for the non-mixture and mixture variables. In this case, the number of columns of the matrices of `corr.yx` should not match the dimensions of the matrices in `corr.x`. The correlations in `corr.x` will be calculated in terms of non-mixture and mixture variables using `rho_M1M2` and `rho_M1Y`. If there are continuous mixture variables and the matrices in `corr.yx` are specified in terms of correlations between outcomes and non-mixture and components of mixture variables, then the solutions are the slope coefficients for the non-mixture and components of mixture variables. In this case, the number of columns of the matrices of `corr.yx` should match the dimensions of the matrices in `corr.x`. 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_betas(corr.yx = list(), corr.x = list(), vars = list(), mix_pis = list(), mix_mus = list(), mix_sigmas = list(), error_type = c("non_mix", "mix"), n = 25, seed = 1234) ```

## Arguments

 `corr.yx` a list of length `M` = # of equations, where the p-th component is a 1 row matrix of correlations between Y_p and X_{(pj)}; if there are mixture variables and the `betas` are desired in terms of these (and not the components), then `corr.yx` should be specified in terms of correlations between outcomes and non-mixture or mixture variables, and the number of columns of the matrices of `corr.yx` should not match the dimensions of the matrices in `corr.x`; if the `betas` are desired in terms of the components, then `corr.yx` should be specified in terms of correlations between outcomes and non-mixture or components of mixture variables, and the number of columns of the matrices of `corr.yx` should match the dimensions of the matrices in `corr.x` `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 `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" `n` the number of sets of random uniform(0, 1) numbers used as starting values in `nleqslv` to find the betas `seed` the seed for random number generation

## Value

`betas` a matrix of slope coefficients where rows represent the outcomes; extra zeros are appended at the end of a row if that outcome has fewer X_{(pj)} terms

## 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`, `rho_M1M2`, `rho_M1Y`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20``` ```# 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[] <- corr.x[] <- corr.x[] <- list() corr.x[][] <- matrix(c(1, 0.1, 0.1, 1), 2, 2) corr.x[][] <- matrix(c(0.1974318, 0.1859656, 0.1879483, 0.1858601), 2, 2, byrow = TRUE) corr.x[][] <- matrix(c(0.2873190, 0.2589830, 0.2682057, 0.2589542), 2, 2, byrow = TRUE) corr.x[][] <- t(corr.x[][]) corr.x[][] <- matrix(c(1, 0.35, 0.35, 1), 2, 2) corr.x[][] <- matrix(c(0.5723303, 0.4883054, 0.5004441, 0.4841808), 2, 2, byrow = TRUE) corr.x[][] <- t(corr.x[][]) corr.x[][] <- t(corr.x[][]) corr.x[][] <- matrix(c(1, 0.7, 0.7, 1), 2, 2) vars <- list(rep(1, 3), rep(1, 3), rep(1, 3)) calc_betas(corr.yx, corr.x, vars) ```