corx (version 1.0.6.1)

corx: corx

Description

Creates an object of class 'corx'. This function calculates correlation matrices. It stores effect sizes, p-values, the number of pairwise observations, and a formatted correlation matrix in a list. The argument 'z' allows for control variables to be assigned. If z does not equal NULL, partial correlations are performed. Methods are exported for the generic functions 'print', 'plot', 'summary', 'data.frame' and, 'coef'.

Usage

corx(
  data,
  x = NULL,
  y = NULL,
  z = NULL,
  method = c("pearson", "spearman", "kendall"),
  stars = c(0.05),
  round = 2,
  remove_lead = TRUE,
  triangle = NULL,
  caption = NULL,
  note = NULL,
  describe = FALSE,
  grey_nonsig = TRUE,
  call_only = FALSE
)

Value

A list of class 'corx' which includes:

  • "call" The call

  • "apa" An 'APA' formatted correlation matrix with significance stars

  • "r" Raw correlation coefficients

  • "p" Raw p-values

  • "n" Pairwise observations

  • "caption" Object caption

  • "note" Object note

Arguments

data

A data.frame or matrix

x

a vector of rownames. Defaults to all

y

a vector of colnames. If not supplied, y is set to x.

z

a vector of colnames. Control variables to be used in partial correlations - defaults to NULL

method

a string. One of "pearson", "spearman", or "kendall"

stars

a numeric vector. This argument defines cut-offs for p-value stars.

round

a scalar. Number of digits in printing

remove_lead

a logical. if TRUE (the default), leading zeros are removed in summaries

triangle

one of "lower", "upper" or NULL (the default)

caption

table caption. Passed to plots

note

table note

describe

a list of functions. If functions are supplied to describe, new columns will be bound to the 'APA matrix' for each function in the list. Describe also accepts a variety of shortcuts. If describe is set to TRUE, mean and standard deviation are returned for all row variables. Describe can accept a character vector to call the following descriptive functions: c('mean','sd','var','median','iqr','skewness','kurtosis'). These shortcuts are powered by 'tidyselect'. Skewness and kurtosis are calculated using the 'moments' package. All functions retrieved with shortcuts remove missing values.

grey_nonsig

a logical. Should non-significant values be grey in output? This argument does nothing if describe is not set to FALSE

call_only

For debugging, if TRUE only the call is returned

Details

'corx' constructs intercorrelation matrices using 'psych::corr.test'. P-values attained are not adjusted for multiple comparisons. The argument z can be used to specify control variables. If control variables are specified, partial correlations are calculated using 'ppcor::ppcor.test'. Asymmetrical correlation matrices can be constructed using the arguments 'x' and 'y'. The arguments 'x', 'y', and 'z' are powered by 'tidyselect::vars_select'.

Examples

Run this code
cor_mat <- corx(mtcars, x = c(mpg,cyl,disp), y = c(wt,drat,disp,qsec),
           z = wt, round = 2, stars = c(0.05),
           caption = "Controlling for weight" ,
           describe = list("mean" = function(x) mean(x,na.rm=TRUE)))
cor_mat
coef(cor_mat)
cor_mat$p
plot(cor_mat)
cor_2 <- corx(iris[,-5], describe = c(median, IQR = iqr, kurt = kurtosis),
         note = "Using shortcuts to select describe functions", triangle = "lower")
cor_2

Run the code above in your browser using DataCamp Workspace