# ANALISIS PENGUKURAN BERULANG KADAR PLAK GIGI (TQHI): 3 KELOMPOK x 4 WAKTU
# Mahasiswa: Silvidiana
# NIM: 2611018009
# Jalankan seluruh script melalui Source di RStudio.
# Letakkan script ini dan data_repeated_measure_gigi.xlsx dalam folder yang sama.
# Laporan HTML dibuat otomatis setelah seluruh analisis selesai.
#
# **Nama:** Silvidiana 
# **NIM:** 2611018009  
# **Mata Kuliah:** Biostatistika Intermediate  
# **Program Studi:** Magister Kesehatan Masyarakat Universitas Mulawarman
#
# ## Metode
# Data mencakup tiga kelompok dan empat pengukuran skor plak gigi TQHI per peserta.
# Analisis meliputi repeated-measures ANOVA satu arah pada kelompok MBT, mixed ANOVA kelompok x waktu, koreksi
# Greenhouse-Geisser, pendekatan multivariat, post hoc, kontras interaksi,
# alternatif nonparametrik, dan linear mixed model (LMM).
# Baseline, minggu ke-1, ke-2, dan ke-4 tidak berjarak sama.
# Kontras tren menggunakan minggu aktual 0, 1, 2, dan 4.
# Sumber: data_repeated_measure_gigi.xlsx, sheet Wide.
# Outcome: Turesky modification of the Quigley & Hein Plaque Index (TQHI).
# Sheet Sumber menyatakan data SIMULASI untuk latihan, bukan data individu asli artikel.
# ======================= PARAMETER ANALISIS =========================
FILE_DATA <- "data_repeated_measure_gigi.xlsx"
SHEET_DATA <- "Wide"
FOLDER_HASIL <- "Hasil_Analisis_TQHI_Silvidiana"
INSTALL_PAKET_OTOMATIS <- TRUE
BUKA_HTML_OTOMATIS <- TRUE
KELOMPOK_RM <- "MBT" # Analisis satu kelompok; dapat diganti menjadi Rolling atau CBT.

