gen_z_varcov: gen_z_varcov

View source: R/gen_z_varcov.R

gen_z_varcovR Documentation

gen_z_varcov

Description

This function constructs the variance-covariance matrix used in generating multivariate normal values for a school-level predictor, z. The variance- covariance matrix for the predictor is a square matrix with dimensions of .n_sch (total number of schools) x .n_sch. The values given in .clust_cov define a form of a Toeplitz structure, such that the values on the main diagonal take a value of .clust_cov[1], the values on the first off diagonal take a value of .clust_cov[2], etc. All values not defined by .clust_cov default to 0.

Usage

gen_z_varcov(.n_sch, .clust_cov)

Arguments

.n_sch

Numeric scalar. Gives the total number of schools in the dataset. The variance-covariance matrix for predictor z will have dimensions .n_sch x .n_sch.

.clust_cov

Numeric vector. The first element of the vector gives the variance of all schools' predictors, z. If present, the second element gives the covariance of z between schools k and k + 1. The values given in .clust_cov apply to all schools (that is, similar to a Toeplitz pattern). Any off-diagonal values (i.e., covariances) not specified will default to 0. The main diagonal is the variance explained by the predictor.

Details

It is important to note that because this simulation is intended for use with a single school-level predictor, the proportion of variance explained by the predictor out of the total school-level variance will be equal to .clust_cov[1] / (residual variance + .clust_cov[1]).

Value

This function returns a matrix of dimensions .n_sch x .n_sch, the variance-covariance matrix for a school-level predictor, z. This matrix can be used to generate multivariate normal values for predictor z.

Examples

## Not run: 

# give values for the variance (0.8), covariance between schools
# k & k + 1 (0.3), and schools k and k + 2 (0.1)
cov_vec <- c(0.8, 0.3, 0.1)

# output the variance-covariance matrix
gen_z_varcov(.n_sch = 50, .clust_cov = cov_vec)


## End(Not run)

tessaleejohnson/corclus documentation built on Oct. 11, 2022, 3:46 a.m.