HARcorr: Generate a formatted, APA-ready correlation table with...

Description Usage Arguments Value

View source: R/correlations.r

Description

Below is code for producing formatted, paper-ready correlation tables with 'HARcorr' (i.e. hot-and-ready correlations; I like fun function names, sue me). I tried to write the code to minimize the amount of packages the function required, and to use packages that you probably already use frequently. The code produces bivariate correlation tables complete with many features that align the output with APA style and with standards and information you might want for publishing your research. The main features include: Bivariate correlations displayed on the lower half of the correlation matrix (omitted for the upper half), with 1's on the diagonal omitted. Stars to indicate significance level, with a dagger indicating marginal significance (p < .10) leading 0's removed from correlations; correlations rounded to 2 decimal places Numbered variable names vertically, along with corresponding numbers horizontally. Descriptive statistics for each variable (mean, standard deviation, n) displayed for each variable at the bottom of the matrix. Per APA, numbers greater than 1,000 have commas (1,000 vs. 1000), and means and standard deviations between -1, 1 that have a maximum/minimum of greater than 1/-1 have a leading 0 (e.g. 0.57). "Means" of binary variables are presented as percentages and SD for these variables are omitted. The options to include headers for groups of variables (e.g. including a header "Covariates" before rows of covariate variables) For me, the inclusion of APA formatting, numbered variables, and descriptives are a huge improvement over previous correlation table functions I've used, and save me a lot of time in formatting tables in papers.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
HARcorr(
  df,
  vars,
  describe = TRUE,
  numbers = TRUE,
  headers = NULL,
  spots = NULL,
  copy = FALSE,
  names = NULL,
  full.labels = FALSE
)

Arguments

df

data frame

vars

quosure of variables to analyze

describe

allows you to toggle on/off the descriptives (mean, standard deviation, and n) at the bottom of the table by specifying describe = TRUE/FALSE.

numbers

allows you to toggle on/off the numbers used to reference variables on the horizontal axis by specifying numbers = TRUE/FALSE. If numbers = FALSE, variable names are used as the horizontal axis reference.

headers

The options headers and spots are used together. They each take a vector as an argument. Headers specifies subheaders for groupings of variables; headers takes a character vector.

spots

spots specifies the row before which you would like to insert the headers. Spots takes a numeric vector.

copy

Copy allows you to toggle on/off the table formatting. If copy = FALSE, kable() formatting is applied to make the table formatted nicely for easy of use and presentation. If copy = TRUE, the formatting is removed and HARcorr() returns a data table, which makes the values more easily copied into other programs such as Excel or Word.

names

a character vector containing full names of variables. These replace variable names to increase clarity.

full.labels

Would you also like names on the top axis?

Value

a formatted correlation table


crbwin/clnR documentation built on Oct. 29, 2020, 1:55 a.m.