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 apsychobject.

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")
  Age Life_Satisfaction Concealing Adjusting
Age        
Life_Satisfaction 0.03      
Concealing -0.05 -0.06    
Adjusting 0.03 0.36*** 0.22***  
Tolerating 0.03 0.15*** 0.07 0.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()
  Age Life_Satisfaction Concealing Adjusting
Age        
Life_Satisfaction 0.01      
Concealing -0.06 -0.16***    
Adjusting 0.02 0.36*** 0.25***  
Tolerating 0.02 0.06 0.02 0.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)
  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11
X1                      
X2 -0.04                    
X3 -0.04 -0.02                  
X4 0.02 0.05 -0.02                
X5 -0.01 -0.02 0.05 -0.03              
X6 -0.03 0.03 0.08* 0.02 0.02            
X7 0.03 -0.01 -0.02 -0.04 -0.03 -0.04          
X8 0.01 -0.07* 0.04 0.02 -0.01 -0.01 0.00        
X9 -0.02 0.03 -0.03 -0.02 0.00 -0.04 0.03 -0.02      
X10 -0.03 0.00 0.00 0.01 0.01 -0.01 0.01 -0.02 0.02    
X11 0.01 0.01 -0.03 -0.05 0.00 0.05 0.01 0.00 -0.01 0.07*  
Local_Air_Density 0.26*** -0.02 -0.44*** -0.15*** -0.25*** -0.50*** 0.57*** -0.11*** 0.47*** 0.06 0.01
Reincarnation_Cycle -0.03 -0.02 0.02 0.04 0.01 0.00 0.05 -0.04 -0.05 -0.01 0.03
Communism_Level 0.58*** -0.44*** 0.04 0.06 -0.10** -0.18*** 0.10** 0.46*** -0.50*** -0.21*** -0.14***
Alien_Mothership_Distance 0.00 -0.03 0.01 0.00 -0.01 -0.03 -0.04 0.01 0.01 -0.02 0.00
Schopenhauers_Optimism 0.11*** 0.31*** -0.25*** 0.64*** -0.29*** -0.15*** -0.35*** -0.09** 0.08* -0.22*** -0.47***
Hulks_Power 0.03 0.00 0.02 0.03 -0.02 -0.01 -0.05 -0.01 0.00 0.01 0.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

转自:https://neuropsychology.github.io/psycho.R//2018/05/20/correlation.html

Beautiful and Powerful Correlation Tables in R的更多相关文章

  1. Interactive pivot tables with R(转)

    I love interactive pivot tables. That is the number one reason why I keep using spreadsheet software ...

  2. Data manipulation primitives in R and Python

    Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...

  3. R2—《R in Nutshell》 读书笔记(连载)

    R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshe ...

  4. 使用R进行相关性分析

    基于R进行相关性分析 一.相关性矩阵计算: [1] 加载数据: >data = read.csv("231-6057_2016-04-05-ZX_WD_2.csv",head ...

  5. 基于R进行相关性分析--转载

    https://www.cnblogs.com/fanling999/p/5857122.html 一.相关性矩阵计算: [1] 加载数据: >data = read.csv("231 ...

  6. CF 55D Beautiful numbers (数位DP)

    题意: 如果一个正整数能被其所有位上的数字整除,则称其为Beautiful number,问区间[L,R]共有多少个Beautiful number?(1<=L<=R<=9*1018 ...

  7. HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

    beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. codeforces Beautiful Numbers

    来源:http://codeforces.com/problemset/problem/1265/B   B. Beautiful Numbers   You are given a permutat ...

  9. 【原创】大数据基础之Marathon(1)简介、安装、使用

    marathon 1.6.322 官方:https://mesosphere.github.io/marathon/ 一 简介 Marathon is a production-grade conta ...

随机推荐

  1. 20145315 《Java程序设计》第八周学习总结

    20145315 <Java程序设计>第八周学习总结 教材学习内容总结 第十五章通用API 15.1日志 15.1.1日志API简介 使用日志的起点是logger类,logger实例的创建 ...

  2. MyBatis的简单入门学习

    一个新知识开始是最难学的.(万事开头难) MyBatis大体分三层,接口层,数据处理层,基础支撑层. 其中接口层不是java中的那个interface,而是框架和程序员之间的对接.一个API,程序员可 ...

  3. Mac下配置Hive环境

    在配置Hive环境之前,需要Hadoop环境. 安装Hive 点击下载 下载结束后,会有一个.tar文件,使用以下命令解压该文件. tar -zxvf 要解压的tar包 解压完成后如下 修改Hive配 ...

  4. 深入Linux内核架构第一章笔记

    1. Linux是多任务系统, 支持并发执行若干进程,系统同时真正运行的进程数目不超过CPU的数量,因此内核会按照时间间隔在不同进程之间切换. 2.确定那个进程运行多长时间的过程称为调度. 3.内核启 ...

  5. Minimum Depth of Binary Tree,求树的最小深度

    算法分析:递归和非递归两种方法. public class MinimumDepthofBinaryTree { //递归,树的最小深度,就是它左右子树的最小深度的最小值+1 public int m ...

  6. hdu 1498 50 years, 50 colors 最小点覆盖

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. Qt5_vs2013_error_C2001: 常量中有换行符__资料

    ZC: Win7x64 + Qt551(x86) + vs2013(x86) ZC: 问题:UTF-8 在源码文件中有中文时,有时会报编译错误:C2001 & C2143 分析: --> ...

  8. redis缓存穿透、缓存击穿、缓存雪崩

    缓存穿透 缓存穿透是指查询一个一定不存在的数据,由于缓存是不命中时需要从数据库查询,查不到数据则不写入缓存,这将导致这个不存在的数据每次请求都要到数据库去查询,造成缓存穿透. 解决办法: 预校验 在控 ...

  9. Aho-Corasick算法

    2018-03-15 10:25:02 在计算机科学中,Aho–Corasick算法是由Alfred V. Aho和Margaret J.Corasick 发明的字符串搜索算法,用于在输入的一串字符串 ...

  10. 为什么要使用MQ消息中间件?它解决了什么问题?

    1.应用场景 1.1 异步处理 场景说明:用户注册后,需要发注册邮件和注册短信,传统的做法有两种1.串行的方式;2.并行的方式 (1)串行方式:将注册信息写入数据库后,发送注册邮件,再发送注册短信,以 ...