KORELASI

TABEL KONTINGENSI

a <- c(250, 50, 300)
b <- c(200, 1000, 1200)
c <- c(450, 1050, 1500)

matrik <- cbind(a, b, c)
dimnames(matrik) <- list(Jenis_Bacaan = c("Fiction", "Non-Fiction", "Total"), Jenis_Kelamin = c("Male", "Female", "Total"))
matrik
##              Jenis_Kelamin
## Jenis_Bacaan  Male Female Total
##   Fiction      250    200   450
##   Non-Fiction   50   1000  1050
##   Total        300   1200  1500
Uji1_a=chisq.test(matrik,correct=TRUE)
Uji1_a
## 
##  Pearson's Chi-squared test
## 
## data:  matrik
## X-squared = 507.94, df = 4, p-value < 2.2e-16
Uji1_a$observed
##              Jenis_Kelamin
## Jenis_Bacaan  Male Female Total
##   Fiction      250    200   450
##   Non-Fiction   50   1000  1050
##   Total        300   1200  1500
Uji1_a$expectedV
## NULL

KORELASI PEARSON

x <- c(2,1,5,0)
y <- c(5,3,6,2)
data_pearson <- cbind(x, y)
dimnames(data_pearson) = list(c("1", "2", "3", "4"), c("x", "y"))

data_pearson
##   x y
## 1 2 5
## 2 1 3
## 3 5 6
## 4 0 2
Uji2=cor.test(x, y, alternative = "two.sided", method = "pearson", conf.level = 0.90)
Uji2
## 
##  Pearson's product-moment correlation
## 
## data:  x and y
## t = 3.5689, df = 2, p-value = 0.07033
## alternative hypothesis: true correlation is not equal to 0
## 90 percent confidence interval:
##  0.01109648 0.99728732
## sample estimates:
##       cor 
## 0.9296697

KORELASI RANK SPEARMAN

data_praktikum_3 <- data.frame(
  kedisiplinanX = c(75, 45, 44, 70, 75, 64, 80, 77, 92, 66),
  kinerjaY = c(80, 45, 34, 80, 70, 65, 79, 76, 89, 72)
)

data_praktikum_3
##    kedisiplinanX kinerjaY
## 1             75       80
## 2             45       45
## 3             44       34
## 4             70       80
## 5             75       70
## 6             64       65
## 7             80       79
## 8             77       76
## 9             92       89
## 10            66       72
x=data_praktikum_3$`kedisiplinanX`
y=data_praktikum_3$`kinerjaY`

Uji3=cor.test(x,y,alternative="two.sided", method = "spearman", exact = FALSE, conf.level = 0.95)
Uji3
## 
##  Spearman's rank correlation rho
## 
## data:  x and y
## S = 31.692, p-value = 0.004689
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.8079268

KORELASI TAU-KENDALL

data.praktikum.4 <- data.frame(
  pewawancara_1 = c(7, 1.5, 8, 10, 9, 6, 5, 3, 1.5, 4),
  pewawancara_2 = c(5, 2, 6, 8, 7, 9.5, 9.5, 3.5, 1, 3.5)
)

x = data.praktikum.4$pewawancara_1
y = data.praktikum.4$pewawancara_2

Uji4=cor.test(x,y,alternative = "two.sided", method = "kendall", exact = FALSE, conf.level = 0.95)
Uji4
## 
##  Kendall's rank correlation tau
## 
## data:  x and y
## z = 2.3535, p-value = 0.0186
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
##       tau 
## 0.5977406