partial_correltable {scipub}R Documentation

Create partial correlation table (with stars for significance) for scientific publication

Description

The partial_correltable function can be used to create partial correlation table (with stars for significance) for scientific publication This is intended to summarize partial correlations between (vars) from an input dataset (data), residualizing all vars by partialvars. This function allows for numeric, binary, and factor variables as partialvars. but only numeric vars are used and any non-numeric vars will be dropped. All other flags follow from scipub::correltable. Correlations are based on stats::cor, use and method follow from that function. Stars indicate significance: ⁠*p<.05, **p<.01, ***p<.001⁠ For formatting, variables can be renamed, numbers can be rounded, upper or lower triangle only can be selected (or whole matrix), and empty columns/rows can be dropped if using triangles. For more compact columns, variable names can be numbered in the rows and column names will be corresponding numbers. Requires tidyverse and stats libraries.

Usage

partial_correltable(
  data,
  vars = NULL,
  var_names = vars,
  partialvars = NULL,
  partialvar_names = partialvars,
  method = c("pearson", "spearman"),
  use = c("pairwise", "complete"),
  round_n = 2,
  tri = c("upper", "lower", "all"),
  cutempty = c(FALSE, TRUE),
  colnum = c(FALSE, TRUE),
  html = c(FALSE, TRUE)
)

Arguments

data

The input dataset.

vars

A list of the names of 2+ variables to correlate, e.g. c("Age","height","WASI"). All variables must be numeric.

var_names

An optional list to rename the vars colnames in the output table, e.g. c("Age (years)","Height (inches)","IQ"). Must match vars in length. If not supplied, vars will be printed as is.

partialvars

A list of the names of 1+ variables to partial out, e.g. c("iq","Sex","Income"). Can include numeric, binary, factor variables.

partialvar_names

An optional list to rename the partialvars colnames in the output table, e.g. c("IQ (WASI)","Sex","Income"). Must match partialvar_names in length. If not supplied, partialvar_names will be printed as is.

method

Type of correlation to calculate c("pearson", "spearman"), based on stats::cor, default = "pearson".

use

Use pairwise.complete.obs or restrict to complete cases c("pairwise", "complete"), based on stats::cor, default = "pairwise".

round_n

The number of decimal places to round all output to (default=2).

tri

Select output formatting c("upper", "lower","all"); KEEP the upper triangle, lower triangle, or all values, default ="upper.

cutempty

If keeping only upper/lower triangle with tri, cut empty row/column, default=FALSE.

colnum

For more concise column names, number row names and just use corresponding numbers as column names, default=FALSE, if TRUE overrides cutempty.

html

Format as html in viewer or not (default=F, print in console), needs library(htmlTable) installed.

Value

Output Table 1

Examples

partial_correltable(
  data = psydat, vars = c("Age", "Height", "iq"),
  partialvars = c("Sex", "Income"),
  tri = "lower", html = TRUE
)

partial_correltable(
  data = psydat, vars = c("Age", "Height", "iq"),
  var_names = c("Age (months)", "Height (inches)", "IQ"),
  partialvars = c("Sex", "Income"),
  tri = "upper", colnum = TRUE, html = TRUE
)

partial_correltable(
  data = psydat, vars = c("Age", "Height", "iq"),
  var_names = c("Age (months)", "Height (inches)", "IQ"),
  partialvars = c("anxT"),
  partialvar_names = "Anxiety",
  tri = "all", html = TRUE
)

[Package scipub version 1.2.3 Index]