Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the correlation analysis of editors in R language?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you what the correlation analysis of the editor in R language is like, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The cor function in R language can only calculate the correlation coefficient. If you want to calculate the significance, you need to use two cor.test. If it is multi-column data, the operation is more troublesome. Here, two packages are introduced, which are very convenient to test the correlation coefficient and significance of multi-column data, and give visualization.

1. Simulated data

Here, 10 columns of data are simulated and transformed into a database, which is 100 rows and 10 columns of data. The purpose is to calculate the correlation coefficient and significance of these 10 columns. Although random numbers are not significant, as a demonstration, it is still very illustrative.

> set.seed (123)

> dd = as.data.frame (matrix (rnorm (1000), 100jing10))

> head (dd)

V1 V2 V3 V4 V5 V6 V7 V8 V9 V10

1-0.56047565-0.71040656 2.1988103-0.7152422-0.07355602-0.60189285 1.07401226-0.7282191 0.3562833-1.0141142

2-0.23017749 0.25688371 1.3124130-0.7526890-1.16865142-0.99369859-0.02734697-1.5404424-0.6580102-0.7913139

3 1.55870831-0.24669188-0.2651451-0.9385387-0.63474826 1.02678506-0.03333034-0.6930946 0.8552022 0.2995937

4 0.07050839-0.34754260 0.5431941-1.0525133-0.02884155 0.75106130-1.51606762 0.1188494 1.1529362 1.6390519

5 0.12928774-0.95161857-0.4143399-0.4371595 0.67069597-1.50916654 0.79038534-1.3647095 0.2762746 1.0846170

6 1.71506499-0.04502772-0.4762469 0.3311792-1.65054654-0.09514745-0.21073418 0.5899827 0.1441047-0.6245675

two。 Calculate the correlation coefficient and significance

First of all, you need to load the Hmisc package, because we are going to use the rcorr function in this package. If you don't have this package, just run the command install.packages ("Hmisc") to install it.

Beside the point, this blue code highlights, it is really too beautiful, I then think that Arena of Valor's skin so many people buy is really a lot of people care about appearance, and then speculate that the persistence of my diamond five-star Rank and I do not have krypton gold has a strong relationship, because the joy of charging can only be realized by the joy of N-winning streak. By the way, when you knelt down, unload the game and wash it to sleep. Today, I complained to WeCom of Tencent. It was a screenshot complaint, and then the leader told me, "do you know why Tencent sealed your official account for a month?" no, no, no.

❞> # calculation correlation coefficient and significance

> library (Hmisc) # load package

> res2 res2

V1 V2 V3 V4 V5 V6 V7 V8 V9 V10

V1 1.00-0.05-0.13-0.04-0.19-0.06-0.03 0.18-0.02 0.01

V2-0.05 1.00 0.03 0.04-0.13 0.11 0.08-0.03-0.05-0.09

V3-0.13 0.03 1.00-0.04-0.02 0.02 0.01-0.12-0.05-0.01

V4-0.04 0.04-0.04 1.00-0.02-0.09-0.06 0.17-0.17 0.25

V5-0.19-0.13-0.02-0.02 1.00 0.21-0.01-0.14-0.04-0.02

V6-0.06 0.11 0.02-0.09 0.21 1.00-0.06 0.09 0.07-0.03

V7-0.03 0.08 0.01-0.06-0.01-0.06 1.00 0.00-0.13-0.02

V8 0.18-0.03-0.12 0.17-0.14 0.09 0.00 1.00 0.02

V9-0.02-0.05-0.05-0.17-0.04 0.07-0.13 0.00 1.00-0.02

V10 0.01-0.09-0.01 0.25-0.02-0.03-0.02-0.02-0.02 1.00

N = 100

P

V1 V2 V3 V4 V5 V6 V7 V8 V9 V10

V1 0.6246 0.2002 0.6632 0.0547 0.5767 0.7343 0.0706 0.8234 0.9135

V2 0.6246 0.7626 0.6650 0.1952 0.2567 0.4398 0.7435 0.6543 0.3653

V3 0.2002 0.7626 0.6576 0.8061 0.8573 0.9317 0.2544 0.5985 0.8866

V4 0.6632 0.6650 0.6576 0.8492 0.3737 0.5284 0.0950 0.1008 0.0139

V5 0.0547 0.1952 0.8061 0.8492 0.0392 0.9488 0.1628 0.6958 0.8741

V6 0.5767 0.2567 0.8573 0.3737 0.0392 0.5225 0.3515 0.4622 0.8046

V7 0.7343 0.4398 0.9317 0.5284 0.9488 0.5225 0.9979 0.2012 0.8398

V8 0.0706 0.7435 0.2544 0.0950 0.1628 0.3515 0.9979 0.9936 0.8107

V9 0.8234 0.6543 0.5985 0.1008 0.6958 0.4622 0.2012 0.9936 0.8225

V10 0.9135 0.3653 0.8866 0.0139 0.8741 0.8046 0.8398 0.8107 0.8225

3. Significant visualization

There is a correlation coefficient above, there is a corresponding significance, but R language finished statistics if there is no visualization, just like eating without soup, the total feeling of missing something, then you can visualize it!

> library (PerformanceAnalytics) # load package

> chart.Correlation (dd, histogram=TRUE, pch=19)

4. Complete Code set.seed (123)

Dd = as.data.frame (matrix (rnorm (1000), 100jing10))

Head (dd)

# calculate the correlation coefficient and significance

Library (Hmisc) # load package

Res2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report