analisis_tqhi_silvia <- function() {
  paket <- c("readxl", "dplyr", "tidyr", "ggplot2", "afex", "emmeans", "rstatix",
             "car", "effectsize", "lme4", "lmerTest", "pbkrtest",
             "performance", "ggpubr", "WRS2", "htmltools", "base64enc")
  belum <- paket[!vapply(paket, requireNamespace, logical(1), quietly = TRUE)]
  if (length(belum)) {
    if (!INSTALL_PAKET_OTOMATIS)
      stop("Paket belum tersedia: ", paste(belum, collapse = ", "))
    install.packages(belum, repos = "https://cloud.r-project.org")
  }
  gagal <- paket[!vapply(paket, requireNamespace, logical(1), quietly = TRUE)]
  if (length(gagal)) stop("Paket belum tersedia: ", paste(gagal, collapse = ", "))
  suppressPackageStartupMessages({
    library(dplyr); library(tidyr); library(ggplot2)
  })
  opsi_lama <- options(contrasts = c("contr.sum", "contr.poly"), width = 120)
  on.exit(options(opsi_lama), add = TRUE)
  afex::afex_options(emmeans_model = "multivariate")
  theme_set(theme_bw(base_size = 12))
  set.seed(2026)
  # Cari data di folder script dan direktori kerja.
  sumber <- unlist(lapply(sys.frames(), function(fr) {
    if (!is.null(fr$ofile)) as.character(fr$ofile) else character(0)
  }))
  if (requireNamespace("rstudioapi", quietly = TRUE) && rstudioapi::isAvailable()) {
    aktif <- tryCatch(rstudioapi::getSourceEditorContext()$path,
                     error = function(e) "")
    if (nzchar(aktif)) sumber <- c(sumber, aktif)
  }
  kandidat <- unique(c(file.path(dirname(sumber), FILE_DATA), FILE_DATA))
  kandidat <- kandidat[file.exists(kandidat)]
  if (!length(kandidat)) stop(
    "Berkas Excel tidak ditemukan. Letakkan data dan script dalam folder yang sama, ",
    "atau isi FILE_DATA dengan lokasi lengkap berkas. Nama yang dicari: ", FILE_DATA)
  path_data <- normalizePath(kandidat[1], winslash = "/", mustWork = TRUE)
  if (!SHEET_DATA %in% readxl::excel_sheets(path_data))
    stop("Sheet tidak ditemukan: ", SHEET_DATA)
  folder <- file.path(dirname(path_data), FOLDER_HASIL)
  message("Data: ", path_data, "\nSheet: ", SHEET_DATA, "\nHasil: ", folder)
  dir.create(folder, recursive = TRUE, showWarnings = FALSE)
  hasil <- list(); isi <- list(); grafik <- list()
  teks <- function(judul, x) {
    cat("\n", judul, "\n", sep = "")
    cat(x, "\n")
    isi[[length(isi) + 1L]] <<- htmltools::tagList(
      htmltools::tags$h2(judul), htmltools::tags$p(x))
  }
  tampil <- function(nama, x) {
    hasil[[nama]] <<- x
    cat("\n", gsub("_", " ", nama), "\n", sep = "")
    print(x)
    cetak <- capture.output(print(x))
    writeLines(cetak, file.path(folder, paste0(nama, "_Silvidiana.txt")))
    if (is.data.frame(x)) write.csv(x, file.path(folder, paste0(nama, "_Silvidiana.csv")), row.names = FALSE)
    isi[[length(isi) + 1L]] <<- htmltools::tagList(
      htmltools::tags$h2(gsub("_", " ", nama)),
      htmltools::tags$pre(paste(cetak, collapse = "\n")))
    invisible(x)
  }
  gambar <- function(nama, p, lebar = 11, tinggi = 6) {
    print(p)
    berkas <- file.path(folder, paste0(nama, "_Silvidiana.png"))
    ggsave(berkas, plot = p, width = lebar, height = tinggi, dpi = 300, bg = "white")
    grafik[[nama]] <<- p
    isi[[length(isi) + 1L]] <<- htmltools::tagList(
      htmltools::tags$h2(gsub("_", " ", nama)),
      htmltools::tags$img(src = base64enc::dataURI(file = berkas, mime = "image/png"),
                         style = "max-width:100%;height:auto;"))
    invisible(p)
  }
  opsional <- function(nama, ekspresi) {
    tryCatch(tampil(nama, ekspresi), error = function(e) {
      teks(nama, paste("Analisis tidak dapat diestimasi:", conditionMessage(e)))
      invisible(NULL)
    })
  }
  fp <- function(p) ifelse(is.na(p), "NA", ifelse(p < .001, "< 0,001",
                          paste0("= ", formatC(p, digits = 3, format = "f", decimal.mark = ","))))

  dat_wide <- as.data.frame(readxl::read_excel(path_data, sheet = SHEET_DATA))
  names(dat_wide) <- trimws(names(dat_wide))
  # Sesuaikan nama ID dan Kelompok pada sheet Wide ke variabel internal.
  names(dat_wide)[names(dat_wide) == "ID"] <- "id"
  names(dat_wide)[names(dat_wide) == "Kelompok"] <- "kelompok"
  kolom <- c("id", "kelompok", "TQHI_Baseline", "TQHI_Minggu1", "TQHI_Minggu2", "TQHI_Minggu4")
  if (!all(kolom %in% names(dat_wide)))
    stop("Kolom tidak ditemukan: ", paste(setdiff(kolom, names(dat_wide)), collapse = ", "))
  if (!nrow(dat_wide)) stop("Sheet data tidak memiliki peserta.")
  if (anyNA(dat_wide$id) || anyDuplicated(dat_wide$id))
    stop("ID peserta kosong atau duplikat. Periksa kolom id.")
  dat_wide$id <- trimws(as.character(dat_wide$id))
  dat_wide$kelompok <- trimws(as.character(dat_wide$kelompok))
  if (any(!nzchar(dat_wide$id)) || anyDuplicated(dat_wide$id))
    stop("ID peserta kosong atau duplikat setelah spasi dibersihkan.")
  minggu <- c(0, 1, 2, 4)
  kolom_tqhi <- c("TQHI_Baseline", "TQHI_Minggu1", "TQHI_Minggu2", "TQHI_Minggu4")
  kelompok <- c("MBT", "Rolling", "CBT")
  if (!KELOMPOK_RM %in% kelompok) stop("KELOMPOK_RM harus MBT, Rolling, atau CBT.")
  # Polinomial ortogonal berdasarkan jarak minggu aktual.
  polinom <- stats::poly(minggu, degree = 3)
  tren_minggu <- list(linear = polinom[, 1], quadratic = polinom[, 2], cubic = polinom[, 3])
  if (anyNA(dat_wide$kelompok) || !setequal(unique(dat_wide$kelompok), kelompok))
    stop("Kolom kelompok harus memuat MBT, Rolling, dan CBT tanpa nilai kosong.")
  if (!all(vapply(dat_wide[kolom_tqhi], is.numeric, logical(1))))
    stop("Kolom TQHI_Baseline, TQHI_Minggu1, TQHI_Minggu2, dan TQHI_Minggu4 harus berisi angka.")
  if (!all(is.finite(as.matrix(dat_wide[kolom_tqhi]))))
    stop("Pengukuran TQHI mengandung nilai kosong atau tak hingga. ",
         "Versi analisis ini membutuhkan empat pengukuran lengkap per peserta.")
  dat_wide <- dat_wide |> mutate(id = factor(id), kelompok = factor(kelompok, levels = c("MBT", "Rolling", "CBT")))
  dat_long <- dat_wide |>
    pivot_longer(all_of(kolom_tqhi), names_to = "waktu", values_to = "tqhi") |>
    mutate(waktu = factor(waktu, levels = kolom_tqhi, labels = c("Baseline", "Minggu 1", "Minggu 2", "Minggu 4")),
           minggu = minggu[as.integer(waktu)]) |> arrange(id, waktu)
  teks("Identitas", paste("Nama: Silvidiana | NIM: 2611018009 |",
       "Mata Kuliah: Biostatistika Intermediate | Magister Kesehatan Masyarakat Universitas Mulawarman"))
  teks("Desain", paste(nrow(dat_wide), "peserta; tiga kelompok; empat pengukuran berulang.",
                      "Tanpa nilai hilang. Outcome: skor TQHI. Data simulasi untuk latihan biostatistika."))
  tampil("01_Jumlah_Peserta", dat_wide |> count(kelompok, name = "n"))
  teks("Berkas data yang digunakan", paste(path_data, "| Sheet:", SHEET_DATA))
  teks("Sumber data", "Analisis dihitung dari sheet Wide; sheet Long memuat bentuk panjang dan Ringkasan memuat statistik agregat. Sheet Sumber menyatakan bahwa workbook ini berisi DATA SIMULASI untuk latihan, bukan data individu asli artikel. Outcome adalah Turesky modification of the Quigley & Hein Plaque Index (TQHI).")
  tampil("02_Data_Wide", head(dat_wide))
  tampil("03_Data_Long", head(dat_long, 12))
  desk <- dat_long |> group_by(kelompok, waktu, minggu) |>
    summarise(n = n(), mean = mean(tqhi), sd = sd(tqhi), median = median(tqhi),
              min = min(tqhi), max = max(tqhi), se = sd / sqrt(n),
              lower = mean - qt(.975, n - 1) * se,
              upper = mean + qt(.975, n - 1) * se, .groups = "drop")
  tampil("04_Deskriptif", desk)
  tampil("05_Kovarians", cov(dat_wide[kolom_tqhi]))
  tampil("06_Korelasi", cor(dat_wide[kolom_tqhi]))
  pasangan <- combn(kolom_tqhi, 2)
  tampil("07_Varians_Selisih", data.frame(
    pasangan = apply(pasangan, 2, paste, collapse = " - "),
    varians = apply(pasangan, 2, function(p) var(dat_wide[[p[1]]] - dat_wide[[p[2]]]))))
  gambar("G01_Profil_Rerata_CI95", ggplot(desk, aes(minggu, mean, color = kelompok, group = kelompok)) +
    geom_line(linewidth = 1) + geom_point(size = 3) +
    geom_errorbar(aes(ymin = lower, ymax = upper), width = .5) +
    scale_x_continuous(breaks = minggu) +
    labs(title = "Profil rerata skor plak gigi TQHI dan interval kepercayaan 95%", x = "Minggu", y = "Skor TQHI", color = "Kelompok") +
    theme(legend.position = "bottom"))
  gambar("G02_Lintasan_Individu", ggplot(dat_long, aes(minggu, tqhi, group = id)) +
    geom_line(alpha = .25) + stat_summary(aes(group = kelompok), fun = mean,
      geom = "line", color = "firebrick", linewidth = 1.2) +
    facet_wrap(~ kelompok) + scale_x_continuous(breaks = minggu) +
    labs(title = "Lintasan individu dan rerata kelompok", x = "Minggu", y = "Skor TQHI"))
  gambar("G03_Boxplot", ggplot(dat_long, aes(waktu, tqhi, fill = kelompok)) +
    geom_boxplot() + labs(title = "Distribusi skor plak gigi TQHI berdasarkan kelompok dan waktu", x = "Waktu", y = "Skor TQHI", fill = "Kelompok") +
    theme(legend.position = "bottom"))

  teks("Analisis satu kelompok", paste("Repeated-measures ANOVA dan alternatif nonparametrik menggunakan kelompok", KELOMPOK_RM))
  d1 <- droplevels(filter(dat_long, kelompok == KELOMPOK_RM))
  tampil("08_Outlier_Satu_Kelompok", d1 |> group_by(waktu) |> rstatix::identify_outliers(tqhi))
  tampil("09_Shapiro_Satu_Kelompok", d1 |> group_by(waktu) |> rstatix::shapiro_test(tqhi))
  gambar("G04_QQ_Satu_Kelompok", ggpubr::ggqqplot(d1, "tqhi", facet.by = "waktu"))
  aov1_rs <- rstatix::anova_test(data = d1, dv = tqhi, wid = id, within = waktu, effect.size = "pes")
  tampil("10_ANOVA_Rstatix_Satu_Kelompok", aov1_rs)
  aov1 <- afex::aov_ez(id = "id", dv = "tqhi", data = d1, within = "waktu",
                       anova_table = list(es = c("ges", "pes"), correction = "GG"))
  tampil("11_RM_ANOVA", aov1)
  tampil("12_Sferisitas_dan_Koreksi_RM", summary(aov1))
  tampil("13_Multivariat_RM", aov1$Anova)
  tampil("14_Eta_Kuadrat_RM", effectsize::eta_squared(aov1, partial = TRUE))
  em1 <- emmeans::emmeans(aov1, ~ waktu)
  tampil("15_EMM_RM", as.data.frame(em1))
  tampil("16_Posthoc_RM_Bonferroni", as.data.frame(pairs(em1, adjust = "bonferroni")))
  tampil("17_RM_vs_Baseline_Holm", as.data.frame(emmeans::contrast(em1, "trt.vs.ctrl", ref = 1, adjust = "holm")))
  tampil("18_Tren_Polinomial_RM", as.data.frame(emmeans::contrast(em1, tren_minggu)))
  tampil("19_Friedman", rstatix::friedman_test(d1, tqhi ~ waktu | id))
  tampil("20_Kendall_W", rstatix::friedman_effsize(d1, tqhi ~ waktu | id))
  tampil("21_Wilcoxon_Berpasangan", d1 |> arrange(waktu, id) |>
           rstatix::wilcox_test(tqhi ~ waktu, paired = TRUE, p.adjust.method = "bonferroni"))
  opsional("22_Robust_RM_Trim20", WRS2::rmanova(d1$tqhi, d1$waktu, d1$id, tr = .2))

  tampil("23_Outlier_Mixed", dat_long |> group_by(kelompok, waktu) |> rstatix::identify_outliers(tqhi))
  tampil("24_Shapiro_Mixed", dat_long |> group_by(kelompok, waktu) |> rstatix::shapiro_test(tqhi))
  gambar("G05_QQ_Mixed", ggpubr::ggqqplot(dat_long, "tqhi", ggtheme = theme_bw()) +
           facet_grid(waktu ~ kelompok), tinggi = 9)
  tampil("25_Levene", dat_long |> group_by(waktu) |> rstatix::levene_test(tqhi ~ kelompok))
  tampil("26_Box_M", rstatix::box_m(dat_wide[kolom_tqhi], dat_wide$kelompok))
  aov2 <- afex::aov_ez(id = "id", dv = "tqhi", data = dat_long, between = "kelompok", within = "waktu",
                       anova_table = list(es = c("ges", "pes"), correction = "GG"))
  tampil("27_Mixed_ANOVA", aov2)
  tampil("28_Sferisitas_dan_Koreksi_Mixed", summary(aov2))
  tampil("29_Multivariat_Mixed", aov2$Anova)
  tampil("30_Eta_Kuadrat_Mixed", effectsize::eta_squared(aov2, partial = TRUE))
  gambar("G06_Profil_Mixed_ANOVA", afex::afex_plot(aov2, x = "waktu", trace = "kelompok",
           error = "within", mapping = c("colour", "shape", "linetype")) +
           labs(title = "Profil mixed ANOVA", x = "Waktu", y = "Skor TQHI"))
  teks("Interval grafik mixed ANOVA", "Interval within-subject pada grafik afex berbeda dari interval kepercayaan rerata biasa pada grafik profil deskriptif.")
  tampil("31_Efek_Waktu_per_Kelompok", as.data.frame(emmeans::joint_tests(aov2, by = "kelompok")))
  tampil("32_Efek_Kelompok_per_Waktu", as.data.frame(emmeans::joint_tests(aov2, by = "waktu")))
  em2 <- emmeans::emmeans(aov2, ~ waktu | kelompok)
  em2b <- emmeans::emmeans(aov2, ~ kelompok | waktu)
  tampil("33_EMM_Waktu_per_Kelompok", as.data.frame(em2))
  tampil("34_Waktu_vs_Baseline_Holm", as.data.frame(emmeans::contrast(em2, "trt.vs.ctrl", ref = 1, adjust = "holm")))
  tampil("35_Antarkelompok_Tukey", as.data.frame(pairs(em2b, adjust = "tukey")))
  em_full <- emmeans::emmeans(aov2, ~ waktu * kelompok)
  ki <- emmeans::contrast(em_full, interaction = list(
    waktu = list("Minggu4-Baseline" = c(-1, 0, 0, 1)), kelompok = "pairwise"), adjust = "holm")
  tampil("36_Kontras_Perbedaan_Perubahan", as.data.frame(ki))
  # Bandingkan tren linear antarkelompok berdasarkan minggu aktual.
  # Susun koefisien mengikuti urutan grid EMM, bukan urutan baris Excel.
  grid_em <- as.data.frame(em_full)
  pasangan_kelompok <- combn(levels(dat_long$kelompok), 2, simplify = FALSE)
  bobot_linear <- tren_minggu$linear[match(as.character(grid_em$waktu), levels(dat_long$waktu))]
  kontras_linear <- lapply(pasangan_kelompok, function(p) {
    bobot_linear * (as.numeric(grid_em$kelompok == p[1]) - as.numeric(grid_em$kelompok == p[2]))
  })
  names(kontras_linear) <- vapply(pasangan_kelompok, paste, character(1), collapse = " - ")
  tren_lin <- as.data.frame(emmeans::contrast(em_full, kontras_linear, adjust = "holm"))
  tampil("37_Kontras_Tren_Linear", tren_lin)
  teks("Tren waktu", "Kontras polinomial dan perbedaan tren linear menggunakan minggu aktual 0, 1, 2, dan 4; waktu pada ANOVA tetap faktor. Kontras Minggu4-Baseline membandingkan perubahan skor dari baseline sampai minggu ke-4.")
  teks("Koreksi perbandingan", "Holm untuk waktu versus baseline berlaku dalam tiap kelompok; Tukey berlaku dalam tiap waktu. Kontras perbedaan perubahan dan tren linear memakai Holm pada masing-masing keluarga kontras.")
  tabel_gg <- as.data.frame(afex::nice(aov2, correction = "GG", es = "pes"))
  tampil("38_Tabel_ANOVA_GG", tabel_gg)
  tab_num <- as.data.frame(aov2$anova_table)
  if ("kelompok:waktu" %in% rownames(tab_num)) {
    r <- tab_num["kelompok:waktu", , drop = FALSE]
    teks("Interpretasi interaksi", paste0("Mixed ANOVA dengan koreksi Greenhouse-Geisser menghasilkan interaksi kelompok x waktu: F(",
      round(r[["num Df"]], 2), ", ", round(r[["den Df"]], 2), ") = ", round(r[["F"]], 3),
      "; p ", fp(r[["Pr(>F)"]]), ". ",
      if (r[["Pr(>F)"]] < .05) "Pola perubahan skor plak gigi TQHI berbeda secara statistik antar kelompok."
      else "Belum ditemukan bukti statistik perbedaan pola perubahan skor plak gigi TQHI antar kelompok.",
      " Arah dan besarnya perbedaan dinilai dari rerata serta kontras perubahan Minggu4-Baseline."))
  }

  kontrol <- lme4::lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 200000))
  lmm1 <- lmerTest::lmer(tqhi ~ kelompok * waktu + (1 | id), data = dat_long, REML = TRUE, control = kontrol)
  lmm2 <- lmerTest::lmer(tqhi ~ kelompok * waktu + (1 + minggu | id), data = dat_long, REML = TRUE, control = kontrol)
  tampil("39_LMM_Intersep", summary(lmm1))
  tampil("40_LMM_Intersep_Slope", summary(lmm2))
  tampil("41_Perbandingan_LMM_REML", anova(lmm1, lmm2, refit = FALSE))
  teks("Perbandingan model", "Kedua model mempunyai fixed effects yang sama. Perbandingan REML mengikuti materi; nilai p likelihood-ratio bersifat pendekatan karena varians acak diuji pada batas ruang parameter.")
  tampil("42_Singularitas_LMM", data.frame(model = c("Intersep", "Intersep dan slope"),
         singular = c(lme4::isSingular(lmm1), lme4::isSingular(lmm2))))
  opsional("43_LMM_Kenward_Roger", anova(lmm2, ddf = "Kenward-Roger"))
  opsional("44_ICC", performance::icc(lmm1))
  rd <- data.frame(prediksi = fitted(lmm2), residual = resid(lmm2))
  gambar("G07_QQ_Residual_LMM", ggplot(rd, aes(sample = residual)) + stat_qq() + stat_qq_line() +
         labs(title = "Q-Q residual LMM", x = "Kuantil teoretis", y = "Kuantil residual"))
  ra <- data.frame(intersep = lme4::ranef(lmm2)$id[, 1])
  gambar("G08_QQ_Intersep_Acak", ggplot(ra, aes(sample = intersep)) + stat_qq() + stat_qq_line() +
         labs(title = "Q-Q intersep acak LMM", x = "Kuantil teoretis", y = "Kuantil intersep acak"))
  gambar("G09_Residual_vs_Prediksi", ggplot(rd, aes(prediksi, residual)) + geom_point(alpha = .5) +
         geom_hline(yintercept = 0, linetype = 2) + labs(title = "Residual versus nilai prediksi LMM", x = "Prediksi skor plak gigi TQHI", y = "Residual"))
  em_lmm <- emmeans::emmeans(lmm2, ~ waktu | kelompok, lmer.df = "kenward-roger")
  tampil("45_EMM_LMM", as.data.frame(em_lmm))

  set.seed(1)
  dat_miss <- dat_long
  indeks_hilang <- sample(which(dat_miss$waktu != "Baseline"), 30)
  dat_miss$tqhi[indeks_hilang] <- NA_real_
  teks("Demonstrasi data hilang", "Sebanyak 30 pengukuran pascabaseline dihapus secara acak hanya pada salinan demonstrasi. Analisis utama tetap menggunakan seluruh data yang dilampirkan; demonstrasi ini mengikuti bagian LMM data hilang dalam materi.")
  lmm_miss <- lmerTest::lmer(tqhi ~ kelompok * waktu + (1 + minggu | id), data = dat_miss,
                            REML = TRUE, control = kontrol, na.action = na.omit)
  opsional("46_LMM_Data_Hilang_KR", anova(lmm_miss, ddf = "Kenward-Roger"))
  tampil("47_Ringkasan_Data_Hilang", data.frame(pengukuran_hilang = sum(is.na(dat_miss$tqhi)),
    peserta_terdampak = n_distinct(dat_miss$id[is.na(dat_miss$tqhi)]),
    peserta_lengkap = n_distinct(dat_miss$id) - n_distinct(dat_miss$id[is.na(dat_miss$tqhi)]),
    pengukuran_dianalisis_LMM = nobs(lmm_miss)))
  tampil("48_Informasi_Sesi", sessionInfo())
  write.csv(dat_wide, file.path(folder, "Data_TQHI_Silvidiana_Wide.csv"), row.names = FALSE)
  write.csv(dat_long, file.path(folder, "Data_TQHI_Silvidiana_Long.csv"), row.names = FALSE)
  write.csv(dat_miss, file.path(folder, "Data_Demonstrasi_Missing_Silvidiana.csv"), row.names = FALSE)
  saveRDS(list(hasil = hasil, data_wide = dat_wide, data_long = dat_long,
    aov1 = aov1, aov2 = aov2, lmm1 = lmm1, lmm2 = lmm2, lmm_miss = lmm_miss),
    file.path(folder, "Objek_Analisis_TQHI_Silvidiana.rds"))
  laporan <- htmltools::tags$html(lang = "id",
    htmltools::tags$head(htmltools::tags$meta(charset = "UTF-8"),
      htmltools::tags$title("Analisis Skor Plak Gigi (TQHI) Silvidiana: 3 x 4"),
      htmltools::tags$style("body{font-family:Arial,sans-serif;max-width:1100px;margin:40px auto;padding:20px;line-height:1.6;color:#17342e}h1,h2{color:#0b6b4f}h2{border-bottom:1px solid #d9e4e0;padding-top:24px}pre{background:#f3f7f5;padding:16px;overflow:auto;font-size:13px}img{display:block;margin:15px auto}")),
    htmltools::tags$body(htmltools::tags$h1("Analisis Pengukuran Berulang Skor Plak Gigi (TQHI) Silvidiana: 3 x 4"), isi))
  path_html <- file.path(folder, "Laporan_Analisis_TQHI_Silvidiana.html")
  htmltools::save_html(laporan, path_html)
  if (BUKA_HTML_OTOMATIS && interactive())
    try(utils::browseURL(path_html), silent = TRUE)
  cat("\nHasil analisis: ", normalizePath(folder), "\n", sep = "")
  invisible(list(hasil = hasil, grafik = grafik, data_wide = dat_wide,
                 data_long = dat_long, aov1 = aov1, aov2 = aov2,
                 lmm1 = lmm1, lmm2 = lmm2, lmm_miss = lmm_miss))
}

