Memuat
Memuat
ANOVA, ANCOVA and Tukey Post Hoc Test for Education and Learning
0 views
Comparing mean physics test score across teaching method groups with ANOVA, ANCOVA adjusted for pretest score, and Tukey tests using synthetic data for demonstration. One-way ANOVA compares the mean of a numeric outcome across three or more groups, while ANCOVA makes the same comparison after adjusting for a covariate such as a pretest score. It suits experimental or quasi-experimental theses comparing treatments, methods or varieties, with the Tukey post hoc test showing which pairs differ.

Comparing mean physics test score across teaching method groups with ANOVA, ANCOVA adjusted for pretest score, and Tukey tests using synthetic data for demonstration.
| Role | Variable | Unit |
|---|---|---|
| Main | Physics test score | score |
| Supporting 1 | Teaching method | group |
| Supporting 2 | Pretest score | score |
ANOVA shows that Physics test score differs significantly across levels of Teaching method (F = 19.86, p < 0.001, eta2 = 0.168); Tukey finds 2 of 3 pairs different. Adjusting for Pretest score (ANCOVA), the group effect remains significant (p < 0.001, partial eta2 = 0.231), highest in Lecture; Levene p = 0.084.
Computed from illustrative synthetic data, not from a real study.
One-way ANOVA compares the mean of a numeric outcome across three or more groups, while ANCOVA makes the same comparison after adjusting for a covariate such as a pretest score. It suits experimental or quasi-experimental theses comparing treatments, methods or varieties, with the Tukey post hoc test showing which pairs differ.
Report the ANOVA F, degrees of freedom, p-value and eta squared, then the pairs that differ according to Tukey with their differences and confidence intervals. For ANCOVA report the group effect after adjusting for the covariate, partial eta squared, the adjusted group means and the slope homogeneity test.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
# Contoh kode R: ANOVA, ANCOVA and Tukey Post Hoc Test
suppressPackageStartupMessages({
library(ggplot2)
library(patchwork)
library(car)
library(emmeans)
library(scales)
})
set.seed(42)
# ---- Gaya grafik ----
pal <- c("#1f6feb", "#e8590c", "#2f9e44", "#ae3ec9", "#f59f00")
warna <- list(bg = "#f4f6fa", panel = "#ffffff", teks = "#1f2933", redup = "#5f6b78", grid = "#e3e8ee", bar = "#1d3557")
tata <- 1
theme_set(theme_minimal(base_size = 11) + theme(legend.position = "bottom"))
# ---- Data sintetis: tiga kelompok perlakuan dengan satu kovariat ----
n <- 200
lv <- c("A", "B", "C")
d <- data.frame(teaching_method = factor(sample(rep(lv, length.out = n)), levels = lv),
pretest_score = round(rnorm(n, 30, 6), 2))
z2 <- as.numeric(scale(d$pretest_score))
efek <- c(0, runif(1, 0.25, 0.6), runif(1, 0.55, 1.1))[sample(3)] # beda rata-rata antarkelompok (dalam SD)
b_kov <- runif(1, 0.35, 0.7) # pengaruh kovariat
d$physics_test_score <- round(100 + 15 * (efek[as.integer(d$teaching_method)] - mean(efek) + b_kov * z2 +
rnorm(n, 0, runif(1, 0.55, 0.8))), 2)
write.csv(d, "data_contoh.csv", row.names = FALSE)
# ---- Analisis 1: ANOVA satu arah ----
fit_aov <- aov(physics_test_score ~ teaching_method, data = d)
tab_aov <- summary(fit_aov)[[1]]
print(tab_aov)
print(aggregate(physics_test_score ~ teaching_method, data = d, FUN = function(v) c(rerata = mean(v), sd = sd(v), n = length(v))))
# ---- Uji asumsi ANOVA ----
lev <- car::leveneTest(physics_test_score ~ teaching_method, data = d, center = median) # homogenitas varians (Levene/Brown-Forsythe)
sw <- shapiro.test(residuals(fit_aov)) # normalitas residual
print(lev); print(sw)
eta2 <- tab_aov[1, "Sum Sq"] / sum(tab_aov[, "Sum Sq"]) # eta kuadrat (= partial eta2 pada ANOVA satu arah)
# ---- Uji lanjut Tukey HSD ----
tk <- TukeyHSD(fit_aov, conf.level = 0.95)
print(tk)
tkd <- as.data.frame(tk[[1]])
names(tkd) <- c("selisih", "bawah", "atas", "p_adj")
# ---- Analisis 2: ANCOVA (kovariat pretest_score) ----
fit_slope <- lm(physics_test_score ~ pretest_score * teaching_method, data = d) # uji homogenitas kemiringan regresi
a_slope <- car::Anova(fit_slope, type = 2)
print(a_slope)
p_slope <- a_slope[3, "Pr(>F)"]
fit_anc <- lm(physics_test_score ~ pretest_score + teaching_method, data = d)
a_anc <- car::Anova(fit_anc, type = 2)
print(a_anc)
p_anc <- a_anc[2, "Pr(>F)"]
peta2 <- a_anc[2, "Sum Sq"] / (a_anc[2, "Sum Sq"] + a_anc["Residuals", "Sum Sq"]) # partial eta kuadrat kelompok
em <- emmeans::emmeans(fit_anc, specs = "teaching_method") # rata-rata terkoreksi kovariat
print(em)
print(pairs(em, adjust = "tukey"))
emd <- as.data.frame(summary(em))
names(emd)[1:6] <- c("kelompok", "rerata", "se", "db", "bawah", "atas")
# ---- Grafik ----
bungkus <- scales::label_wrap(12)
pendek <- function(s, w = 12) ifelse(nchar(s) > w, paste0(trimws(substr(s, 1, w - 1)), "."), s)
rata <- aggregate(physics_test_score ~ teaching_method, data = d, FUN = mean)
p1 <- ggplot(d, aes(teaching_method, physics_test_score)) +
geom_boxplot(aes(fill = teaching_method), alpha = 0.25, outlier.shape = NA, colour = warna$redup, width = 0.6) +
geom_jitter(aes(colour = teaching_method), width = 0.15, alpha = 0.5, size = 1.3) +
geom_point(data = rata, shape = 23, size = 3.2, fill = warna$panel, colour = warna$teks, stroke = 1.1) +
scale_fill_manual(values = pal[1:3], guide = "none") +
scale_colour_manual(values = pal[1:3], guide = "none") +
scale_x_discrete(labels = bungkus) +
labs(title = "Distribution by group (diamond = mean)", x = NULL, y = "physics_test_score")
pasangan <- combn(lv, 2)
tkd$pasangan <- factor(paste(pendek(pasangan[2, ]), "-", pendek(pasangan[1, ])),
levels = rev(paste(pendek(pasangan[2, ]), "-", pendek(pasangan[1, ]))))
tkd$nyata <- ifelse(tkd$p_adj < 0.05, "p < 0.05", "n.s.")
p2 <- ggplot(tkd, aes(selisih, pasangan, colour = nyata)) +
geom_vline(xintercept = 0, linetype = "dashed", colour = warna$redup) +
geom_errorbarh(aes(xmin = bawah, xmax = atas), height = 0.25, linewidth = 0.9) +
geom_point(size = 2.8) +
scale_colour_manual(values = c("p < 0.05" = pal[2], "n.s." = warna$redup), name = NULL, drop = FALSE) +
labs(title = "Tukey HSD: mean differences (95% CI)", x = "Difference in physics_test_score", y = NULL) +
theme(legend.position = "bottom")
garis <- expand.grid(pretest_score = seq(min(d$pretest_score), max(d$pretest_score), length.out = 30), teaching_method = factor(lv, levels = lv))
garis$prediksi <- predict(fit_anc, newdata = garis)
p3 <- ggplot(d, aes(pretest_score, physics_test_score, colour = teaching_method)) +
geom_point(alpha = 0.45, size = 1.3) +
geom_line(data = garis, aes(y = prediksi), linewidth = 1.1) +
scale_colour_manual(values = pal[1:3], name = NULL, labels = pendek) +
labs(title = "ANCOVA: parallel fitted lines", x = "pretest_score", y = "physics_test_score") +
theme(legend.position = "bottom")
mentah <- aggregate(physics_test_score ~ teaching_method, data = d, FUN = function(v) c(m = mean(v), se = sd(v) / sqrt(length(v))))
dm <- rbind(data.frame(kelompok = factor(lv, levels = lv), rerata = mentah$physics_test_score[, "m"],
bawah = mentah$physics_test_score[, "m"] - 1.96 * mentah$physics_test_score[, "se"],
atas = mentah$physics_test_score[, "m"] + 1.96 * mentah$physics_test_score[, "se"], jenis = "Raw mean"),
data.frame(kelompok = emd$kelompok, rerata = emd$rerata, bawah = emd$bawah, atas = emd$atas,
jenis = "Adjusted mean"))
dm$jenis <- factor(dm$jenis, levels = c("Raw mean", "Adjusted mean"))
p4 <- ggplot(dm, aes(kelompok, rerata, colour = jenis)) +
geom_pointrange(aes(ymin = bawah, ymax = atas), position = position_dodge(width = 0.5), size = 0.45, linewidth = 0.9) +
scale_colour_manual(values = c("Raw mean" = warna$redup, "Adjusted mean" = pal[4]), name = NULL) +
scale_x_discrete(labels = bungkus) +
labs(title = "Raw vs covariate-adjusted means", x = NULL, y = "physics_test_score") +
theme(legend.position = "bottom")
p_hasil <- if (tata == 1) (p1 | p2) / (p3 | p4) else (p1 | p3) / (p4 | p2)
print(p_hasil)
The original project file is available. It is not just the picture above: you get the working R project. It can be downloaded after payment, and we send it by WhatsApp or email.
ZIP: analisis.R + data_contoh.csv + BACA-DULU.txt
Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$19
excl. 11% VAT
Duration: 3 working days
Output: R files + result figures
Deliverables
Package 2 · most chosen
US$56
excl. 11% VAT
Duration: 7 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$125
excl. 11% VAT
Duration: 12-15 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. The original project file is a ZIP containing the complete analisis.R script, a data_contoh.csv sample dataset and a BACA-DULU.txt guide. It can be downloaded after payment, and we send it by WhatsApp or email. For your own data (Package 2 and 3) the script is adapted to your dataset.
Yes. ANOVA, ANCOVA and Tukey Post Hoc Test is commonly used at this level in Education and Learning. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output R Studio gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$19, Package 2 (your data analysis and interpretation) US$56 and Package 3 (full guidance) US$125, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. R is a programming language of the R Foundation project; RStudio and Posit are trademarks of Posit PBC.
Back to R Studio portfolio