reshape_mat2dat {psychmeta}R Documentation

Extract a long-format correlation database from a correlation matrix and its supporting vectors/matrices of variable information

Description

This function is designed to extract data from a correlation matrix that is in the format commonly published in journals, with leading columns of construct names and descriptive statistics being listed along with correlation data.

Usage

reshape_mat2dat(
  var_names,
  cor_data,
  common_data = NULL,
  unique_data = NULL,
  diag_label = NULL,
  lower_tri = TRUE,
  data = NULL
)

Arguments

var_names

Vector (or scalar column name to match with data) containing variable names.

cor_data

Square matrix (or vector of column names to match with data) containing correlations among variables.

common_data

Vector or matrix (or vector of column names to match with data) of data common to both X and Y variables (e.g., sample size, study-wise moderators).

unique_data

Vector or matrix (or vector of column names to match with data) of data unique to X and Y variables (e.g., mean, SD, reliability).

diag_label

Optional name to attribute to values extracted from the diagonal of the matrix (if NULL, no values are extracted from the diagonal).

lower_tri

Logical scalar that identifies whether the correlations are in the lower triangle (TRUE) or in the upper triangle FALSE of the matrix.

data

Matrix or data frame containing study data (when present, column names of data will be matched to column names provided as other arguments).

Value

Long-format data frame of correlation data, variable names, and supporting information

Author(s)

Jack W. Kostal

Examples

## Create a hypothetical matrix of data from a small study:
mat <- data.frame(var_names = c("X", "Y", "Z"),
                  n = c(100, 100, 100),
                  mean = c(4, 5, 3),
                  sd = c(2.4, 2.6, 2),
                  rel = c(.8, .7, .85),
                  reshape_vec2mat(cov = c(.3, .4, .5)))

## Arguments can be provided as quoted characters or as the unquoted names of `data`'s columns:
reshape_mat2dat(var_names = var_names,
               cor_data = c("Var1", "Var2", "Var3"),
               common_data = "n",
               unique_data = c("mean", "sd", "rel"),
               data = mat)

## Arguments can also provided as raw vectors, matrices, or data frames, without a data argument:
reshape_mat2dat(var_names = mat[,1],
               cor_data = mat[,6:8],
               common_data = mat[,2],
               unique_data = mat[,3:5])

## If data is not null, arguments can be a mix of matrix/data frame/vector and column-name arguments
reshape_mat2dat(var_names = mat[,1],
               cor_data = mat[,6:8],
               common_data = "n",
               unique_data = c("mean", "sd", "rel"),
               data = mat)

[Package psychmeta version 2.6.5 Index]