hasil_tqhi_silvia <- analisis_tqhi_silvia()
## Registered S3 method overwritten by 'lme4':
##   method           from
##   na.action.merMod car
## Data: D:/biostatistika tugas kedua/data_repeated_measure_gigi.xlsx
## Sheet: Wide
## Hasil: D:/biostatistika tugas kedua/Hasil_Analisis_TQHI_Silvidiana
## 
## Identitas
## Nama: Silvidiana | NIM: 2611018009 | Mata Kuliah: Biostatistika Intermediate | Magister Kesehatan Masyarakat Universitas Mulawarman 
## 
## Desain
## 90 peserta; tiga kelompok; empat pengukuran berulang. Tanpa nilai hilang. Outcome: skor TQHI. Data simulasi untuk latihan biostatistika. 
## 
## 01 Jumlah Peserta
##   kelompok  n
## 1      MBT 30
## 2  Rolling 30
## 3      CBT 30
## 
## Berkas data yang digunakan
## D:/biostatistika tugas kedua/data_repeated_measure_gigi.xlsx | Sheet: Wide 
## 
## Sumber data
## Analisis dihitung dari sheet Wide; sheet Long memuat bentuk panjang dan Ringkasan memuat statistik agregat. Sheet Sumber menyatakan bahwa workbook ini berisi DATA SIMULASI untuk latihan, bukan data individu asli artikel. Outcome adalah Turesky modification of the Quigley & Hein Plaque Index (TQHI). 
## 
## 02 Data Wide
##     id kelompok TQHI_Baseline TQHI_Minggu1 TQHI_Minggu2 TQHI_Minggu4
## 1 MB01      MBT     2.5033975    0.9095049    1.4191272    1.9174517
## 2 MB02      MBT     0.3021991    0.5710462    1.0518513    0.9014395
## 3 MB03      MBT     1.8618804    1.0379559    1.1408609    1.0483123
## 4 MB04      MBT     1.4599071    0.4566607    0.8623449    0.8122396
## 5 MB05      MBT     2.0311455    1.1609085    1.6847425    2.2469307
## 6 MB06      MBT     2.2593697    1.2614265    1.4016445    1.8944522
## 
## 03 Data Long
## # A tibble: 12 × 5
##    id    kelompok waktu     tqhi minggu
##    <fct> <fct>    <fct>    <dbl>  <dbl>
##  1 CB01  CBT      Baseline 1.48       0
##  2 CB01  CBT      Minggu 1 0.849      1
##  3 CB01  CBT      Minggu 2 1.41       2
##  4 CB01  CBT      Minggu 4 1.18       4
##  5 CB02  CBT      Baseline 2.07       0
##  6 CB02  CBT      Minggu 1 1.25       1
##  7 CB02  CBT      Minggu 2 1.42       2
##  8 CB02  CBT      Minggu 4 1.21       4
##  9 CB03  CBT      Baseline 1.83       0
## 10 CB03  CBT      Minggu 1 1.22       1
## 11 CB03  CBT      Minggu 2 1.12       2
## 12 CB03  CBT      Minggu 4 1.38       4
## 
## 04 Deskriptif
## # A tibble: 12 × 12
##    kelompok waktu    minggu     n  mean    sd median   min   max     se lower upper
##    <fct>    <fct>     <dbl> <int> <dbl> <dbl>  <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl>
##  1 MBT      Baseline      0    30  1.87 0.472   1.86 0.302  2.87 0.0862 1.69   2.04
##  2 MBT      Minggu 1      1    30  1.07 0.376   1.11 0.352  2.12 0.0687 0.927  1.21
##  3 MBT      Minggu 2      2    30  1.37 0.347   1.40 0.747  1.97 0.0634 1.24   1.50
##  4 MBT      Minggu 4      4    30  1.52 0.419   1.43 0.812  2.42 0.0765 1.37   1.68
##  5 Rolling  Baseline      0    30  1.94 0.340   1.96 1.11   2.66 0.0621 1.81   2.06
##  6 Rolling  Minggu 1      1    30  1.11 0.244   1.15 0.593  1.46 0.0445 1.02   1.20
##  7 Rolling  Minggu 2      2    30  1.29 0.287   1.28 0.792  2.01 0.0523 1.18   1.40
##  8 Rolling  Minggu 4      4    30  1.55 0.311   1.57 0.878  2.07 0.0567 1.43   1.67
##  9 CBT      Baseline      0    30  1.94 0.327   1.93 1.35   2.63 0.0598 1.82   2.06
## 10 CBT      Minggu 1      1    30  1.15 0.278   1.15 0.615  1.66 0.0507 1.04   1.25
## 11 CBT      Minggu 2      2    30  1.40 0.297   1.39 0.889  2.04 0.0542 1.29   1.52
## 12 CBT      Minggu 4      4    30  1.54 0.301   1.52 0.704  2.16 0.0549 1.43   1.66
## 
## 05 Kovarians
##               TQHI_Baseline TQHI_Minggu1 TQHI_Minggu2 TQHI_Minggu4
## TQHI_Baseline    0.14648560   0.03394710   0.04396238   0.06212269
## TQHI_Minggu1     0.03394710   0.09161299   0.03875087   0.03446044
## TQHI_Minggu2     0.04396238   0.03875087   0.09708944   0.05602839
## TQHI_Minggu4     0.06212269   0.03446044   0.05602839   0.11824543
## 
## 06 Korelasi
##               TQHI_Baseline TQHI_Minggu1 TQHI_Minggu2 TQHI_Minggu4
## TQHI_Baseline     1.0000000    0.2930399    0.3686360    0.4720202
## TQHI_Minggu1      0.2930399    1.0000000    0.4108818    0.3310931
## TQHI_Minggu2      0.3686360    0.4108818    1.0000000    0.5229137
## TQHI_Minggu4      0.4720202    0.3310931    0.5229137    1.0000000
## 
## 07 Varians Selisih
##                       pasangan   varians
## 1 TQHI_Baseline - TQHI_Minggu1 0.1702044
## 2 TQHI_Baseline - TQHI_Minggu2 0.1556503
## 3 TQHI_Baseline - TQHI_Minggu4 0.1404857
## 4  TQHI_Minggu1 - TQHI_Minggu2 0.1112007
## 5  TQHI_Minggu1 - TQHI_Minggu4 0.1409375
## 6  TQHI_Minggu2 - TQHI_Minggu4 0.1032781

