Menentukan Nilai Kritis t dengan R

qt(0.975, df = 18) #pengujian hipotesis 2 arah, sehingga 0.975, bukan 0.95
## [1] 2.100922

Menentukan Nilai Kritis F dengan R

qf(0.95, df=1, df2=18)
## [1] 4.413873

Contoh Kasus Uji Kesamaan Rata-Rata dari Dua Populasi yang Tidak Berhubungan (Independen) dengan Asumsi Varians yang Sama (Contoh Perhitungan)

data = read.csv("data_independen_1.csv")
data
##     X  Y
## 1  65 85
## 2  68 75
## 3  70 75
## 4  80 80
## 5  75 75
## 6  72 75
## 7  65 75
## 8  60 80
## 9  88 90
## 10 70 85
t.test(data$Y, data$X, var.equal = TRUE, paired = FALSE)
## 
##  Two Sample t-test
## 
## data:  data$Y and data$X
## t = 2.6487, df = 18, p-value = 0.01633
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   1.695807 14.704193
## sample estimates:
## mean of x mean of y 
##      79.5      71.3
t.test(data$Y, data$X, var.equal = FALSE, paired = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  data$Y and data$X
## t = 2.6487, df = 15.851, p-value = 0.01762
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   1.632025 14.767975
## sample estimates:
## mean of x mean of y 
##      79.5      71.3

Uji Asumsi Normalitas dalam R

data = read.csv("data_independen_1.csv")

X = data$X
Y = data$Y

library(nortest)
lillie.test(X) #dengan koreksi (lihat p-value)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  X
## D = 0.16556, p-value = 0.6103
suppressWarnings(ks.test(X, "pnorm", mean(X), sd(X))) #tanpa koreksi (lihat p-value)
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  X
## D = 0.16556, p-value = 0.9469
## alternative hypothesis: two-sided
suppressWarnings(ks.test(Y, "pnorm", mean(Y), sd(Y)))
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  Y
## D = 0.29327, p-value = 0.356
## alternative hypothesis: two-sided
library(tseries)
jarque.bera.test(X)
## 
##  Jarque Bera Test
## 
## data:  X
## X-squared = 0.92911, df = 2, p-value = 0.6284
jarque.bera.test(Y)
## 
##  Jarque Bera Test
## 
## data:  Y
## X-squared = 1.1767, df = 2, p-value = 0.5552

Uji Asumsi Kesamaan Varians dalam R

varians = read.csv("varians3.csv")
varians
##    Nilai Jenis
## 1     65     1
## 2     68     1
## 3     70     1
## 4     80     1
## 5     75     1
## 6     72     1
## 7     65     1
## 8     60     1
## 9     88     1
## 10    70     1
## 11    85     2
## 12    75     2
## 13    75     2
## 14    80     2
## 15    75     2
## 16    75     2
## 17    75     2
## 18    80     2
## 19    90     2
## 20    85     2
library(car)
## Loading required package: carData
leveneTest(varians$Nilai, varians$Jenis)
## Warning in leveneTest.default(varians$Nilai, varians$Jenis): varians$Jenis
## coerced to factor.
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  1  0.3305 0.5725
##       18
# library(Rcmdr)
# leveneTest(varians$Nilai, varians$Jenis)

library(lawstat)
## 
## Attaching package: 'lawstat'
## The following object is masked from 'package:car':
## 
##     levene.test
## The following object is masked from 'package:tseries':
## 
##     runs.test
levene.test(varians[, "Nilai"], varians[, "Jenis"], location = "median") #Sesuai Minitab
## 
##  Modified robust Brown-Forsythe Levene-type test based on the absolute
##  deviations from the median
## 
## data:  varians[, "Nilai"]
## Test Statistic = 0.33053, p-value = 0.5725
levene.test(varians[, "Nilai"], varians[, "Jenis"], location = "mean") #Sesuai SPSS
## 
##  Classical Levene's test based on the absolute deviations from the mean
##  ( none not applied because the location is not set to median )
## 
## data:  varians[, "Nilai"]
## Test Statistic = 0.62924, p-value = 0.438