Uji z digunakan untuk data yang diketahui ragam populasinya, data berdistribusi normal, atau untuk jumlah sampel (n) besar yaitu >30.
Terlebih dahulu install package BSDA dengan cara install.packages(“BSDA”)
## Loading required package: lattice
##
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
##
## Orange
Fungsi zsum.test bisa digunakan langsung dengan memasukkan info-info statistik dari sampel, seperti nilai tengah (mean), standar deviasi (sigma.x) dan jumlah data (n).
Secara umum, dengan nilai alpha 0,05 dan hipotesis dua arah (H0 : mu=0 vs H1 : mu=/=0), maka syntax yang diperoleh adalah sebagai berikut :
zsum.test(mean.x=1200000, sigma.x = 600000, n.x = 16,
alternative = "greater", mu = 0,
conf.level = 0.95)
##
## One-sample z-Test
##
## data: Summarized x
## z = 8, p-value = 6.661e-16
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
## 953272 NA
## sample estimates:
## mean of x
## 1200000
Apabila hipotesis yang diuji adalah satu arah, (H0 : mu<=0 vs H1 : mu>0), maka syntax yang diperoleh adalah sebagai berikut :
zsum.test(mean.x=1200000, sigma.x = 600000, n.x = 16,
alternative = "greater", mu = 0,
conf.level = 0.95)
##
## One-sample z-Test
##
## data: Summarized x
## z = 8, p-value = 6.661e-16
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
## 953272 NA
## sample estimates:
## mean of x
## 1200000
Apabila hipotesis yang diuji adalah satu arah, (H0 : mu>=0 vs H1 : mu<0), maka syntax yang diperoleh adalah sebagai berikut :
zsum.test(mean.x=1200000, sigma.x = 600000, n.x = 16,
alternative = "less", mu = 0,
conf.level = 0.95)
##
## One-sample z-Test
##
## data: Summarized x
## z = 8, p-value = 1
## alternative hypothesis: true mean is less than 0
## 95 percent confidence interval:
## NA 1446728
## sample estimates:
## mean of x
## 1200000
Uji t digunakan untuk data yang tidak diketahui ragam populasinya, data tidak berdistribusi normal, atau untuk jumlah sampel (n) kecil yaitu <30.
Apabila tidak diketahui ragam populasi, namun data >30, maka berdasarkan Teorema Limit Pusat (CLT) maka data dikatakan mendekati distribusi normal.
Secara umum jika jumlah sampel besar, maka penggunaan Uji t adalah sama dengan uji z.
tsum.test(mean.x=25, s.x = 6.4, n.x = 20,
alternative = "two.sided", mu = 0,
var.equal = TRUE, conf.level = 0.95)
##
## One-sample t-Test
##
## data: Summarized x
## t = 17.469, df = 19, p-value = 3.668e-13
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 22.00471 27.99529
## sample estimates:
## mean of x
## 25
Atau dengan cara lain, yaitu dengan langsung melakukan input data berupa vektor seperti di bawah :
IR64=c(4.5,4.8,4,3.6,3.8,5,4,3.9,4.8)
MSP=c(6.4,6.5,4.2,4,5.8,5.9,6.2,3.8,2.5,3.6,7,8)
t.test(MSP,alternative ="two.sided")
##
## One Sample t-test
##
## data: MSP
## t = 11.147, df = 11, p-value = 2.473e-07
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 4.273581 6.376419
## sample estimates:
## mean of x
## 5.325
##
## One Sample t-test
##
## data: IR64
## t = 24.983, df = 8, p-value = 3.525e-09
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
## 3.949088 Inf
## sample estimates:
## mean of x
## 4.266667
##
## One Sample t-test
##
## data: IR64
## t = 24.983, df = 8, p-value = 1
## alternative hypothesis: true mean is less than 0
## 95 percent confidence interval:
## -Inf 4.584245
## sample estimates:
## mean of x
## 4.266667
Perhatikan bahwa data yang diinput harus dalam bentuk vektor atau data frame.
Uji t independen berlaku bagi dua populasi yang saling bebas.
Contoh : akan dilakukan uji 2 populasi untuk mengetahui apakah terdapat perbedaan antara beras tipe IR64 dan tipe MSP
Karena kedua beras tersebut tidak saling berpasangan, maka dapat dilakukan dengan uji t independen
t.test(x=IR64, y=MSP,
alternative = "two.sided",
paired = FALSE, var.equal = TRUE,
conf.level = 0.95)
##
## Two Sample t-test
##
## data: IR64 and MSP
## t = -1.843, df = 19, p-value = 0.08099
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.2602512 0.1435846
## sample estimates:
## mean of x mean of y
## 4.266667 5.325000
tsum.test(mean.x=254, s.x = 3, n.x = 18,
mean.y =225 , s.y = 2,
n.y = 27, alternative = "greater",
mu = 0, var.equal = TRUE,
conf.level = 0.90)
##
## Standard Two-Sample t-Test
##
## data: Summarized x and y
## t = 38.983, df = 43, p-value < 2.2e-16
## alternative hypothesis: true difference in means is greater than 0
## 90 percent confidence interval:
## 28.03176 NA
## sample estimates:
## mean of x mean of y
## 254 225
Uji t dependen berlaku bagi dua populasi yang saling memengaruhi.
Contoh : akan dilakukan uji 2 populasi untuk mengetahui apakah terdapat perbedaan Berat badan sesudah dilakukan perlakuan dan sebelum dilakukan perlakuan.
Karena kedua populasi Berat Badan tersebut tidak saling berpasangan, maka dapat dilakukan dengan uji t dependen
Orang.ke=c(seq(1:10))
BB.Sebelum=c(57,69,56,67,55,56,62,67,67,56)
BB.Sesudah=c(55,70,56,65,54,55,64,65,67,54)
data=data.frame(Orang.ke,BB.Sebelum,BB.Sesudah)
t.test(x=data$BB.Sebelum, y=data$BB.Sesudah,
alternative = "greater",
mu = 0.5, paired = TRUE, var.equal = TRUE,
conf.level = 0.95)
##
## Paired t-test
##
## data: data$BB.Sebelum and data$BB.Sesudah
## t = 0.44598, df = 9, p-value = 0.3331
## alternative hypothesis: true difference in means is greater than 0.5
## 95 percent confidence interval:
## -0.1220671 Inf
## sample estimates:
## mean of the differences
## 0.7