## 
## Analisis satu kelompok
## Repeated-measures ANOVA dan alternatif nonparametrik menggunakan kelompok MBT 
## 
## 08 Outlier Satu Kelompok
## # A tibble: 2 × 7
##   waktu    id    kelompok  tqhi minggu is.outlier is.extreme
##   <fct>    <fct> <fct>    <dbl>  <dbl> <lgl>      <lgl>     
## 1 Baseline MB02  MBT      0.302      0 TRUE       FALSE     
## 2 Minggu 1 MB21  MBT      2.12       1 TRUE       FALSE     
## 
## 09 Shapiro Satu Kelompok
## # A tibble: 4 × 4
##   waktu    variable statistic      p
##   <fct>    <chr>        <dbl>  <dbl>
## 1 Baseline tqhi         0.935 0.0681
## 2 Minggu 1 tqhi         0.960 0.315 
## 3 Minggu 2 tqhi         0.957 0.264 
## 4 Minggu 4 tqhi         0.964 0.396

## 
## 10 ANOVA Rstatix Satu Kelompok
## ANOVA Table (type III tests)
## 
## $ANOVA
##   Effect DFn DFd      F        p p<.05   pes
## 1  waktu   3  87 42.314 5.84e-17     * 0.593
## 
## $`Mauchly's Test for Sphericity`
##   Effect     W     p p<.05
## 1  waktu 0.725 0.112      
## 
## $`Sphericity Corrections`
##   Effect   GGe      DF[GG]    p[GG] p[GG]<.05   HFe      DF[HF]    p[HF] p[HF]<.05
## 1  waktu 0.857 2.57, 74.58 7.28e-15         * 0.948 2.84, 82.47 3.39e-16         *
## 
## 
## 11 RM ANOVA
## Anova Table (Type 3 tests)
## 
## Response: tqhi
##   Effect          df  MSE         F  ges  pes p.value
## 1  waktu 2.57, 74.58 0.09 42.31 *** .341 .593   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG 
## 
## 12 Sferisitas dan Koreksi RM
## 
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
## 
##              Sum Sq num Df Error SS den Df F value    Pr(>F)    
## (Intercept) 254.772      1   12.367     29 597.414 < 2.2e-16 ***
## waktu         9.915      3    6.795     87  42.314 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Mauchly Tests for Sphericity
## 
##       Test statistic p-value
## waktu        0.72452 0.11196
## 
## 
## Greenhouse-Geisser and Huynh-Feldt Corrections
##  for Departure from Sphericity
## 
##        GG eps Pr(>F[GG])    
## waktu 0.85729  7.275e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##          HF eps   Pr(>F[HF])
## waktu 0.9479354 3.393342e-16
## 
## 13 Multivariat RM
## 
## Type III Repeated Measures MANOVA Tests: Pillai test statistic
##             Df test stat approx F num Df den Df    Pr(>F)    
## (Intercept)  1   0.95370   597.41      1     29 < 2.2e-16 ***
## waktu        1   0.76068    28.61      3     27 1.551e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 14 Eta Kuadrat RM
## # Effect Size for ANOVA (Type III)
## 
## Parameter | Eta2 (partial) |       95% CI
## -----------------------------------------
## waktu     |           0.59 | [0.48, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
## 15 EMM RM
##  waktu      emmean         SE df  lower.CL upper.CL
##  Baseline 1.866038 0.08624537 29 1.6896468 2.042430
##  Minggu.1 1.067220 0.06867046 29 0.9267734 1.207667
##  Minggu.2 1.373160 0.06338683 29 1.2435195 1.502801
##  Minggu.4 1.521926 0.07651021 29 1.3654452 1.678407
## 
## Confidence level used: 0.95 
## 
## 16 Posthoc RM Bonferroni
##  contrast              estimate         SE df t.ratio p.value
##  Baseline - Minggu.1  0.7988182 0.08346497 29   9.571 <0.0001
##  Baseline - Minggu.2  0.4928783 0.07973742 29   6.181 <0.0001
##  Baseline - Minggu.4  0.3441123 0.06457792 29   5.329 <0.0001
##  Minggu.1 - Minggu.2 -0.3059399 0.07049886 29  -4.340  0.0009
##  Minggu.1 - Minggu.4 -0.4547059 0.07633776 29  -5.956 <0.0001
##  Minggu.2 - Minggu.4 -0.1487660 0.05430493 29  -2.739  0.0625
## 
## P value adjustment: bonferroni method for 6 tests 
## 
## 17 RM vs Baseline Holm
##  contrast              estimate         SE df t.ratio p.value
##  Minggu.1 - Baseline -0.7988182 0.08346497 29  -9.571 <0.0001
##  Minggu.2 - Baseline -0.4928783 0.07973742 29  -6.181 <0.0001
##  Minggu.4 - Baseline -0.3441123 0.06457792 29  -5.329 <0.0001
## 
## P value adjustment: holm method for 3 tests 
## 
## 18 Tren Polinomial RM
##  contrast    estimate         SE df t.ratio p.value
##  linear    -0.1008636 0.04680138 29  -2.155  0.0396
##  quadratic  0.4365737 0.05586491 29   7.815 <0.0001
##  cubic     -0.3601598 0.04999076 29  -7.205 <0.0001
## 
## 
## 19 Friedman
## # A tibble: 1 × 6
##   .y.       n statistic    df        p method       
## * <chr> <int>     <dbl> <dbl>    <dbl> <chr>        
## 1 tqhi     30      50.5     3 6.19e-11 Friedman test
## 
## 20 Kendall W
## # A tibble: 1 × 5
##   .y.       n effsize method    magnitude
## * <chr> <int>   <dbl> <chr>     <ord>    
## 1 tqhi     30   0.561 Kendall W large    
## 
## 21 Wilcoxon Berpasangan
## # A tibble: 6 × 9
##   .y.   group1   group2      n1    n2 statistic             p        p.adj p.adj.signif
## * <chr> <chr>    <chr>    <int> <int>     <dbl>         <dbl>        <dbl> <chr>       
## 1 tqhi  Baseline Minggu 1    30    30       462 0.00000000931 0.0000000559 ****        
## 2 tqhi  Baseline Minggu 2    30    30       436 0.00000324    0.0000194    ****        
## 3 tqhi  Baseline Minggu 4    30    30       419 0.0000345     0.000207     ***         
## 4 tqhi  Minggu 1 Minggu 2    30    30        68 0.000380      0.00228      **          
## 5 tqhi  Minggu 1 Minggu 4    30    30        23 0.00000119    0.00000715   ****        
## 6 tqhi  Minggu 2 Minggu 4    30    30       114 0.0137        0.0820       ns          
## 
## 22 Robust RM Trim20
## Call:
## WRS2::rmanova(y = d1$tqhi, groups = d1$waktu, blocks = d1$id, 
##     tr = 0.2)
## 
## Test statistic: F = 31.0465 
## Degrees of freedom 1: 2.59 
## Degrees of freedom 2: 44.05 
## p-value: 0 
## 
## 
## 23 Outlier Mixed
## # A tibble: 6 × 7
##   kelompok waktu    id     tqhi minggu is.outlier is.extreme
##   <fct>    <fct>    <fct> <dbl>  <dbl> <lgl>      <lgl>     
## 1 MBT      Baseline MB02  0.302      0 TRUE       FALSE     
## 2 MBT      Minggu 1 MB21  2.12       1 TRUE       FALSE     
## 3 Rolling  Baseline Ro02  1.11       0 TRUE       FALSE     
## 4 Rolling  Baseline Ro08  2.66       0 TRUE       FALSE     
## 5 Rolling  Minggu 2 Ro22  2.01       2 TRUE       FALSE     
## 6 CBT      Minggu 4 CB18  0.704      4 TRUE       FALSE     
## 
## 24 Shapiro Mixed
## # A tibble: 12 × 5
##    kelompok waktu    variable statistic      p
##    <fct>    <fct>    <chr>        <dbl>  <dbl>
##  1 MBT      Baseline tqhi         0.935 0.0681
##  2 MBT      Minggu 1 tqhi         0.960 0.315 
##  3 MBT      Minggu 2 tqhi         0.957 0.264 
##  4 MBT      Minggu 4 tqhi         0.964 0.396 
##  5 Rolling  Baseline tqhi         0.979 0.796 
##  6 Rolling  Minggu 1 tqhi         0.957 0.254 
##  7 Rolling  Minggu 2 tqhi         0.979 0.811 
##  8 Rolling  Minggu 4 tqhi         0.969 0.511 
##  9 CBT      Baseline tqhi         0.979 0.789 
## 10 CBT      Minggu 1 tqhi         0.971 0.554 
## 11 CBT      Minggu 2 tqhi         0.975 0.672 
## 12 CBT      Minggu 4 tqhi         0.975 0.696

