Beautiful and Powerful Correlation Tables in R
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的更多相关文章
- Interactive pivot tables with R(转)
I love interactive pivot tables. That is the number one reason why I keep using spreadsheet software ...
- Data manipulation primitives in R and Python
Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...
- R2—《R in Nutshell》 读书笔记(连载)
R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshe ...
- 使用R进行相关性分析
基于R进行相关性分析 一.相关性矩阵计算: [1] 加载数据: >data = read.csv("231-6057_2016-04-05-ZX_WD_2.csv",head ...
- 基于R进行相关性分析--转载
https://www.cnblogs.com/fanling999/p/5857122.html 一.相关性矩阵计算: [1] 加载数据: >data = read.csv("231 ...
- CF 55D Beautiful numbers (数位DP)
题意: 如果一个正整数能被其所有位上的数字整除,则称其为Beautiful number,问区间[L,R]共有多少个Beautiful number?(1<=L<=R<=9*1018 ...
- HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)
beautiful number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- codeforces Beautiful Numbers
来源:http://codeforces.com/problemset/problem/1265/B B. Beautiful Numbers You are given a permutat ...
- 【原创】大数据基础之Marathon(1)简介、安装、使用
marathon 1.6.322 官方:https://mesosphere.github.io/marathon/ 一 简介 Marathon is a production-grade conta ...
随机推荐
- Java实现:数据结构之排序
Java实现:数据结构之排序 0.概述 形式化定义:假设有n个记录的序列(待排序列)为{ R1, R2 , -, Rn },其相应的关键字序列为 { K1, K2, -, Kn }.找到{1,2, - ...
- Vue.js 2.x中事件总线(EvevntBus)及element-ui中全屏loading的使用
事件总线(Event Bus)可以在vue项目的index.js文件中创建,也可以在一个独立的.vue文件中创建.使用时,在各个子组件中引入该组件即可. 项目中的全屏loading较多时,可以在根组件 ...
- SpringMVC整个执行流程
在SSM (或SSH) 框架整合使用后,基本骨架看上去还是MVC的结构. MyBatis整合一些数据封装方法节省了DAO层的代码量, Spring提供了AOP,IoC( DI 具体实现 ). 而Spr ...
- Java回顾之反射
在这一篇文章里,我们关注反射及其相关话题. 反射可以帮助我们查看指定类型中的信息.创建类型的实例,调用类型的方法.我们平时使用框架,例如Spring.EJB.Hibernate等都大量的使用了反射技术 ...
- css输入框的圆角
转载:http://jingyan.baidu.com/article/73c3ce28f0b38fe50343d926.html 1.原理是四张圆角的图片放在四个角上,就是圆角矩形的四个角,但这种方 ...
- python numpy 学习
例子 >>> import numpy as np >>> a = np.arange(15).reshape(3, 5) >>> a array ...
- 微信小程序纯css制作圆形进度条所遇到的问题
wrapBox:最外层盒子,背景色为进度条的颜色 leftBox/rightBox:半宽等长 左/右浮动的盒子,背景色为灰色 roundMask:居中的盒子 用来遮盖leftBox和rightBox ...
- 牛客网——A找一找
链接:https://www.nowcoder.net/acm/contest/71/A来源:牛客网 题目描述 给定n个正整数,请找出其中有多少个数x满足:在这n个数中存在数y=kx,其中k为大于1的 ...
- mysql插入中文数据报错 java.sql.SQLException: Incorrect string value: '\xE5\x90\x88\xE8\xAE\xA1' for column
1.我们创建数据库的时候没有更改数据库的字符集为utf8. 在mysql工具中,右击数据库,->"改变数据库",->选择“基字符集”为utf-8; 2,数据库中表的字符 ...
- 转载 ORACLE中实现表变量的方法
源文地址:http://blog.itpub.net/750077/viewspace-2134222/ 经常看到SQLSERVER 中用表变量类型的方式就能做到缓存一个比较大的中间结果, 然后再对这 ...