Add p-Values to Correlation Matrix Plot in R (2 Examples) | psych, corrplot & ggcorrplot Packages

Statistics Globe
Statistics Globe
2.6 هزار بار بازدید - 2 سال پیش - How to draw a correlation
How to draw a correlation plot with p-values in the R programming language. More details: https://statisticsglobe.com/add-p-val...
R code of this video:

set.seed(3673845)                    # Create example data
x1 <- rnorm(1000)
x2 <- rnorm(1000) + 0.3 * x1
x3 <- runif(1000) - 0.2 * x1 + 0.1 * x2
x4 <- rnorm(1000) + 0.03 * x1
data <- data.frame(x1, x2, x3, x4)
head(data)                           # Print head of example data

cor_mat <- cor(data)                 # Correlation matrix of example data
cor_mat                              # Print correlation matrix

install.packages("psych")            # Install psych package
library("psych")                     # Load psych package

cor_test_mat <- corr.test(data)$p    # Apply corr.test function
cor_test_mat                         # Print matrix of p-values

install.packages("corrplot")         # Install corrplot package
library("corrplot")                  # Load corrplot package

corrplot(cor_mat)                    # Draw corrplot

corrplot(cor_mat,                    # Draw corrplot with p-values
        p.mat = cor_test_mat,
        insig = "p-value")

install.packages("ggcorrplot")       # Install ggcorrplot package
library("ggcorrplot")                # Load ggcorrplot package

ggcorrplot(cor_mat)                  # Draw ggcorrplot

ggcorrplot(cor_mat,                  # Draw ggcorrplot with p-values
          p.mat = cor_test_mat)

Follow me on Social Media:
Facebook – Statistics Globe Page: Facebook: statisticsglobecom
Facebook – R Programming Group for Discussions & Questions: Facebook: statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: Facebook: statisticsglobepython
LinkedIn – Statistics Globe Page: LinkedIn: statisticsglobe
LinkedIn – R Programming Group for Discussions & Questions: LinkedIn: 12555223
LinkedIn – Python Programming Group for Discussions & Questions: LinkedIn: 12673534
Twitter: Twitter: JoachimSchork

Music by bensound.com
2 سال پیش در تاریخ 1401/06/14 منتشر شده است.
2,632 بـار بازدید شده
... بیشتر