## 
## 25 Levene
## # A tibble: 4 × 5
##   waktu      df1   df2 statistic     p
##   <fct>    <int> <int>     <dbl> <dbl>
## 1 Baseline     2    87     0.999 0.372
## 2 Minggu 1     2    87     1.63  0.201
## 3 Minggu 2     2    87     0.579 0.563
## 4 Minggu 4     2    87     2.25  0.111
## 
## 26 Box M
## # A tibble: 1 × 4
##   statistic p.value parameter method                                             
##       <dbl>   <dbl>     <dbl> <chr>                                              
## 1      22.6   0.307        20 Box's M-test for Homogeneity of Covariance Matrices
## 
## 27 Mixed ANOVA
## Anova Table (Type 3 tests)
## 
## Response: tqhi
##           Effect           df  MSE          F  ges  pes p.value
## 1       kelompok        2, 87 0.25       0.34 .004 .008    .713
## 2          waktu 2.80, 243.59 0.07 150.74 *** .439 .634   <.001
## 3 kelompok:waktu 5.60, 243.59 0.07       0.61 .006 .014    .714
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG 
## 
## 28 Sferisitas dan Koreksi Mixed
## 
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
## 
##                Sum Sq num Df Error SS den Df   F value Pr(>F)    
## (Intercept)    787.66      1   21.900     87 3129.0001 <2e-16 ***
## kelompok         0.17      2   21.900     87    0.3398 0.7129    
## waktu           31.24      3   18.033    261  150.7380 <2e-16 ***
## kelompok:waktu   0.25      6   18.033    261    0.6062 0.7253    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Mauchly Tests for Sphericity
## 
##                Test statistic  p-value
## waktu                 0.89339 0.085378
## kelompok:waktu        0.89339 0.085378
## 
## 
## Greenhouse-Geisser and Huynh-Feldt Corrections
##  for Departure from Sphericity
## 
##                 GG eps Pr(>F[GG])    
## waktu          0.93331     <2e-16 ***
## kelompok:waktu 0.93331     0.7139    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                   HF eps   Pr(>F[HF])
## waktu          0.9675152 6.178315e-55
## kelompok:waktu 0.9675152 7.198361e-01
## 
## 29 Multivariat Mixed
## 
## Type III Repeated Measures MANOVA Tests: Pillai test statistic
##                Df test stat approx F num Df den Df Pr(>F)    
## (Intercept)     1   0.97295  3129.00      1     87 <2e-16 ***
## kelompok        2   0.00775     0.34      2     87 0.7129    
## waktu           1   0.79827   112.12      3     85 <2e-16 ***
## kelompok:waktu  2   0.04821     0.71      6    172 0.6435    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 30 Eta Kuadrat Mixed
## # Effect Size for ANOVA (Type III)
## 
## Parameter      | Eta2 (partial) |       95% CI
## ----------------------------------------------
## kelompok       |       7.75e-03 | [0.00, 1.00]
## waktu          |           0.63 | [0.58, 1.00]
## kelompok:waktu |           0.01 | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
## Warning: Panel(s) show a mixed within-between-design.
## Error bars do not allow comparisons across all means.
## Suppress error bars with: error = "none"

