tau <- rep(c(1:4),each = 4)
jenis.mak <- factor(tau, levels = c(seq(1,4)), labels = c("M1","M2","M3","M4"))

y <- c(9, 11, 15, 10,
       5, 8, 4, 5,
       13, 19, 17,20,
       7, 8, 10, 9)

dataeksp <- data.frame(jenis.mak, berat = y)
anv <- aov(berat ~ jenis.mak, data = dataeksp)
output <- anova(anv)
output
plot(jenis.mak, y, xlab = "Jenis makanan", ylab ="Pertambahan berat")

Nilai yang diperlukan untuk uji lanjut

RJKE <- output$`Mean Sq`[2]
dkE <- output$Df[2]
k <- length(levels(jenis.mak)) # banyaknya taraf perlakuan
n <- 4 # banyaknya replikasi

Uji Lanjut SNK

library(agricolae)
SNK <- SNK.test(anv, "jenis.mak", alpha = 0.05, group = TRUE)
print(SNK)

Uji Lanjut Tukey (HSD)

tukey <- HSD.test(anv, "jenis.mak", alpha = 0.05, group = FALSE)
print(tukey)

Uji Lanjut Kontras

Susun kontras

c1 <- c(1, 0,  0, -1)
c2 <- c(1, 1, -1, -1)
c3 <- c(-1, -1, 0, 2)
contrastmat <- cbind(c1,c2,c3)

rataan <- aggregate(dataeksp$berat, by = list(dataeksp$jenis.mak), FUN = "mean")
C <- rataan$x %*% contrastmat

sigmac2 <- (1/n)*colSums(contrastmat^2)
F_hitung <- (C^2/sigmac2)/RJKE
Ftabel <- qf(1 - 0.05, 1, dkE)
round(F_hitung, 4)
round(Ftabel, 4)

Uji Lanjut Scheffe

# Susun kontras
c11 <- c(1, -1, 1, -1)
c22 <- c(0, 1, 0, -1)
matriks.c <- cbind(c11,c22)
colnames(matriks.c) <- c("c1","c2")

Cs <- rataan$x %*%matriks.c
SC <- sqrt(RJKE *(1/n)*colSums(matriks.c^2))
SCalpha <- SC * sqrt((k-1)*qf((1-0.05), (k - 1), (k*n) - k))

kesimpulan <- rep(0,2)
for (i in 1:2){
  kesimpulan[i] <- if(abs(as.vector(Cs)[i]) > as.vector(SCalpha)[i]) {print('H0 ditolak')} else {print('H0 diterima')}
}

results <- data.frame(abs(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