make_VCV_matrix: make_VCV_matrix

View source: R/make_VCV_matrix.R

make_VCV_matrixR Documentation

make_VCV_matrix

Description

Function for generating simple covariance and correlation matrices based on a clustered variable

Usage

make_VCV_matrix(
  data,
  matrix = NULL,
  V,
  m,
  sd,
  n,
  cluster,
  obs,
  type = c("vcv", "cor"),
  vcal = c("none", "lnOR", "ROM"),
  rho = 0.5
)

Arguments

data

Dataframe object containing effect sizes, their variance, unique IDs and clustering variable

matrix

Sometimes clustering can get quite complicated. Here you can 'daisy' chain matrices for different levels of clustering to build a combined matrix. Just add in the matrix with an existing cluster and set up a new cluster.

V

Name of the variable (as a string – e.g, "V1") containing effect size variances variances

m

Mean of the control group that is shared. Only used when vcal does not equal "none".

sd

Standard deviation of the control group that is shared. Only used when vcal does not equal "none".

n

Sample size of the control group that is shared.Only used when vcal does not equal "none".

cluster

Name of the variable (as a string – e.g, "V1") indicating which effects belong to the same cluster. Same value of 'cluster' are assumed to be nonindependent (correlated).

obs

Name of the variable (as a string – e.g, "V1") containing individual IDs for each value in the V (Vector of variances). If this parameter is missing, label will be labelled with consecutive integers starting from 1.

type

Optional logical parameter indicating whether a full variance-covariance matrix (default or "vcv") is needed or a correlation matrix ("cor") for the non-independent blocks of variance values.

vcal

The calculation of the covariance. Defaults to "none" in which case rho is used. Otherwise, "ROM" (log response ratio) or "LOR" (log odds ratios) can be calculated based on large-sample approximations.

rho

Known or assumed correlation value among effect sizes sharing same 'cluster' value. Default value is 0.5.

Examples

{
data(sparrows)
# Add sampling variance
sparrows$v <- 1 / (sparrows$SampleSize - 3)
# Fake grouping
sparrows$group1 <- rep(1:2, length.out = nrow(sparrows))
# Calculate V based on Place grouping, just for demonstration purposes. 
V <- make_VCV_matrix(data = sparrows, V = "v", cluster = "Place", type = "vcv", vcal = "none", rho = 0.5)
# Now we an add the second level of clustering
V <- make_VCV_matrix(data = sparrows, matrix = V, V = "v", cluster = "group1", type = "vcv", vcal = "none", rho = 0.5)

}

daniel1noble/metaAidR documentation built on Oct. 14, 2023, 3:23 p.m.