Quantcast
Channel: R-bloggers
Viewing all articles
Browse latest Browse all 12094

Beautiful and Powerful Correlation Tables in R

$
0
0

(This article was first published on Dominique Makowski, and kindly contributed to R-bloggers)

Another correlation function?!

Yes, the correlation function from the psycho package.

devtools::install_github("neuropsychology/psycho.R")# Install the newest versionlibrary(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")
 AgeLife_SatisfactionConcealingAdjusting
Age    
Life_Satisfaction0.03   
Concealing-0.05-0.06  
Adjusting0.030.36***0.22*** 
Tolerating0.030.15***0.070.29***

A Plot

It integrates a plot done with ggcorplot.

plot(cor)

A print

It also includes a pairwise correlation printing method.

print(cor)
Pearson Full correlation (p value correction: holm):   - Age / Life_Satisfaction:   Results of the Pearson correlation showed a non significant and weak negative association between Age and Life_Satisfaction (r(1249) = 0.030, p > .1).   - Age / Concealing:   Results of the Pearson correlation showed a non significant and weak positive association between Age and Concealing (r(1249) = -0.050, p > .1).   - Life_Satisfaction / Concealing:   Results of the Pearson correlation showed a non significant and weak positive association between Life_Satisfaction and Concealing (r(1249) = -0.063, p > .1).   - Age / Adjusting:   Results of the Pearson correlation showed a non significant and weak negative association between Age and Adjusting (r(1249) = 0.027, p > .1).   - Life_Satisfaction / Adjusting:   Results of the Pearson correlation showed a significant and moderate negative association between Life_Satisfaction and Adjusting (r(1249) = 0.36, p < .001***).   - Concealing / Adjusting:   Results of the Pearson correlation showed a significant and weak negative association between Concealing and Adjusting (r(1249) = 0.22, p < .001***).   - Age / Tolerating:   Results of the Pearson correlation showed a non significant and weak negative association between Age and Tolerating (r(1249) = 0.031, p > .1).   - Life_Satisfaction / Tolerating:   Results of the Pearson correlation showed a significant and weak negative association between Life_Satisfaction and Tolerating (r(1249) = 0.15, p < .001***).   - Concealing / Tolerating:   Results of the Pearson correlation showed a non significant and weak negative association between Concealing and Tolerating (r(1249) = 0.074, p = 0.05°).   - Adjusting / Tolerating:   Results of the Pearson correlation showed a significant and weak negative association between Adjusting and Tolerating (r(1249) = 0.29, p < .001***).

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()
 AgeLife_SatisfactionConcealingAdjusting
Age    
Life_Satisfaction0.01   
Concealing-0.06-0.16***  
Adjusting0.020.36***0.25*** 
Tolerating0.020.060.020.24***

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")
## Warning in correlation(df_with_11_vars, adjust = "none"): We've detected that you are running a lot (> 10) of correlation tests without adjusting the p values. To help you in your p-fishing, we've added some interesting variables: You never know, you might find something significant!## To deactivate this, change the 'i_am_cheating' argument to TRUE.
summary(cor)
 X1X2X3X4X5X6X7X8X9X10X11
X1           
X2-0.04          
X3-0.04-0.02         
X40.020.05-0.02        
X5-0.01-0.020.05-0.03       
X6-0.030.030.08*0.020.02      
X70.03-0.01-0.02-0.04-0.03-0.04     
X80.01-0.07*0.040.02-0.01-0.010.00    
X9-0.020.03-0.03-0.020.00-0.040.03-0.02   
X10-0.030.000.000.010.01-0.010.01-0.020.02  
X110.010.01-0.03-0.050.000.050.010.00-0.010.07* 
Local_Air_Density0.26***-0.02-0.44***-0.15***-0.25***-0.50***0.57***-0.11***0.47***0.060.01
Reincarnation_Cycle-0.03-0.020.020.040.010.000.05-0.04-0.05-0.010.03
Communism_Level0.58***-0.44***0.040.06-0.10**-0.18***0.10**0.46***-0.50***-0.21***-0.14***
Alien_Mothership_Distance0.00-0.030.010.00-0.01-0.03-0.040.010.01-0.020.00
Schopenhauers_Optimism0.11***0.31***-0.25***0.64***-0.29***-0.15***-0.35***-0.09**0.08*-0.22***-0.47***
Hulks_Power0.030.000.020.03-0.02-0.01-0.05-0.010.000.010.03

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

Credits

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

  • Makowski, (2018). The psycho Package: an Efficient and Publishing-Oriented Workflow for Psychological Science. Journal of Open Source Software, 3(22), 470. https://doi.org/10.21105/joss.00470
var vglnk = { key: '949efb41171ac6ec1bf7f206d57e90b8' }; (function(d, t) {var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;s.src = '//cdn.viglink.com/api/vglnk.js';var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Dominique Makowski.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...


Viewing all articles
Browse latest Browse all 12094

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>