## 
## Interval grafik mixed ANOVA
## Interval within-subject pada grafik afex berbeda dari interval kepercayaan rerata biasa pada grafik profil deskriptif. 
## 
## 31 Efek Waktu per Kelompok
## kelompok = MBT:
##  model term df1 df2 F.ratio p.value
##  waktu        3  87  37.043 <0.0001
## 
## kelompok = Rolling:
##  model term df1 df2 F.ratio p.value
##  waktu        3  87  42.635 <0.0001
## 
## kelompok = CBT:
##  model term df1 df2 F.ratio p.value
##  waktu        3  87  36.534 <0.0001
## 
## 
## 32 Efek Kelompok per Waktu
## waktu = Baseline:
##  model term df1 df2 F.ratio p.value
##  kelompok     2  87   0.360  0.6988
## 
## waktu = Minggu.1:
##  model term df1 df2 F.ratio p.value
##  kelompok     2  87   0.501  0.6079
## 
## waktu = Minggu.2:
##  model term df1 df2 F.ratio p.value
##  kelompok     2  87   1.078  0.3449
## 
## waktu = Minggu.4:
##  model term df1 df2 F.ratio p.value
##  kelompok     2  87   0.057  0.9447
## 
## 
## 33 EMM Waktu per Kelompok
## kelompok = MBT:
##  waktu      emmean         SE df  lower.CL upper.CL
##  Baseline 1.866038 0.07038555 87 1.7261395 2.005937
##  Minggu.1 1.067220 0.05557358 87 0.9567617 1.177679
##  Minggu.2 1.373160 0.05683903 87 1.2601864 1.486134
##  Minggu.4 1.521926 0.06345752 87 1.3957974 1.648055
## 
## kelompok = Rolling:
##  waktu      emmean         SE df  lower.CL upper.CL
##  Baseline 1.937802 0.07038555 87 1.7979034 2.077701
##  Minggu.1 1.107048 0.05557358 87 0.9965892 1.217506
##  Minggu.2 1.290630 0.05683903 87 1.1776562 1.403604
##  Minggu.4 1.550863 0.06345752 87 1.4247345 1.676992
## 
## kelompok = CBT:
##  waktu      emmean         SE df  lower.CL upper.CL
##  Baseline 1.940455 0.07038555 87 1.8005564 2.080354
##  Minggu.1 1.145862 0.05557358 87 1.0354038 1.256321
##  Minggu.2 1.404946 0.05683903 87 1.2919725 1.517920
##  Minggu.4 1.544095 0.06345752 87 1.4179663 1.670224
## 
## Confidence level used: 0.95 
## 
## 34 Waktu vs Baseline Holm
## kelompok = MBT:
##  contrast              estimate         SE df t.ratio p.value
##  Minggu.1 - Baseline -0.7988182 0.07612436 87 -10.494 <0.0001
##  Minggu.2 - Baseline -0.4928783 0.07184473 87  -6.860 <0.0001
##  Minggu.4 - Baseline -0.3441123 0.06908459 87  -4.981 <0.0001
## 
## kelompok = Rolling:
##  contrast              estimate         SE df t.ratio p.value
##  Minggu.1 - Baseline -0.8307546 0.07612436 87 -10.913 <0.0001
##  Minggu.2 - Baseline -0.6471723 0.07184473 87  -9.008 <0.0001
##  Minggu.4 - Baseline -0.3869391 0.06908459 87  -5.601 <0.0001
## 
## kelompok = CBT:
##  contrast              estimate         SE df t.ratio p.value
##  Minggu.1 - Baseline -0.7945930 0.07612436 87 -10.438 <0.0001
##  Minggu.2 - Baseline -0.5355091 0.07184473 87  -7.454 <0.0001
##  Minggu.4 - Baseline -0.3963603 0.06908459 87  -5.737 <0.0001
## 
## P value adjustment: holm method for 3 tests 
## 
## 35 Antarkelompok Tukey
## waktu = Baseline:
##  contrast         estimate         SE df t.ratio p.value
##  MBT - Rolling -0.07176391 0.09954020 87  -0.721  0.7518
##  MBT - CBT     -0.07441693 0.09954020 87  -0.748  0.7359
##  Rolling - CBT -0.00265302 0.09954020 87  -0.027  0.9996
## 
## waktu = Minggu.1:
##  contrast         estimate         SE df t.ratio p.value
##  MBT - Rolling -0.03982751 0.07859291 87  -0.507  0.8683
##  MBT - CBT     -0.07864207 0.07859291 87  -1.001  0.5785
##  Rolling - CBT -0.03881457 0.07859291 87  -0.494  0.8744
## 
## waktu = Minggu.2:
##  contrast         estimate         SE df t.ratio p.value
##  MBT - Rolling  0.08253014 0.08038252 87   1.027  0.5621
##  MBT - CBT     -0.03178616 0.08038252 87  -0.395  0.9175
##  Rolling - CBT -0.11431630 0.08038252 87  -1.422  0.3340
## 
## waktu = Minggu.4:
##  contrast         estimate         SE df t.ratio p.value
##  MBT - Rolling -0.02893709 0.08974249 87  -0.322  0.9443
##  MBT - CBT     -0.02216887 0.08974249 87  -0.247  0.9669
##  Rolling - CBT  0.00676822 0.08974249 87   0.075  0.9969
## 
## P value adjustment: tukey method for comparing a family of 3 estimates 
## 
## 36 Kontras Perbedaan Perubahan
##  waktu_custom     kelompok_pairwise   estimate         SE df t.ratio p.value
##  Minggu4-Baseline MBT - Rolling     0.04282682 0.09770036 87   0.438  1.0000
##  Minggu4-Baseline MBT - CBT         0.05224806 0.09770036 87   0.535  1.0000
##  Minggu4-Baseline Rolling - CBT     0.00942124 0.09770036 87   0.096  1.0000
## 
## P value adjustment: holm method for 3 tests 
## 
## 37 Kontras Tren Linear
##  contrast      estimate SE df z.ratio p.value
##  MBT - Rolling   nonEst NA NA      NA      NA
##  MBT - CBT       nonEst NA NA      NA      NA
##  Rolling - CBT   nonEst NA NA      NA      NA
## 
## P value adjustment: holm method for 1 tests 
## 
## Tren waktu
## Kontras polinomial dan perbedaan tren linear menggunakan minggu aktual 0, 1, 2, dan 4; waktu pada ANOVA tetap faktor. Kontras Minggu4-Baseline membandingkan perubahan skor dari baseline sampai minggu ke-4. 
## 
## Koreksi perbandingan
## Holm untuk waktu versus baseline berlaku dalam tiap kelompok; Tukey berlaku dalam tiap waktu. Kontras perbedaan perubahan dan tren linear memakai Holm pada masing-masing keluarga kontras. 
## 
## 38 Tabel ANOVA GG
##           Effect           df  MSE          F  pes p.value
## 1       kelompok        2, 87 0.25       0.34 .008    .713
## 2          waktu 2.80, 243.59 0.07 150.74 *** .634   <.001
## 3 kelompok:waktu 5.60, 243.59 0.07       0.61 .014    .714
## 
## Interpretasi interaksi
## Mixed ANOVA dengan koreksi Greenhouse-Geisser menghasilkan interaksi kelompok x waktu: F(5.6, 243.59) = 0.606; p = 0,714. Belum ditemukan bukti statistik perbedaan pola perubahan skor plak gigi TQHI antar kelompok. Arah dan besarnya perbedaan dinilai dari rerata serta kontras perubahan Minggu4-Baseline. 
## 
## 39 LMM Intersep
## Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
## Formula: tqhi ~ kelompok * waktu + (1 | id)
##    Data: dat_long
## Control: kontrol
## 
## REML criterion at convergence: 228
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8781 -0.6009  0.0176  0.5868  2.5173 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.04566  0.2137  
##  Residual             0.06909  0.2629  
## Number of obs: 360, groups:  id, 90
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)        1.479171   0.026443  87.000000  55.937  < 2e-16 ***
## kelompok1         -0.022084   0.037396  87.000000  -0.591   0.5564    
## kelompok2         -0.007585   0.037396  87.000000  -0.203   0.8397    
## waktu1             0.435595   0.023995 261.000000  18.154  < 2e-16 ***
## waktu2            -0.372460   0.023995 261.000000 -15.522  < 2e-16 ***
## waktu3            -0.122925   0.023995 261.000000  -5.123 5.85e-07 ***
## kelompok1:waktu1  -0.026643   0.033934 261.000000  -0.785   0.4331    
## kelompok2:waktu1   0.030622   0.033934 261.000000   0.902   0.3677    
## kelompok1:waktu2  -0.017405   0.033934 261.000000  -0.513   0.6084    
## kelompok2:waktu2   0.007922   0.033934 261.000000   0.233   0.8156    
## kelompok1:waktu3   0.038999   0.033934 261.000000   1.149   0.2515    
## kelompok2:waktu3  -0.058031   0.033934 261.000000  -1.710   0.0884 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) klmpk1 klmpk2 waktu1 waktu2 waktu3 klm1:1 klm2:1 klm1:2 klm2:2 klm1:3
## kelompok1    0.000                                                                      
## kelompok2    0.000 -0.500                                                               
## waktu1       0.000  0.000  0.000                                                        
## waktu2       0.000  0.000  0.000 -0.333                                                 
## waktu3       0.000  0.000  0.000 -0.333 -0.333                                          
## klmpk1:wkt1  0.000  0.000  0.000  0.000  0.000  0.000                                   
## klmpk2:wkt1  0.000  0.000  0.000  0.000  0.000  0.000 -0.500                            
## klmpk1:wkt2  0.000  0.000  0.000  0.000  0.000  0.000 -0.333  0.167                     
## klmpk2:wkt2  0.000  0.000  0.000  0.000  0.000  0.000  0.167 -0.333 -0.500              
## klmpk1:wkt3  0.000  0.000  0.000  0.000  0.000  0.000 -0.333  0.167 -0.333  0.167       
## klmpk2:wkt3  0.000  0.000  0.000  0.000  0.000  0.000  0.167 -0.333  0.167 -0.333 -0.500
## 
## 40 LMM Intersep Slope
## Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
## Formula: tqhi ~ kelompok * waktu + (1 + minggu | id)
##    Data: dat_long
## Control: kontrol
## 
## REML criterion at convergence: 227.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9373 -0.5996  0.0142  0.5929  2.5305 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr 
##  id       (Intercept) 4.372e-02 0.209093      
##           minggu      8.262e-05 0.009089 0.26 
##  Residual             6.885e-02 0.262393      
## Number of obs: 360, groups:  id, 90
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)        1.479171   0.026443  87.000004  55.937  < 2e-16 ***
## kelompok1         -0.022084   0.037396  87.000004  -0.591   0.5564    
## kelompok2         -0.007585   0.037396  87.000004  -0.203   0.8397    
## waktu1             0.435595   0.024012 240.963367  18.141  < 2e-16 ***
## waktu2            -0.372460   0.023964 204.851565 -15.543  < 2e-16 ***
## waktu3            -0.122925   0.023954 177.363410  -5.132 7.49e-07 ***
## kelompok1:waktu1  -0.026643   0.033958 240.963367  -0.785   0.4335    
## kelompok2:waktu1   0.030622   0.033958 240.963367   0.902   0.3681    
## kelompok1:waktu2  -0.017405   0.033890 204.851565  -0.514   0.6081    
## kelompok2:waktu2   0.007922   0.033890 204.851565   0.234   0.8154    
## kelompok1:waktu3   0.038999   0.033876 177.363411   1.151   0.2512    
## kelompok2:waktu3  -0.058031   0.033876 177.363411  -1.713   0.0885 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) klmpk1 klmpk2 waktu1 waktu2 waktu3 klm1:1 klm2:1 klm1:2 klm2:2 klm1:3
## kelompok1    0.000                                                                      
## kelompok2    0.000 -0.500                                                               
## waktu1      -0.020  0.000  0.000                                                        
## waktu2      -0.008  0.000  0.000 -0.330                                                 
## waktu3       0.003  0.000  0.000 -0.333 -0.333                                          
## klmpk1:wkt1  0.000 -0.020  0.010  0.000  0.000  0.000                                   
## klmpk2:wkt1  0.000  0.010 -0.020  0.000  0.000  0.000 -0.500                            
## klmpk1:wkt2  0.000 -0.008  0.004  0.000  0.000  0.000 -0.330  0.165                     
## klmpk2:wkt2  0.000  0.004 -0.008  0.000  0.000  0.000  0.165 -0.330 -0.500              
## klmpk1:wkt3  0.000  0.003 -0.001  0.000  0.000  0.000 -0.333  0.167 -0.333  0.167       
## klmpk2:wkt3  0.000 -0.001  0.003  0.000  0.000  0.000  0.167 -0.333  0.167 -0.333 -0.500
## 
## 41 Perbandingan LMM REML
## Data: dat_long
## Models:
## lmm1: tqhi ~ kelompok * waktu + (1 | id)
## lmm2: tqhi ~ kelompok * waktu + (1 + minggu | id)
##      npar    AIC    BIC  logLik -2*log(L)  Chisq Df Pr(>Chisq)
## lmm1   14 256.02 310.42 -114.01    228.02                     
## lmm2   16 259.94 322.12 -113.97    227.94 0.0752  2     0.9631
## 
## Perbandingan model
## Kedua model mempunyai fixed effects yang sama. Perbandingan REML mengikuti materi; nilai p likelihood-ratio bersifat pendekatan karena varians acak diuji pada batas ruang parameter. 
## 
## 42 Singularitas LMM
##                model singular
## 1           Intersep    FALSE
## 2 Intersep dan slope    FALSE
## 
## 43 LMM Kenward Roger
## Type III Analysis of Variance Table with Kenward-Roger's method
##                 Sum Sq Mean Sq NumDF  DenDF  F value Pr(>F)    
## kelompok        0.0468  0.0234     2  87.00   0.3398 0.7129    
## waktu          31.2286 10.4095     3 185.37 150.4978 <2e-16 ***
## kelompok:waktu  0.2510  0.0418     6 206.40   0.6040 0.7270    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 44 ICC
## # Intraclass Correlation Coefficient
## 
##     Adjusted ICC: 0.398
##   Unadjusted ICC: 0.225

