Skip to contents

Creates a properly formatted APA 7 style correlation table with superscript asterisks and proper lower triangle orientation when descriptives are shifted, exported to Excel

Usage

apa_cor_table(
  data,
  filename = NA,
  show.conf.interval = TRUE,
  show.sig.stars = TRUE,
  show.pvalue = TRUE,
  landscape = TRUE,
  shift.descriptives = FALSE,
  cor.methods = NULL
)

Arguments

data

Data frame containing variables for correlation

filename

Output filename (should end in .xlsx)

show.conf.interval

Whether to display confidence intervals

show.sig.stars

Whether to display significance stars

show.pvalue

Whether to display p-values

landscape

Whether to create landscape-oriented output

shift.descriptives

Whether to display descriptives as rows at bottom

cor.methods

Named vector specifying correlation methods for variables

Value

An object with the correlation table data

Examples

# Basic usage with sample data
test_data <- data.frame(
  x = rnorm(30),
  y = rnorm(30),
  z = rnorm(30)
)
apa_cor_table(test_data)
#> 
#>  Descriptive Statistics and Correlations 
#> 
#>      Variable N  M    SD   1   2   3
#> [1,] 1. x     30 -.17 1.08          
#> [2,] 2. y     30 .14  1.09 .11      
#> [3,] 3. z     30 .12  1.01 .00 .14  
#> 
#>  Note. N = number of cases. M = mean. SD = standard deviation. 
#> * indicates p < .05. ** indicates p < .01. *** indicates p < .001. 
#> $table.title
#> [1] "Descriptive Statistics and Correlations"
#> 
#> $table.body
#>      Variable N    M      SD     1     2     3 
#> [1,] "1. x"   "30" "-.17" "1.08" ""    ""    ""
#> [2,] "2. y"   "30" ".14"  "1.09" ".11" ""    ""
#> [3,] "3. z"   "30" ".12"  "1.01" ".00" ".14" ""
#> 
#> $table.note
#> [1] "Note. N = number of cases. M = mean. SD = standard deviation."
#> 
#> $landscape
#> [1] TRUE
#> 
#> attr(,"class")
#> [1] "apa.cor.table"

# With shifted descriptives
apa_cor_table(test_data, shift.descriptives = TRUE)
#> 
#>  Descriptive Statistics and Correlations 
#> 
#>      Variable 1    2    3   
#> [1,] 1. x                   
#> [2,] 2. y     .11           
#> [3,] 3. z     .00  .14      
#> [4,] N        30   30   30  
#> [5,] M        -.17 .14  .12 
#> [6,] SD       1.08 1.09 1.01
#> 
#>  Note. N = number of cases. M = mean. SD = standard deviation. 
#> * indicates p < .05. ** indicates p < .01. *** indicates p < .001. 
#> $table.title
#> [1] "Descriptive Statistics and Correlations"
#> 
#> $table.body
#>      Variable 1      2      3     
#> [1,] "1. x"   ""     ""     ""    
#> [2,] "2. y"   ".11"  ""     ""    
#> [3,] "3. z"   ".00"  ".14"  ""    
#> [4,] "N"      "30"   "30"   "30"  
#> [5,] "M"      "-.17" ".14"  ".12" 
#> [6,] "SD"     "1.08" "1.09" "1.01"
#> 
#> $table.note
#> [1] "Note. N = number of cases. M = mean. SD = standard deviation."
#> 
#> $landscape
#> [1] TRUE
#> 
#> attr(,"class")
#> [1] "apa.cor.table"