Skip to contents

A table that holds several samples, such as a meta-analytic SEM corpus with one study per group, becomes a named list of matrices on a common set of variables plus a named vector of sample sizes: what metaSEM::tssem1(Cov =, n =) wants. Each matrix is built as irw_cov2matrix() builds it, then padded to the union of the variables across samples, in order of first appearance. A variable a sample did not measure is NA in that sample's matrix, diagonal included, which is metaSEM's convention for a missing variable. A cell a sample measured but did not report (a row with an empty value) is NA too, off the diagonal, with no warning: metaSEM takes both.

Usage

irw_cov2list(df)

Arguments

df

A table with columns stat, var1, var2, value, n and, optionally, group. Without a group column, or with one sample, the result has one element, named after that sample ("all" when there is no group column).

Value

A list: matrices (a named list of square matrices, named by group exactly as the table gives it), n (a named integer vector, one N per sample), type ("cor" or "cov", the same for every sample), variables (the common variable set), and sd, mean and rel (named lists of named vectors, empty vectors where a sample reports none). Reliabilities (rel) are what a correction for attenuation needs, matched to each study's matrix.

See also

irw_cov2matrix() for one sample.

Examples

pub <- data.frame(
  stat  = "cor",
  var1  = c("a", "b", "b", "a", "c", "c"),
  var2  = c("a", "a", "b", "a", "a", "c"),
  value = c(1, 0.4, 1, 1, 0.3, 1),
  n     = c(100, 100, 100, 80, 80, 80),
  group = c(rep("study 1", 3), rep("study 2", 3)))
x <- irw_cov2list(pub)
x$matrices
#> $`study 1`
#>     a   b  c
#> a 1.0 0.4 NA
#> b 0.4 1.0 NA
#> c  NA  NA NA
#> 
#> $`study 2`
#>     a  b   c
#> a 1.0 NA 0.3
#> b  NA NA  NA
#> c 0.3 NA 1.0
#> 
x$n
#> study 1 study 2 
#>     100      80 
# metaSEM::tssem1(x$matrices, x$n)