## 
## 45 EMM LMM
## kelompok = MBT:
##  waktu      emmean         SE     df  lower.CL upper.CL
##  Baseline 1.866038 0.06125631 144.88 1.7449669 1.987110
##  Minggu 1 1.067220 0.06154967 203.26 0.9458625 1.188578
##  Minggu 2 1.373160 0.06188615 213.79 1.2511749 1.495145
##  Minggu 4 1.521926 0.06268563 106.78 1.3976562 1.646196
## 
## kelompok = Rolling:
##  waktu      emmean         SE     df  lower.CL upper.CL
##  Baseline 1.937802 0.06125631 144.88 1.8167308 2.058874
##  Minggu 1 1.107048 0.06154967 203.26 0.9856900 1.228405
##  Minggu 2 1.290630 0.06188615 213.79 1.1686448 1.412615
##  Minggu 4 1.550863 0.06268563 106.78 1.4265933 1.675133
## 
## kelompok = CBT:
##  waktu      emmean         SE     df  lower.CL upper.CL
##  Baseline 1.940455 0.06125631 144.88 1.8193839 2.061527
##  Minggu 1 1.145862 0.06154967 203.26 1.0245046 1.267220
##  Minggu 2 1.404946 0.06188615 213.79 1.2829611 1.526931
##  Minggu 4 1.544095 0.06268563 106.78 1.4198251 1.668365
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## 
## Demonstrasi data hilang
## Sebanyak 30 pengukuran pascabaseline dihapus secara acak hanya pada salinan demonstrasi. Analisis utama tetap menggunakan seluruh data yang dilampirkan; demonstrasi ini mengikuti bagian LMM data hilang dalam materi. 
## 
## 46 LMM Data Hilang KR
## Type III Analysis of Variance Table with Kenward-Roger's method
##                 Sum Sq Mean Sq NumDF   DenDF  F value Pr(>F)    
## kelompok        0.0186  0.0093     2  86.685   0.1341 0.8747    
## waktu          28.3363  9.4454     3 169.523 135.3050 <2e-16 ***
## kelompok:waktu  0.1918  0.0320     6 187.926   0.4573 0.8391    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 47 Ringkasan Data Hilang
##   pengukuran_hilang peserta_terdampak peserta_lengkap pengukuran_dianalisis_LMM
## 1                30                25              65                       330
## 
## 48 Informasi Sesi
## R version 4.6.1 (2026-06-24 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 11 x64 (build 26200)
## 
## Matrix products: default
##   LAPACK version 3.12.1
## 
## locale:
## [1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    
## 
## time zone: Asia/Singapore
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggplot2_4.0.3 tidyr_1.3.2   dplyr_1.2.1  
## 
## loaded via a namespace (and not attached):
##  [1] gtable_0.3.6        xfun_0.60           bslib_0.12.0        bayestestR_0.19.0   insight_1.5.4      
##  [6] rstatix_1.1.0       lattice_0.22-9      numDeriv_2016.8-1.1 vctrs_0.7.3         tools_4.6.1        
## [11] Rdpack_2.6.6        generics_0.1.4      pbkrtest_0.5.5      datawizard_1.4.0    parallel_4.6.1     
## [16] tibble_3.3.1        pkgconfig_2.0.3     Matrix_1.7-5        WRS2_1.1-7          RColorBrewer_1.1-3 
## [21] S7_0.2.2            readxl_1.5.0.1      afex_1.5-1          lifecycle_1.0.5     compiler_4.6.1     
## [26] farver_2.1.2        stringr_1.6.0       lmerTest_3.2-1      carData_3.0-6       htmltools_0.5.9    
## [31] sass_0.4.10         yaml_2.3.12         Formula_1.2-6       ggpubr_1.0.0        pillar_1.11.1      
## [36] car_3.1-5           nloptr_2.2.1        jquerylib_0.1.4     MASS_7.3-65         cachem_1.1.0       
## [41] reformulas_0.4.4    boot_1.3-32         abind_1.4-8         nlme_3.1-169        tidyselect_1.2.1   
## [46] digest_0.6.39       performance_0.18.2  mvtnorm_1.4-2       stringi_1.8.9       reshape2_1.4.5     
## [51] purrr_1.2.2         labeling_0.4.3      splines_4.6.1       fastmap_1.2.0       grid_4.6.1         
## [56] cli_3.6.6           magrittr_2.0.5      base64enc_0.1-6     utf8_1.2.6          broom_1.0.13       
## [61] withr_3.0.3         scales_1.4.0        backports_1.5.1     estimability_2.0.0  rmarkdown_2.31     
## [66] emmeans_2.0.4       lme4_2.0-6          ggsignif_0.6.4      cellranger_1.1.0    evaluate_1.0.5     
## [71] knitr_1.51          parameters_0.29.3   rbibutils_2.4.1     rlang_1.3.0         Rcpp_1.1.2         
## [76] glue_1.8.1          reshape_0.8.10      rstudioapi_0.19.0   minqa_1.2.8         jsonlite_2.0.0     
## [81] effectsize_1.0.3    R6_2.6.1            plyr_1.8.9         
## 
## Hasil analisis: D:\biostatistika tugas kedua\Hasil_Analisis_TQHI_Silvidiana