#korelasi pearson
# Masukkan data
data <- data.frame(
y = c(57.5, 52.8, 61.3, 67, 53.5, 62.7, 56.2, 68.5, 69.2),
x1 = c(78, 69, 77, 88, 67, 80, 74, 94, 102),
x2 = c(2.75, 2.15, 4.41, 5.52, 3.21, 4.32, 2.31, 4.30, 3.71),
x3 = c(29.5, 26.3, 32.2, 36.5, 27.2, 27.7, 28.3, 30.3, 28.7)
)
# Matriks korelasi
R <- cor(data)
heatmap(R, Rowv=NA, Colv=NA)

library(pheatmap)
pheatmap(R, display_numbers=TRUE)

pheatmap(R,
display_numbers=TRUE,
cluster_rows=FALSE,
cluster_cols=FALSE)

pheatmap(R)

y <- c(57.5, 52.8, 61.3, 67, 53.5, 62.7, 56.2, 68.5, 69.2)
x1 <- c(78, 69, 77, 88, 67, 80, 74, 94, 102)
x2 <- c(2.75, 2.15, 4.41, 5.52, 3.21, 4.32, 2.31, 4.30, 3.71)
x3 <- c(29.5, 26.3, 32.2, 36.5, 27.2, 27.7, 28.3, 30.3, 28.7)
data <- cbind(y, x1, x2, x3)
data
## y x1 x2 x3
## [1,] 57.5 78 2.75 29.5
## [2,] 52.8 69 2.15 26.3
## [3,] 61.3 77 4.41 32.2
## [4,] 67.0 88 5.52 36.5
## [5,] 53.5 67 3.21 27.2
## [6,] 62.7 80 4.32 27.7
## [7,] 56.2 74 2.31 28.3
## [8,] 68.5 94 4.30 30.3
## [9,] 69.2 102 3.71 28.7
R <- cor(data, method = "pearson")
R
## y x1 x2 x3
## y 1.0000000 0.9470919 0.7611425 0.5603295
## x1 0.9470919 1.0000000 0.5340188 0.3899864
## x2 0.7611425 0.5340188 1.0000000 0.7844691
## x3 0.5603295 0.3899864 0.7844691 1.0000000
heatmap(R)

install.packages("pheatmap")
## Warning: package 'pheatmap' is in use and will not be installed
library(pheatmap)
pheatmap(R,
display_numbers = TRUE,
cluster_rows = FALSE,
cluster_cols = FALSE)
