library(knitr)

Another correlation function?!

Yes, the correlation function from the psycho package.

# devtools::install_github("neuropsychology/psycho.R")  # Install the newest version

library(psycho)
library(tidyverse)

cor <- psycho::affective %>% 
  correlation()

This function automatically select numeric variables and run a correlation analysis. It returns a psychobject.

A table

We can then extract a formatted table that can be saved and pasted into reports and manuscripts by using the summary function.

summary(cor)
# write.csv(summary(cor), "myformattedcortable.csv")
knitr::kable(summary(cor))

A Plot

It integrates a plot done with ggcorplot.

plot(cor)

A print

It also includes a pairwise correlation printing method.

print(cor)

Options

You can also cutomize the type (pearson, spearman or kendall), the p value correction method (holm (default), bonferroni, fdr, none...) and run partial, semi-partial or glasso correlations.

psycho::affective %>% 
  correlation(method = "pearson", adjust="bonferroni", type="partial") %>% 
  summary()
psycho::affective %>% 
  correlation(method = "pearson", adjust="bonferroni", type="partial") %>% 
  summary() %>% 
  knitr::kable()

Fun with p-hacking

In order to prevent people for running many uncorrected correlation tests (promoting p-hacking and result-fishing), we included the i_am_cheating parameter. If FALSE (default), the function will help you finding interesting results!

df_with_11_vars <- data.frame(replicate(11, rnorm(1000)))
cor <- correlation(df_with_11_vars, adjust="none") 
summary(cor)
knitr::kable(summary(cor)[,1:11])

As we can see, Schopenhauer's Optimism is strongly related to many variables!!!

Credits

This package was useful? You can cite psycho as follows:



neuropsychology/psycho.R documentation built on Jan. 25, 2021, 7:59 a.m.