# ============================================================
# TUGAS BIOSTATISTIKA INTERMEDIETE
# PENGARUH TEH DAUN KELOR TERHADAP PENINGKATAN KADAR HEMOGBLOBIN PENEDERITA ANEMIA
# Nama         : Fadillah Hana Hafifah
# NIM          : 2611018008
# Rpubs        : Dilla01
# Mata Kuliah  : Biostatistika Intermediete
# Magister Kesehatan Masyarakat Universitas Mulawarman
#
# Data: https://jurnal.stikesmus.ac.id/index.php/avicenna/article/view/590/395
# Analisis sekunder menggunakan RM ANOVA, Mixed Design ANOVA, dan LMM.
# ============================================================

# ======================= PARAMETER ANALISIS =========================
FILE_DATA <- "dtdaunkelor.xlsx"
SHEET_DATA <- "Data"
KELOMPOK_FOKUS <- "Teh Daun Kelor"
FOLDER_HASIL <- "hasil analisis teh daun kelor"
INSTALL_PAKET_OTOMATIS <- TRUE
BUKA_HTML_OTOMATIS <- TRUE
TAMPILKAN_GRAFIK_RSTUDIO <- TRUE

# ======================== PROGRAM UTAMA ==============================
jalankan_analisis <- function() {

  waktu_mulai <- Sys.time()

  # ---------- Paket ----------
  paket <- c(
    "readxl", "dplyr", "tidyr", "ggplot2",
    "afex", "emmeans", "rstatix", "car", "effectsize",
    "lme4", "lmerTest", "pbkrtest", "performance",
    "ggpubr", "knitr", "htmltools", "base64enc", "tibble"
  )

  belum <- paket[!vapply(paket, requireNamespace, logical(1), quietly = TRUE)]

  if (length(belum)) {
    if (!INSTALL_PAKET_OTOMATIS)
      stop("Paket belum tersedia: ", paste(belum, collapse = ", "))
    message("Menginstal paket: ", paste(belum, collapse = ", "))
    install.packages(belum, repos = "https://cloud.r-project.org")
  }

  gagal_paket <- paket[!vapply(paket, requireNamespace, logical(1), quietly = TRUE)]
  if (length(gagal_paket))
    stop("Instalasi gagal: ", paste(gagal_paket, collapse = ", "))

  suppressPackageStartupMessages({
    library(dplyr)
    library(tidyr)
    library(ggplot2)
    library(afex)
    library(emmeans)
    library(rstatix)
    library(car)
    library(effectsize)
    library(lme4)
    library(lmerTest)
    library(pbkrtest)
    library(performance)
    library(ggpubr)
    library(knitr)
    library(htmltools)
    library(base64enc)
    library(tibble)
  })

  opsi_lama <- options(contrasts = c("contr.sum", "contr.poly"))
  on.exit(options(opsi_lama), add = TRUE)

  # ---------- Lokasi file ----------
  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_DATA,
    file.path(dirname(sumber), FILE_DATA),
    file.path(getwd(), FILE_DATA)
  ))

  kandidat <- kandidat[file.exists(kandidat)]

  # Fallback: cari dtdaunkelor dengan ekstensi Excel apa pun
  if (!length(kandidat)) {
    folder_script <- if (length(sumber)) dirname(tail(sumber, 1)) else getwd()
    kandidat_excel <- list.files(
      folder_script,
      pattern = "^dtdaunkelor\\\\.(xlsx|xls|xlsm)$",
      full.names = TRUE,
      ignore.case = TRUE
    )
    if (length(kandidat_excel)) {
      kandidat <- kandidat_excel
    }
  }

  if (!length(kandidat)) {
    stop(
      "Berkas data tidak ditemukan.\\n",
      "R sedang mencari: ", FILE_DATA, "\\n",
      "Pastikan file Excel dan script R berada pada folder yang sama."
    )
  }

  path_data <- normalizePath(
    kandidat[1], winslash = "/", mustWork = TRUE
  )

  folder <- file.path(dirname(path_data), FOLDER_HASIL)
  dir.create(folder, recursive = TRUE, showWarnings = FALSE)
  folder <- normalizePath(folder, winslash = "/", mustWork = TRUE)

  message("Data: ", path_data)
  message("Hasil: ", folder)

  # ---------- Fungsi laporan ----------
  isi <- character(0)
  status <- data.frame()

  tambah <- function(html) isi <<- c(isi, html)

  escape <- function(x) {
    as.character(htmltools::htmlEscape(paste(x, collapse = "\n")))
  }

  narasi <- function(x) {
    tambah(paste0("<p>", escape(x), "</p>"))
  }

  output <- function(x) {
    teks <- capture.output(print(x))
    cat(paste(teks, collapse = "\n"), "\n")
    tambah(paste0("<pre>", escape(teks), "</pre>"))
    invisible(x)
  }

  tabel <- function(x, nama) {
    x <- as.data.frame(x)

    write.csv(
      x,
      file.path(folder, paste0(nama, ".csv")),
      row.names = FALSE,
      na = "",
      fileEncoding = "UTF-8"
    )

    if (nrow(x)) {
      tambah(
        paste0(
          "<div class='table'>",
          as.character(knitr::kable(
            x, format = "html", digits = 4
          )),
          "</div>"
        )
      )
    } else {
      narasi("Tidak ada baris untuk tabel ini.")
    }

    print(x)
    invisible(x)
  }

  gambar <- function(p, nama, lebar = 10, tinggi = 6) {
    path <- file.path(folder, paste0(nama, ".png"))

    ggplot2::ggsave(
      path, plot = p,
      width = lebar, height = tinggi, dpi = 180
    )

    if (TAMPILKAN_GRAFIK_RSTUDIO) {
      tryCatch(print(p), error = function(e) {
        message(
          "Tampilan Plots gagal, tetapi PNG tetap tersimpan: ",
          conditionMessage(e)
        )
      })
    }

    tambah(
      paste0(
        "<figure><img src='",
        base64enc::dataURI(file = path, mime = "image/png"),
        "' alt='", escape(nama),
        "'><figcaption>", escape(nama),
        "</figcaption></figure>"
      )
    )

    message("Grafik tersimpan: ", path)
  }

  bagian <- function(judul, f) {
    message("\n>>> ", judul)
    tambah(paste0("<h2>", escape(judul), "</h2>"))

    warnings <- character(0)

    ok <- tryCatch(
      withCallingHandlers(
        {
          f()
          TRUE
        },
        warning = function(w) {
          warnings <<- c(warnings, conditionMessage(w))
          invokeRestart("muffleWarning")
        }
      ),
      error = function(e) {
        narasi(paste("BAGIAN GAGAL:", conditionMessage(e)))
        message("Bagian gagal: ", conditionMessage(e))
        FALSE
      }
    )

    if (length(warnings)) {
      narasi(
        paste(
          "Peringatan estimasi:",
          paste(unique(warnings), collapse = "; ")
        )
      )
    }

    status <<- rbind(
      status,
      data.frame(
        bagian = judul,
        status = if (ok) "Selesai" else "Gagal",
        peringatan = paste(unique(warnings), collapse = "; ")
      )
    )

    invisible(ok)
  }

  fp <- function(p) {
    if (length(p) == 0 || is.na(p)) return("tidak tersedia")
    if (p < .001) "< 0,001"
    else paste0(
      "= ",
      formatC(
        p, digits = 3,
        format = "f",
        decimal.mark = ","
      )
    )
  }

  ringkas_interaksi <- function(tab, pcol, model) {
    idx <- which(grepl(
      "kelompok:waktu|waktu:kelompok",
      rownames(tab)
    ))

    if (!length(idx)) {
      narasi(
        "Efek interaksi tidak teridentifikasi secara otomatis pada tabel model."
      )
      return(invisible(NULL))
    }

    p <- as.numeric(tab[idx[1], pcol])

    narasi(
      paste0(
        model,
        ": interaksi kelompok × waktu memiliki p ",
        fp(p),
        ". ",
        if (is.na(p)) {
          "Pengujian tidak dapat disimpulkan."
        } else if (p < .05) {
          "Terdapat bukti bahwa pola perubahan Hb berbeda antarkelompok."
        } else {
          "Belum ditemukan bukti bahwa pola perubahan Hb berbeda antarkelompok. "
        }
      )
    )
  }

  # ========================= 1. MEMBACA DATA ==========================
  bagian("1. Sumber, desain, dan kelengkapan data", function() {

    raw <- as.data.frame(
      readxl::read_excel(
        path_data,
        sheet = SHEET_DATA
      )
    )

    names(raw) <- trimws(names(raw))

    kolom_hb <- c(
      "Hb_Minggu0",
      "Hb_Minggu1",
      "Hb_Minggu2",
      "Hb_Minggu3"
    )

    wajib <- c(
      "ID",
      "Kelompok",
      "Umur",
      "Pendidikan",
      kolom_hb
    )

    if (!all(wajib %in% names(raw))) {
      stop(
        "Kolom tidak ditemukan: ",
        paste(setdiff(wajib, names(raw)), collapse = ", ")
      )
    }

    level_kelompok <<- c(
      "Kapsul Gelatin",
      "Teh Daun Kelor",
      "Tablet Fe"
    )

    label_waktu <<- c(
      "M0", "M1", "M2", "M3"
    )

    minggu_nilai <<- c(0, 1, 2, 3)

    kel <- trimws(as.character(raw[["Kelompok"]]))

    if (anyNA(kel) || any(!kel %in% level_kelompok)) {
      stop("Label kelompok tidak dikenali.")
    }

    if (anyNA(raw[["ID"]]) || anyDuplicated(raw[["ID"]])) {
      stop("ID hilang atau duplikat.")
    }

    if (!KELOMPOK_FOKUS %in% level_kelompok) {
      stop("KELOMPOK_FOKUS tidak dikenali.")
    }

    if (!all(vapply(raw[kolom_hb], is.numeric, logical(1)))) {
      stop("Kolom Hb harus numerik.")
    }

    if (
      any(
        !is.finite(as.matrix(raw[kolom_hb])) &
          !is.na(as.matrix(raw[kolom_hb]))
      )
    ) {
      stop("Terdapat nilai Hb tak hingga.")
    }

    dat_wide <<- data.frame(
      id = factor(raw[["ID"]]),
      kelompok = factor(
        kel,
        levels = level_kelompok
      ),
      usia = raw[["Umur"]],
      pendidikan = factor(raw[["Pendidikan"]]),
      Hb_M0 = raw[[kolom_hb[1]]],
      Hb_M1 = raw[[kolom_hb[2]]],
      Hb_M2 = raw[[kolom_hb[3]]],
      Hb_M3 = raw[[kolom_hb[4]]]
    )

    hb_names <<- c(
      "Hb_M0", "Hb_M1", "Hb_M2", "Hb_M3"
    )

    dat_wide$lengkap <- complete.cases(
      dat_wide[hb_names]
    )

    dat_long <<- dat_wide |>
      pivot_longer(
        all_of(hb_names),
        names_to = "waktu",
        values_to = "hb"
      ) |>
      mutate(
        waktu = factor(
          waktu,
          levels = hb_names,
          labels = label_waktu
        ),
        minggu = minggu_nilai[
          as.integer(waktu)
        ]
      ) |>
      arrange(id, waktu)

    wide_cc <<- droplevels(
      dat_wide[dat_wide$lengkap, ]
    )

    long_cc <<- droplevels(
      filter(dat_long, lengkap)
    )

    long_obs <<- droplevels(
      filter(dat_long, !is.na(hb))
    )

    d1 <<- droplevels(
      filter(
        long_cc,
        kelompok == KELOMPOK_FOKUS
      )
    )

    if (
      nrow(wide_cc) < 10 ||
      n_distinct(d1$id) < 4
    ) {
      stop("Peserta lengkap terlalu sedikit.")
    }

    write.csv(
      dat_wide,
      file.path(folder, "data_wide.csv"),
      row.names = FALSE,
      na = ""
    )

    write.csv(
      dat_long,
      file.path(folder, "data_long.csv"),
      row.names = FALSE,
      na = ""
    )

    write.csv(
      wide_cc,
      file.path(folder, "data_complete_case.csv"),
      row.names = FALSE,
      na = ""
    )

    message(
      "Data berhasil dibaca: ", nrow(dat_wide),
      " responden; ", n_distinct(dat_wide$kelompok),
      " kelompok; ", nrow(long_obs),
      " pengukuran tersedia."
    )

    narasi(
      paste(
        "Dataset simulasi terdiri dari",
        nrow(dat_wide),
        "responden dan",
        n_distinct(dat_wide$kelompok),
        "kelompok.",
        "Setiap responden memiliki pengukuran Hb pada minggu 0, 1, 2, dan 3."
      )
    )

    narasi(
      paste(
        nrow(wide_cc),
        "responden memiliki data lengkap untuk keempat waktu."
      )
    )

    tabel(
      dat_long |>
        group_by(kelompok, waktu) |>
        summarise(
          n_total = n(),
          n_tersedia = sum(!is.na(hb)),
          n_hilang = sum(is.na(hb)),
          .groups = "drop"
        ),
      "01_kelengkapan"
    )

    tabel(
      dat_wide |>
        group_by(kelompok) |>
        summarise(
          n_total = n(),
          n_lengkap = sum(lengkap),
          n_tidak_lengkap = sum(!lengkap),
          .groups = "drop"
        ),
      "01_peserta"
    )
  })

  # ==================== 2. DESKRIPTIF & VISUALISASI ==================
  bagian("2. Statistik deskriptif dan visualisasi", function() {

    desk <- function(d) {
      d |>
        group_by(kelompok, waktu) |>
        summarise(
          n = n(),
          mean = mean(hb, na.rm = TRUE),
          sd = sd(hb, na.rm = TRUE),
          median = median(hb, na.rm = TRUE),
          min = min(hb, na.rm = TRUE),
          max = max(hb, na.rm = TRUE),
          se = sd / sqrt(n),
          lower_ci = mean - qt(.975, n - 1) * se,
          upper_ci = mean + qt(.975, n - 1) * se,
          .groups = "drop"
        )
    }

    tabel(
      desk(long_obs),
      "02_deskriptif_semua_tersedia"
    )

    tabel(
      desk(long_cc),
      "02_deskriptif_complete_case"
    )

    # Perubahan baseline ke minggu 3
    perubahan <- wide_cc |>
      mutate(
        perubahan_M3_M0 = Hb_M3 - Hb_M0
      ) |>
      group_by(kelompok) |>
      summarise(
        n = n(),
        mean_perubahan = mean(
          perubahan_M3_M0
        ),
        sd_perubahan = sd(
          perubahan_M3_M0
        ),
        median_perubahan = median(
          perubahan_M3_M0
        ),
        min_perubahan = min(
          perubahan_M3_M0
        ),
        max_perubahan = max(
          perubahan_M3_M0
        ),
        .groups = "drop"
      )

    tabel(
      perubahan,
      "02_perubahan_baseline_minggu3"
    )

    p1 <- ggplot(
      long_obs,
      aes(
        x = minggu,
        y = hb,
        colour = kelompok,
        group = kelompok
      )
    ) +
      stat_summary(
        fun = mean,
        geom = "line",
        linewidth = 1
      ) +
      stat_summary(
        fun = mean,
        geom = "point",
        size = 2
      ) +
      stat_summary(
        fun.data = mean_cl_normal,
        geom = "errorbar",
        width = .15
      ) +
      scale_x_continuous(
        breaks = minggu_nilai
      ) +
      theme_bw(base_size = 12) +
      theme(
        legend.position = "bottom"
      ) +
      labs(
        title = "Profil Rerata Hb Menurut Kelompok dan Waktu",
        x = "Minggu",
        y = "Hb (g/dL)",
        colour = "Kelompok"
      )

    gambar(
      p1,
      "02_profil_hb",
      10,
      6
    )

    p2 <- ggplot(
      long_cc,
      aes(
        x = minggu,
        y = hb,
        group = id
      )
    ) +
      geom_line(alpha = .15) +
      stat_summary(
        aes(group = kelompok),
        fun = mean,
        geom = "line",
        colour = "firebrick",
        linewidth = 1.1
      ) +
      facet_wrap(~kelompok) +
      scale_x_continuous(
        breaks = minggu_nilai
      ) +
      theme_bw() +
      labs(
        title = "Lintasan Individu Hb: Peserta Lengkap",
        x = "Minggu",
        y = "Hb (g/dL)"
      )

    gambar(
      p2,
      "02_lintasan_individu",
      11,
      7
    )
  })

  # ============================ 3. ASUMSI =============================
  bagian("3. Pemeriksaan asumsi pada peserta lengkap", function() {

    tabel(
      long_cc |>
        group_by(kelompok, waktu) |>
        identify_outliers(hb),
      "03_outlier"
    )

    tabel(
      long_cc |>
        group_by(kelompok, waktu) |>
        shapiro_test(hb),
      "03_shapiro"
    )

    gambar(
      ggpubr::ggqqplot(
        long_cc,
        "hb",
        facet.by = c("kelompok", "waktu")
      ),
      "03_qq_per_sel",
      12,
      9
    )

    tabel(
      long_cc |>
        group_by(waktu) |>
        levene_test(hb ~ kelompok),
      "03_levene"
    )

    # Box's M untuk kovarians antar waktu
    tabel(
      rstatix::box_m(
        wide_cc[c("Hb_M0", "Hb_M1", "Hb_M2", "Hb_M3")],
        wide_cc$kelompok
      ),
      "03_box_m"
    )

    narasi(
      paste(
        "Interpretasi uji asumsi harus mempertimbangkan ukuran sampel,",
        "Q-Q plot, outlier, dan konteks desain.",
        "Nilai p > 0,05 bukan bukti mutlak bahwa asumsi terpenuhi."
      )
    )
  })

  # ======================== 4. RM ANOVA FOKUS =========================
  aov1 <- NULL
  aov2 <- NULL

  bagian("4. RM ANOVA satu arah: Kelompok Teh Daun Kelor", function() {

    narasi(
      paste(
        "Kelompok fokus:",
        KELOMPOK_FOKUS,
        "—",
        n_distinct(d1$id),
        "peserta lengkap."
      )
    )

    gambar(
      ggpubr::ggqqplot(
        d1,
        "hb",
        facet.by = "waktu"
      ) +
        labs(
          title = "Q-Q Hb per Waktu: Kelompok Teh Daun Kelor"
        ),
      "04_qq_kelompok_fokus",
      10,
      6
    )

    output(
      rstatix::anova_test(
        data = d1,
        dv = hb,
        wid = id,
        within = waktu,
        effect.size = "pes"
      )
    )

    aov1 <<- afex::aov_ez(
      id = "id",
      dv = "hb",
      data = d1,
      within = "waktu",
      anova_table = list(
        es = c("ges", "pes"),
        correction = "GG"
      )
    )

    output(aov1)
    output(summary(aov1))
    output(aov1$Anova)

    tabel(
      as.data.frame(
        aov1$anova_table
      ) |>
        tibble::rownames_to_column("efek"),
      "04_anova_rm_gg"
    )

    output(
      effectsize::eta_squared(
        aov1,
        partial = TRUE
      )
    )

    p <- as.numeric(
      aov1$anova_table[
        1,
        "Pr(>F)"
      ]
    )

    narasi(
      paste0(
        "Efek waktu dengan koreksi Greenhouse-Geisser: p ",
        fp(p),
        ". "
      )
    )
  })

  # ======================= 5. POST HOC WAKTU ==========================
  bagian("5. Post hoc perubahan waktu dalam kelompok Teh Daun Kelor", function() {

    if (is.null(aov1))
      stop("Model RM ANOVA belum tersedia.")

    em <- emmeans::emmeans(
      aov1,
      ~ waktu,
      model = "multivariate"
    )

    tabel(
      summary(em),
      "05_emmeans_waktu"
    )

    tabel(
      summary(
        pairs(
          em,
          adjust = "bonferroni"
        ),
        infer = c(TRUE, TRUE)
      ),
      "05_pasangan_waktu_bonferroni"
    )

    tabel(
      summary(
        contrast(
          em,
          "trt.vs.ctrl",
          ref = 1,
          adjust = "holm"
        ),
        infer = c(TRUE, TRUE)
      ),
      "05_vs_baseline_holm"
    )

    # Dengan 4 waktu (0,1,2,3), tren dapat mencakup linear, kuadratik, dan kubik.
    pol <- poly(
      minggu_nilai,
      degree = 3
    )

    koef <- list(
      linear_minggu = pol[, 1],
      kuadratik_minggu = pol[, 2],
      kubik_minggu = pol[, 3]
    )

    tabel(
      summary(
        contrast(
          em,
          method = koef,
          adjust = "holm"
        ),
        infer = c(TRUE, TRUE)
      ),
      "05_tren_waktu"
    )

    narasi(
      paste(
        "Post hoc digunakan untuk mengetahui pasangan waktu yang berbeda",
        "setelah efek waktu diuji pada RM ANOVA.",
        "Koreksi Bonferroni digunakan untuk pasangan waktu."
      )
    )
  })

  # ====================== 6. FRIEDMAN + WILCOXON ======================
  bagian("6. Pembanding nonparametrik: Friedman dan Wilcoxon", function() {

    tabel(
      rstatix::friedman_test(
        d1,
        hb ~ waktu | id
      ),
      "06_friedman"
    )

    tabel(
      rstatix::friedman_effsize(
        d1,
        hb ~ waktu | id
      ),
      "06_kendall_w"
    )

    w <- wide_cc[
      wide_cc$kelompok == KELOMPOK_FOKUS,
    ]

    hb_names <<- c(
      "Hb_M0",
      "Hb_M1",
      "Hb_M2",
      "Hb_M3"
    )

    ij <- combn(
      seq_along(hb_names),
      2
    )

    hasil <- lapply(
      seq_len(ncol(ij)),
      function(j) {

        a <- ij[1, j]
        b <- ij[2, j]

        wt <- wilcox.test(
          w[[hb_names[a]]],
          w[[hb_names[b]]],
          paired = TRUE,
          exact = FALSE
        )

        data.frame(
          waktu_1 = c(
            "M0", "M0", "M0",
            "M1", "M1",
            "M2"
          )[j],
          waktu_2 = c(
            "M1", "M2", "M3",
            "M2", "M3",
            "M3"
          )[j],
          n_pasangan = nrow(w),
          V = unname(wt$statistic),
          p = wt$p.value
        )
      }
    ) |>
      bind_rows() |>
      mutate(
        p_bonferroni = p.adjust(
          p,
          "bonferroni"
        )
      )

    tabel(
      hasil,
      "06_wilcoxon"
    )

    narasi(
      paste(
        "Friedman menguji perubahan Hb antarwaktu dalam satu kelompok",
        "secara nonparametrik. Wilcoxon signed-rank digunakan untuk",
        "perbandingan pasangan waktu."
      )
    )
  })

  # ======================= 7. MIXED ANOVA =============================
  bagian("7. Mixed Design ANOVA: Kelompok × Waktu", function() {

    aov2 <<- afex::aov_ez(
      id = "id",
      dv = "hb",
      data = long_cc,
      between = "kelompok",
      within = "waktu",
      anova_table = list(
        es = c("ges", "pes"),
        correction = "GG"
      )
    )

    output(aov2)
    output(summary(aov2))
    output(aov2$Anova)

    tabel(
      as.data.frame(
        aov2$anova_table
      ) |>
        tibble::rownames_to_column("efek"),
      "07_mixed_anova_gg"
    )

    output(
      effectsize::eta_squared(
        aov2,
        partial = TRUE
      )
    )

    ringkas_interaksi(
      aov2$anova_table,
      "Pr(>F)",
      "Mixed Design ANOVA"
    )
  })

  # =================== 8. GRAFIK INTERAKSI ===========================
  bagian("8. Visualisasi interaksi Kelompok × Waktu", function() {

    if (is.null(aov2))
      stop("Mixed ANOVA belum tersedia.")

    gambar(
      afex::afex_plot(
        aov2,
        x = "waktu",
        trace = "kelompok",
        error = "within",
        mapping = c(
          "colour",
          "shape",
          "linetype"
        )
      ) +
        labs(
          title = "Mixed Design ANOVA: Kelompok × Waktu",
          x = "Waktu",
          y = "Hb (g/dL)"
        ),
      "08_interaksi_anova",
      10,
      6
    )
  })

  # ==================== 9. EFEK SEDERHANA =============================
  bagian("9. Efek sederhana dan post hoc antarkelompok", function() {

    if (is.null(aov2))
      stop("Mixed ANOVA belum tersedia.")

    jt1 <- as.data.frame(
      joint_tests(
        aov2,
        by = "kelompok",
        model = "multivariate"
      )
    )

    jt1$p_holm <- p.adjust(
      jt1$p.value,
      "holm"
    )

    tabel(
      jt1,
      "09_efek_waktu_per_kelompok"
    )

    jt2 <- as.data.frame(
      joint_tests(
        aov2,
        by = "waktu",
        model = "multivariate"
      )
    )

    jt2$p_holm <- p.adjust(
      jt2$p.value,
      "holm"
    )

    tabel(
      jt2,
      "09_efek_kelompok_per_waktu"
    )

    ew <- emmeans(
      aov2,
      ~ waktu | kelompok,
      model = "multivariate"
    )

    tabel(
      summary(
        contrast(
          ew,
          "trt.vs.ctrl",
          ref = 1,
          adjust = "holm"
        ),
        infer = c(TRUE, TRUE)
      ),
      "09_perubahan_vs_baseline"
    )

    ek <- emmeans(
      aov2,
      ~ kelompok | waktu,
      model = "multivariate"
    )

    tabel(
      summary(
        pairs(
          ek,
          adjust = "tukey"
        ),
        infer = c(TRUE, TRUE)
      ),
      "09_kelompok_per_waktu"
    )
  })

  # =================== 10. KONTRAS INTERAKSI ==========================
  bagian("10. Kontras perubahan baseline–minggu 3 dan tren", function() {

    if (is.null(aov2))
      stop("Mixed ANOVA belum tersedia.")

    e <- emmeans(
      aov2,
      ~ waktu * kelompok,
      model = "multivariate"
    )

    perubahan <- contrast(
      e,
      interaction = list(
        waktu = list(
          "M3-M0" = c(-1, 0, 0, 1)
        ),
        kelompok = "pairwise"
      ),
      adjust = "holm"
    )

    tabel(
      summary(
        perubahan,
        infer = c(TRUE, TRUE)
      ),
      "10_selisih_perubahan_M3_M0"
    )

    # Kontras tren linear
    lin <- poly(
      minggu_nilai,
      degree = 3
    )[, 1]

    tren <- contrast(
      e,
      interaction = list(
        waktu = list(
          linear_minggu = lin
        ),
        kelompok = "pairwise"
      ),
      adjust = "holm"
    )

    tabel(
      summary(
        tren,
        infer = c(TRUE, TRUE)
      ),
      "10_tren_linear_interaksi"
    )

    narasi(
      paste(
        "Kontras M3-M0 membandingkan besar perubahan Hb dari baseline",
        "hingga minggu ke-3 antarkelompok.",
        "Kontras tren linear membandingkan pola kenaikan Hb sepanjang waktu."
      )
    )
  })

  # ======================== 11. LMM ===================================
  lmm <- NULL
  lmm_ri <- NULL
  lmm_rs <- NULL

  bagian("11. Linear Mixed Model (LMM)", function() {

    # Random intercept
    lmm_ri <<- lmerTest::lmer(
      hb ~ kelompok * waktu + (1 | id),
      data = long_obs,
      REML = TRUE,
      control = lmerControl(
        optimizer = "bobyqa"
      )
    )

    # Random slope menggunakan waktu numerik
    lmm_rs <<- tryCatch(

      lmerTest::lmer(
        hb ~ kelompok * waktu +
          (1 + minggu | id),
        data = long_obs,
        REML = TRUE,
        control = lmerControl(
          optimizer = "bobyqa",
          optCtrl = list(
            maxfun = 200000
          )
        )
      ),

      error = function(e) {
        narasi(
          paste(
            "Random slope gagal diestimasi;",
            "model random intercept digunakan.",
            conditionMessage(e)
          )
        )
        NULL
      }
    )

    info_model <- function(m, nama) {

      data.frame(
        model = nama,
        n_observasi = nobs(m),
        AIC = AIC(m),
        BIC = BIC(m),
        singular = lme4::isSingular(m),
        konvergensi = paste(
          m@optinfo$conv$lme4$messages,
          collapse = "; "
        )
      )
    }

    info_ri <- info_model(
      lmm_ri,
      "random_intercept"
    )

    info_rs <- if (!is.null(lmm_rs)) {
      info_model(
        lmm_rs,
        "random_intercept_slope"
      )
    } else {
      NULL
    }

    tabel(
      bind_rows(
        info_ri,
        info_rs
      ),
      "11_perbandingan_model"
    )

    layak <- !is.null(lmm_rs) &&
      !isSingular(lmm_rs) &&
      is.null(lmm_rs@optinfo$conv$lme4$messages)

    pakai_rs <- layak &&
      AIC(lmm_rs) < AIC(lmm_ri)

    lmm <<- if (pakai_rs) {
      lmm_rs
    } else {
      lmm_ri
    }

    narasi(
      paste(
        "Model yang dipakai:",
        if (pakai_rs)
          "random intercept + random slope minggu"
        else
          "random intercept"
      )
    )

    output(
      summary(lmm)
    )

    output(
      VarCorr(lmm)
    )

    hasil <- anova(
      lmm,
      type = 3,
      ddf = "Kenward-Roger"
    )

    tabel(
      as.data.frame(hasil) |>
        tibble::rownames_to_column("efek"),
      "11_lmm_kr"
    )

    ringkas_interaksi(
      hasil,
      "Pr(>F)",
      "LMM"
    )

    output(
      performance::icc(lmm_ri)
    )

    e <- emmeans(
      lmm,
      ~ waktu * kelompok,
      lmer.df = "kenward-roger"
    )

    tabel(
      summary(
        contrast(
          e,
          interaction = list(
            waktu = list(
              "M3-M0" = c(-1, 0, 0, 1)
            ),
            kelompok = "pairwise"
          ),
          adjust = "holm"
        ),
        infer = c(TRUE, TRUE)
      ),
      "11_lmm_selisih_perubahan"
    )

    tabel(
      summary(
        emmeans(
          lmm,
          ~ kelompok | waktu,
          lmer.df = "kenward-roger"
        )
      ),
      "11_lmm_rerata_model"
    )
  })

  # ======================== 12. DIAGNOSTIK LMM ========================
  bagian("12. Diagnostik LMM", function() {

    if (is.null(lmm))
      stop("LMM belum tersedia.")

    diag <- data.frame(
      fitted = fitted(lmm),
      residual = resid(lmm),
      kelompok = long_obs$kelompok,
      waktu = long_obs$waktu
    )

    gambar(
      ggplot(
        diag,
        aes(sample = residual)
      ) +
        stat_qq() +
        stat_qq_line() +
        theme_bw() +
        labs(
          title = "Q-Q Residual LMM"
        ),
      "12_qq_residual"
    )

    gambar(
      ggplot(
        diag,
        aes(
          fitted,
          residual,
          colour = kelompok
        )
      ) +
        geom_point(alpha = .35) +
        geom_hline(
          yintercept = 0,
          linetype = 2
        ) +
        theme_bw() +
        labs(
          x = "Nilai prediksi",
          y = "Residual",
          title = "Residual terhadap Prediksi"
        ),
      "12_residual_prediksi"
    )

    gambar(
      ggplot(
        diag,
        aes(
          waktu,
          residual,
          fill = kelompok
        )
      ) +
        geom_boxplot() +
        theme_bw() +
        labs(
          title = "Residual menurut Kelompok dan Waktu"
        ),
      "12_residual_per_sel"
    )

    output(
      performance::check_singularity(lmm)
    )

    output(
      performance::check_convergence(lmm)
    )

    narasi(
      paste(
        "Diagnostik digunakan untuk menilai residual, outlier,",
        "singularitas, dan konvergensi model."
      )
    )
  })

  # ================= 13. GRAFIK PREDIKSI LMM ==========================
  bagian("13. Grafik rerata prediksi LMM", function() {

    if (is.null(lmm))
      stop("LMM belum tersedia.")

    pred <- as.data.frame(
      summary(
        emmeans(
          lmm,
          ~ kelompok | waktu,
          lmer.df = "kenward-roger"
        )
      )
    )

    pred$minggu <- minggu_nilai[
      as.integer(pred$waktu)
    ]

    gambar(
      ggplot(
        pred,
        aes(
          minggu,
          emmean,
          colour = kelompok,
          group = kelompok
        )
      ) +
        geom_line(linewidth = 1) +
        geom_point(size = 2.5) +
        geom_errorbar(
          aes(
            ymin = lower.CL,
            ymax = upper.CL
          ),
          width = .12
        ) +
        scale_x_continuous(
          breaks = minggu_nilai
        ) +
        theme_bw(base_size = 12) +
        theme(
          legend.position = "bottom"
        ) +
        labs(
          title = "Rerata Prediksi LMM dan 95% CI",
          x = "Minggu",
          y = "Hb (g/dL)",
          colour = "Kelompok"
        ),
      "13_profil_prediksi_lmm",
      10,
      6
    )
  })

  # =============== 14. LMM COMPLETE CASE PEMBANDING ==================
  bagian("14. LMM pada peserta lengkap: pembanding ANOVA", function() {

    if (is.null(lmm))
      stop("LMM belum tersedia.")

    mcc <- update(
      lmm,
      data = long_cc
    )

    output(
      summary(mcc)
    )

    tab <- anova(
      mcc,
      type = 3,
      ddf = "Kenward-Roger"
    )

    tabel(
      as.data.frame(tab) |>
        tibble::rownames_to_column("efek"),
      "14_lmm_complete_case"
    )

    ringkas_interaksi(
      tab,
      "Pr(>F)",
      "LMM peserta lengkap"
    )

    narasi(
      paste(
        "Karena data simulasi tidak memiliki missing value,",
        "hasil LMM seluruh pengukuran dan complete case diharapkan",
        "sangat mirip."
      )
    )
  })

  # ===================== 15. INFORMASI & BATAS ========================
  bagian("15. Informasi sesi dan batas interpretasi", function() {

    narasi(
      paste(
        "Taraf signifikansi ditetapkan pada α = 0,05.",
        "Interpretasi mempertimbangkan nilai p, ukuran efek,",
        "interval kepercayaan, dan arah perubahan."
      )
    )

    narasi(
      paste(
        "DATA INI ADALAH DATA SIMULASI.",
        "Kesamaan dengan angka jurnal hanya bersifat agregat.",
        "Hasil p-value dari data simulasi tidak boleh diklaim sebagai",
        "hasil analisis ulang data asli penelitian."
      )
    )

    output(
      sessionInfo()
    )
  })

  # ======================= 16. SIMPAN LAPORAN =========================
  tambah("<h2>Status setiap bagian</h2>")

  tabel(
    status,
    "status_analisis"
  )

  tambah(
    "<details><summary>Catatan penggunaan</summary>"
  )

  narasi(
    paste(
      "Letakkan file Excel dan script R dalam folder yang sama.",
      "Kemudian jalankan seluruh script.",
      "Folder hasil akan dibuat otomatis di samping file Excel."
    )
  )

  tambah("</details>")

  css <- paste0(
    "body{font:16px/1.6 Arial,sans-serif;",
    "max-width:1100px;margin:40px auto;padding:0 24px;",
    "color:#18332e}",
    "h1,h2{color:#0b6b4f}",
    "h2{border-top:1px solid #d9e4e0;padding-top:24px}",
    "pre{background:#f0f5f3;padding:16px;overflow:auto;",
    "font-size:13px;color:#182822}",
    ".table{overflow:auto}",
    "table{border-collapse:collapse;font-size:13px;width:100%}",
    "td,th{border:1px solid #d9e4e0;padding:8px;text-align:left}",
    "th{background:#e7f2ee}",
    "img{max-width:100%}",
    "summary{cursor:pointer;font-weight:bold}"
  )

  selesai <- sum(
    status$status == "Selesai"
  )

  header <- paste0(
    "<!doctype html><html lang='id'><head>",
    "<meta charset='UTF-8'>",
    "<meta name='viewport' content='width=device-width,initial-scale=1'>",
    "<title>Analisis Hb Teh Daun Kelor — Pengukuran Berulang</title>",
    "<style>", css, "</style></head><body>",
    "<h1>Analisis Pengukuran Berulang: Hemoglobin</h1>",
    "<table class='identitas'><tbody>",
    "<tr><th>Nama</th><td>Fadillah Hana Hafifah</td></tr>",
    "<tr><th>NIM</th><td>2611018008</td></tr>",
    "<tr><th>Rpubs</th><td>Dilla01</td></tr>",
    "<tr><th>Mata Kuliah</th><td>Biostatistika Intermediete</td></tr>",
    "<tr><th>Program Studi / Institusi</th>",
    "<td>Magister Kesehatan Masyarakat Universitas Mulawarman</td></tr>",
    "</tbody></table>",
    "<p>Data simulasi · 3 kelompok × 4 waktu (minggu 0–3)</p>",
    "<p>Dibuat: ",
    escape(format(Sys.time())),
    " · Bagian selesai: ",
    selesai,
    "/",
    nrow(status),
    "</p>"
  )

  path_html <- file.path(
    folder,
    "laporan_analisis_hb_teh_daun_kelor.html"
  )

  writeLines(
    c(
      header,
      isi,
      "</body></html>"
    ),
    path_html,
    useBytes = TRUE
  )

  saveRDS(
    list(
      data_wide = dat_wide,
      data_long = dat_long,
      aov_satu = aov1,
      aov_campuran = aov2,
      lmm = lmm,
      status = status
    ),
    file.path(
      folder,
      "objek_analisis_hb.rds"
    )
  )

  writeLines(
    capture.output(sessionInfo()),
    file.path(
      folder,
      "sessionInfo.txt"
    )
  )

  message(
    "\nLaporan tersedia: ",
    path_html,
    "\nDurasi: ",
    round(
      as.numeric(
        difftime(
          Sys.time(),
          waktu_mulai,
          units = "secs"
        )
      ),
      1
    ),
    " detik."
  )

  if (
    any(status$status == "Gagal")
  ) {
    message(
      "Terdapat bagian analisis yang gagal."
    )
  }

  if (
    BUKA_HTML_OTOMATIS &&
    interactive()
  ) {
    try(
      utils::browseURL(path_html),
      silent = TRUE
    )
  }

  invisible(
    list(
      folder = folder,
      status = status
    )
  )
}

# ======================= EKSEKUSI ANALISIS =============================
hasil_analisis <- jalankan_analisis()
## Registered S3 method overwritten by 'lme4':
##   method           from
##   na.action.merMod car
## Data: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/dtdaunkelor.xlsx
## Hasil: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor
## 
## >>> 1. Sumber, desain, dan kelengkapan data
## Data berhasil dibaca: 141 responden; 3 kelompok; 564 pengukuran tersedia.
##          kelompok waktu n_total n_tersedia n_hilang
## 1  Kapsul Gelatin    M0      47         47        0
## 2  Kapsul Gelatin    M1      47         47        0
## 3  Kapsul Gelatin    M2      47         47        0
## 4  Kapsul Gelatin    M3      47         47        0
## 5  Teh Daun Kelor    M0      47         47        0
## 6  Teh Daun Kelor    M1      47         47        0
## 7  Teh Daun Kelor    M2      47         47        0
## 8  Teh Daun Kelor    M3      47         47        0
## 9       Tablet Fe    M0      47         47        0
## 10      Tablet Fe    M1      47         47        0
## 11      Tablet Fe    M2      47         47        0
## 12      Tablet Fe    M3      47         47        0
##         kelompok n_total n_lengkap n_tidak_lengkap
## 1 Kapsul Gelatin      47        47               0
## 2 Teh Daun Kelor      47        47               0
## 3      Tablet Fe      47        47               0
## 
## >>> 2. Statistik deskriptif dan visualisasi
##          kelompok waktu  n  mean    sd   median  min  max         se lower_ci
## 1  Kapsul Gelatin    M0 47 11.05 0.379 11.06951 10.3 11.8 0.05528283 10.93872
## 2  Kapsul Gelatin    M1 47 11.24 0.295 11.26123 10.5 11.7 0.04303017 11.15338
## 3  Kapsul Gelatin    M2 47 11.27 0.278 11.28898 10.5 11.8 0.04055047 11.18838
## 4  Kapsul Gelatin    M3 47 11.46 0.316 11.49054 10.3 11.9 0.04609334 11.36722
## 5  Teh Daun Kelor    M0 47 10.93 0.363 11.00338 10.1 11.5 0.05294899 10.82342
## 6  Teh Daun Kelor    M1 47 11.27 0.307 11.32588 10.7 11.9 0.04478055 11.17986
## 7  Teh Daun Kelor    M2 47 11.78 0.404 11.85093 11.0 12.7 0.05892946 11.66138
## 8  Teh Daun Kelor    M3 47 12.20 0.500 12.28486 11.3 13.4 0.07293250 12.05319
## 9       Tablet Fe    M0 47 10.90 0.316 10.90760 10.3 11.5 0.04609334 10.80722
## 10      Tablet Fe    M1 47 11.20 0.227 11.20937 10.5 11.7 0.03311135 11.13335
## 11      Tablet Fe    M2 47 12.04 0.465 12.05734 11.0 12.8 0.06782722 11.90347
## 12      Tablet Fe    M3 47 12.51 0.543 12.52776 11.3 13.5 0.07920469 12.35057
##    upper_ci
## 1  11.16128
## 2  11.32662
## 3  11.35162
## 4  11.55278
## 5  11.03658
## 6  11.36014
## 7  11.89862
## 8  12.34681
## 9  10.99278
## 10 11.26665
## 11 12.17653
## 12 12.66943
##          kelompok waktu  n  mean    sd   median  min  max         se lower_ci
## 1  Kapsul Gelatin    M0 47 11.05 0.379 11.06951 10.3 11.8 0.05528283 10.93872
## 2  Kapsul Gelatin    M1 47 11.24 0.295 11.26123 10.5 11.7 0.04303017 11.15338
## 3  Kapsul Gelatin    M2 47 11.27 0.278 11.28898 10.5 11.8 0.04055047 11.18838
## 4  Kapsul Gelatin    M3 47 11.46 0.316 11.49054 10.3 11.9 0.04609334 11.36722
## 5  Teh Daun Kelor    M0 47 10.93 0.363 11.00338 10.1 11.5 0.05294899 10.82342
## 6  Teh Daun Kelor    M1 47 11.27 0.307 11.32588 10.7 11.9 0.04478055 11.17986
## 7  Teh Daun Kelor    M2 47 11.78 0.404 11.85093 11.0 12.7 0.05892946 11.66138
## 8  Teh Daun Kelor    M3 47 12.20 0.500 12.28486 11.3 13.4 0.07293250 12.05319
## 9       Tablet Fe    M0 47 10.90 0.316 10.90760 10.3 11.5 0.04609334 10.80722
## 10      Tablet Fe    M1 47 11.20 0.227 11.20937 10.5 11.7 0.03311135 11.13335
## 11      Tablet Fe    M2 47 12.04 0.465 12.05734 11.0 12.8 0.06782722 11.90347
## 12      Tablet Fe    M3 47 12.51 0.543 12.52776 11.3 13.5 0.07920469 12.35057
##    upper_ci
## 1  11.16128
## 2  11.32662
## 3  11.35162
## 4  11.55278
## 5  11.03658
## 6  11.36014
## 7  11.89862
## 8  12.34681
## 9  10.99278
## 10 11.26665
## 11 12.17653
## 12 12.66943
##         kelompok  n mean_perubahan sd_perubahan median_perubahan min_perubahan
## 1 Kapsul Gelatin 47           0.41    0.1172426         0.415633      0.000000
## 2 Teh Daun Kelor 47           1.27    0.1503855         1.281473      1.036458
## 3      Tablet Fe 47           1.61    0.2280302         1.620164      1.000000
##   max_perubahan
## 1     0.6154056
## 2     1.9000000
## 3     2.0000000

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/02_profil_hb.png

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/02_lintasan_individu.png
## 
## >>> 3. Pemeriksaan asumsi pada peserta lengkap
##         kelompok waktu   id usia pendidikan lengkap   hb minggu is.outlier
## 1 Kapsul Gelatin    M3 R106   33    SMA/SMK    TRUE 10.3      3       TRUE
## 2      Tablet Fe    M1 R089   32      D4/S1    TRUE 10.5      1       TRUE
##   is.extreme
## 1      FALSE
## 2      FALSE
##          kelompok waktu variable statistic           p
## 1  Kapsul Gelatin    M0       hb 0.9773596 0.487982942
## 2  Kapsul Gelatin    M1       hb 0.9703362 0.272842746
## 3  Kapsul Gelatin    M2       hb 0.9802160 0.601192396
## 4  Kapsul Gelatin    M3       hb 0.9292456 0.007116373
## 5  Teh Daun Kelor    M0       hb 0.9601496 0.109067227
## 6  Teh Daun Kelor    M1       hb 0.9664581 0.193433092
## 7  Teh Daun Kelor    M2       hb 0.9722968 0.323138287
## 8  Teh Daun Kelor    M3       hb 0.9696043 0.255901827
## 9       Tablet Fe    M0       hb 0.9739478 0.371312517
## 10      Tablet Fe    M1       hb 0.9784597 0.530174897
## 11      Tablet Fe    M2       hb 0.9721565 0.319291533
## 12      Tablet Fe    M3       hb 0.9786255 0.536704387

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/03_qq_per_sel.png
##   waktu df1 df2 statistic            p
## 1    M0   2 138 0.8943447 0.4112317939
## 2    M1   2 138 3.3835326 0.0367656964
## 3    M2   2 138 7.1936276 0.0010670883
## 4    M3   2 138 8.7860576 0.0002560742
##   statistic p.value parameter
## 1       NaN     NaN        20
##                                                method
## 1 Box's M-test for Homogeneity of Covariance Matrices
## 
## >>> 4. RM ANOVA satu arah: Kelompok Teh Daun Kelor

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/04_qq_kelompok_fokus.png
## ANOVA Table (type III tests)
## 
## $ANOVA
##   Effect DFn DFd        F         p p<.05   pes
## 1  waktu   3 138 2020.991 8.74e-114     * 0.978
## 
## $`Mauchly's Test for Sphericity`
##   Effect     W        p p<.05
## 1  waktu 0.001 1.48e-60     *
## 
## $`Sphericity Corrections`
##   Effect  GGe      DF[GG]    p[GG] p[GG]<.05   HFe      DF[HF]    p[HF]
## 1  waktu 0.37 1.11, 51.11 8.75e-44         * 0.373 1.12, 51.46 4.53e-44
##   p[HF]<.05
## 1         *
##  
## Anova Table (Type 3 tests)
## 
## Response: hb
##   Effect          df  MSE           F  ges  pes p.value
## 1  waktu 1.11, 51.11 0.02 2020.99 *** .600 .978   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG  
## 
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
## 
##              Sum Sq num Df Error SS den Df F value    Pr(>F)    
## (Intercept) 25058.0      1  28.4012     46   40585 < 2.2e-16 ***
## waktu          44.1      3   1.0036    138    2021 < 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.0014991 1.4824e-60
## 
## 
## Greenhouse-Geisser and Huynh-Feldt Corrections
##  for Departure from Sphericity
## 
##        GG eps Pr(>F[GG])    
## waktu 0.37035  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##          HF eps   Pr(>F[HF])
## waktu 0.3729157 4.531419e-44 
## 
## Type III Repeated Measures MANOVA Tests: Pillai test statistic
##             Df test stat approx F num Df den Df    Pr(>F)    
## (Intercept)  1   0.99887    40585      1     46 < 2.2e-16 ***
## waktu        1   0.99782     6709      3     44 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
##    efek   num Df   den Df        MSE        F       pes       ges       Pr(>F)
## 1 waktu 1.111051 51.10833 0.01963581 2020.991 0.9777454 0.5999105 8.746663e-44
## # Effect Size for ANOVA (Type III)
## 
## Parameter | Eta2 (partial) |       95% CI
## -----------------------------------------
## waktu     |           0.98 | [0.97, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
## 
## >>> 5. Post hoc perubahan waktu dalam kelompok Teh Daun Kelor
##  waktu emmean         SE df lower.CL upper.CL
##  M0     10.93 0.05294899 46 10.82342 11.03658
##  M1     11.27 0.04478055 46 11.17986 11.36014
##  M2     11.78 0.05892946 46 11.66138 11.89862
##  M3     12.20 0.07293250 46 12.05320 12.34680
## 
## Confidence level used: 0.95 
##  contrast estimate          SE df   lower.CL   upper.CL t.ratio p.value
##  M0 - M1     -0.34 0.009442873 46 -0.3660356 -0.3139644 -36.006 <0.0001
##  M0 - M2     -0.85 0.008978829 46 -0.8747562 -0.8252438 -94.667 <0.0001
##  M0 - M3     -1.27 0.021935980 46 -1.3304813 -1.2095187 -57.896 <0.0001
##  M1 - M2     -0.51 0.014284348 46 -0.5493844 -0.4706156 -35.703 <0.0001
##  M1 - M3     -0.93 0.028327865 46 -1.0081049 -0.8518951 -32.830 <0.0001
##  M2 - M3     -0.42 0.014114816 46 -0.4589170 -0.3810830 -29.756 <0.0001
## 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 6 estimates 
## P value adjustment: bonferroni method for 6 tests 
##  contrast estimate          SE df  lower.CL  upper.CL t.ratio p.value
##  M1 - M0      0.34 0.009442873 46 0.3165374 0.3634626  36.006 <0.0001
##  M2 - M0      0.85 0.008978829 46 0.8276904 0.8723096  94.667 <0.0001
##  M3 - M0      1.27 0.021935980 46 1.2154959 1.3245041  57.896 <0.0001
## 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 3 estimates 
## P value adjustment: holm method for 3 tests 
##  contrast           estimate          SE df   lower.CL   upper.CL t.ratio
##  linear_minggu     0.9659814 0.017774704 46  0.9218167  1.0101460  54.346
##  kuadratik_minggu  0.0400000 0.011025577 46  0.0126048  0.0673952   3.628
##  kubik_minggu     -0.0581378 0.005164766 46 -0.0709706 -0.0453049 -11.257
##  p.value
##  <0.0001
##   0.0007
##  <0.0001
## 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 3 estimates 
## P value adjustment: holm method for 3 tests
## 
## >>> 6. Pembanding nonparametrik: Friedman dan Wilcoxon
##   .y.  n statistic df            p        method
## 1  hb 47       141  3 2.300576e-30 Friedman test
##   .y.  n effsize    method magnitude
## 1  hb 47       1 Kendall W     large
##   waktu_1 waktu_2 n_pasangan V           p p_bonferroni
## 1      M0      M1         47 0 2.47578e-09 1.485468e-08
## 2      M0      M2         47 0 2.47578e-09 1.485468e-08
## 3      M0      M3         47 0 2.47578e-09 1.485468e-08
## 4      M1      M2         47 0 2.47578e-09 1.485468e-08
## 5      M1      M3         47 0 2.47578e-09 1.485468e-08
## 6      M2      M3         47 0 2.47578e-09 1.485468e-08
## 
## >>> 7. Mixed Design ANOVA: Kelompok × Waktu
## Anova Table (Type 3 tests)
## 
## Response: hb
##           Effect           df  MSE           F  ges  pes p.value
## 1       kelompok       2, 138 0.54   15.38 *** .174 .182   <.001
## 2          waktu 1.26, 173.64 0.03 3120.68 *** .560 .958   <.001
## 3 kelompok:waktu 2.52, 173.64 0.03  405.05 *** .248 .854   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG  
## 
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
## 
##                Sum Sq num Df Error SS den Df    F value    Pr(>F)    
## (Intercept)     74427      1   74.217    138 138390.389 < 2.2e-16 ***
## kelompok           17      2   74.217    138     15.379 9.342e-07 ***
## waktu             100      3    4.420    414   3120.676 < 2.2e-16 ***
## kelompok:waktu     26      6    4.420    414    405.048 < 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.056703 1.4451e-82
## kelompok:waktu       0.056703 1.4451e-82
## 
## 
## Greenhouse-Geisser and Huynh-Feldt Corrections
##  for Departure from Sphericity
## 
##                 GG eps Pr(>F[GG])    
## waktu          0.41943  < 2.2e-16 ***
## kelompok:waktu 0.41943  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                   HF eps    Pr(>F[HF])
## waktu          0.4214785 2.174341e-121
## kelompok:waktu 0.4214785  3.293506e-73 
## 
## Type III Repeated Measures MANOVA Tests: Pillai test statistic
##                Df test stat approx F num Df den Df    Pr(>F)    
## (Intercept)     1   0.99900   138390      1    138 < 2.2e-16 ***
## kelompok        2   0.18226       15      2    138 9.342e-07 ***
## waktu           1   0.98773     3649      3    136 < 2.2e-16 ***
## kelompok:waktu  2   1.28058       81      6    274 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
##             efek   num Df   den Df        MSE          F       pes       ges
## 1       kelompok 2.000000 138.0000 0.53780424   15.37888 0.1822598 0.1737959
## 2          waktu 1.258281 173.6428 0.02545438 3120.67571 0.9576515 0.5596747
## 3 kelompok:waktu 2.516562 173.6428 0.02545438  405.04768 0.8544450 0.2480927
##          Pr(>F)
## 1  9.342418e-07
## 2 8.191974e-121
## 3  7.251227e-73
## # Effect Size for ANOVA (Type III)
## 
## Parameter      | Eta2 (partial) |       95% CI
## ----------------------------------------------
## kelompok       |           0.18 | [0.09, 1.00]
## waktu          |           0.96 | [0.95, 1.00]
## kelompok:waktu |           0.85 | [0.84, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
## 
## >>> 8. Visualisasi interaksi Kelompok × Waktu

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/08_interaksi_anova.png
## 
## >>> 9. Efek sederhana dan post hoc antarkelompok
##   model term       kelompok df1 df2  F.ratio       p.value        p_holm
## 1      waktu Kapsul Gelatin   3 138  382.701  1.152313e-66  1.152313e-66
## 4      waktu Teh Daun Kelor   3 138 1723.755 3.916247e-109 7.832494e-109
## 7      waktu      Tablet Fe   3 138 2221.287 1.479735e-116 4.439205e-116
##   model term waktu df1 df2 F.ratio      p.value       p_holm
## 1   kelompok    M0   2 138   2.367 9.754681e-02 1.950936e-01
## 3   kelompok    M1   2 138   0.747 4.756994e-01 4.756994e-01
## 5   kelompok    M2   2 138  47.368 2.178206e-16 6.534619e-16
## 7   kelompok    M3   2 138  63.650 2.592431e-20 1.036973e-19
## kelompok = Kapsul Gelatin:
##  contrast estimate         SE  df  lower.CL  upper.CL t.ratio p.value
##  M1 - M0      0.19 0.01284673 138 0.1588658 0.2211342  14.790 <0.0001
##  M2 - M0      0.22 0.01652068 138 0.1799619 0.2600381  13.317 <0.0001
##  M3 - M0      0.41 0.02503323 138 0.3493316 0.4706684  16.378 <0.0001
## 
## kelompok = Teh Daun Kelor:
##  contrast estimate         SE  df  lower.CL  upper.CL t.ratio p.value
##  M1 - M0      0.34 0.01284673 138 0.3088658 0.3711342  26.466 <0.0001
##  M2 - M0      0.85 0.01652068 138 0.8099619 0.8900381  51.451 <0.0001
##  M3 - M0      1.27 0.02503323 138 1.2093316 1.3306684  50.733 <0.0001
## 
## kelompok = Tablet Fe:
##  contrast estimate         SE  df  lower.CL  upper.CL t.ratio p.value
##  M1 - M0      0.30 0.01284673 138 0.2688658 0.3311342  23.352 <0.0001
##  M2 - M0      1.14 0.01652068 138 1.0999619 1.1800381  69.004 <0.0001
##  M3 - M0      1.61 0.02503323 138 1.5493316 1.6706684  64.315 <0.0001
## 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 3 estimates 
## P value adjustment: holm method for 3 tests 
## waktu = M0:
##  contrast                        estimate         SE  df   lower.CL   upper.CL
##  Kapsul Gelatin - Teh Daun Kelor     0.12 0.07295836 138 -0.0528582  0.2928582
##  Kapsul Gelatin - Tablet Fe          0.15 0.07295836 138 -0.0228582  0.3228582
##  Teh Daun Kelor - Tablet Fe          0.03 0.07295836 138 -0.1428582  0.2028582
##  t.ratio p.value
##    1.645  0.2305
##    2.056  0.1030
##    0.411  0.9111
## 
## waktu = M1:
##  contrast                        estimate         SE  df   lower.CL   upper.CL
##  Kapsul Gelatin - Teh Daun Kelor    -0.03 0.05746451 138 -0.1661491  0.1061491
##  Kapsul Gelatin - Tablet Fe          0.04 0.05746451 138 -0.0961491  0.1761491
##  Teh Daun Kelor - Tablet Fe          0.07 0.05746451 138 -0.0661491  0.2061491
##  t.ratio p.value
##   -0.522  0.8607
##    0.696  0.7662
##    1.218  0.4445
## 
## waktu = M2:
##  contrast                        estimate         SE  df   lower.CL   upper.CL
##  Kapsul Gelatin - Teh Daun Kelor    -0.51 0.08048831 138 -0.7006987 -0.3193013
##  Kapsul Gelatin - Tablet Fe         -0.77 0.08048831 138 -0.9606987 -0.5793013
##  Teh Daun Kelor - Tablet Fe         -0.26 0.08048831 138 -0.4506987 -0.0693013
##  t.ratio p.value
##   -6.336 <0.0001
##   -9.567 <0.0001
##   -3.230  0.0044
## 
## waktu = M3:
##  contrast                        estimate         SE  df   lower.CL   upper.CL
##  Kapsul Gelatin - Teh Daun Kelor    -0.74 0.09562820 138 -0.9665692 -0.5134308
##  Kapsul Gelatin - Tablet Fe         -1.05 0.09562820 138 -1.2765692 -0.8234308
##  Teh Daun Kelor - Tablet Fe         -0.31 0.09562820 138 -0.5365692 -0.0834308
##  t.ratio p.value
##   -7.738 <0.0001
##  -10.980 <0.0001
##   -3.242  0.0042
## 
## Confidence level used: 0.95 
## Conf-level adjustment: tukey method for comparing a family of 3 estimates 
## P value adjustment: tukey method for comparing a family of 3 estimates
## 
## >>> 10. Kontras perubahan baseline–minggu 3 dan tren
##  waktu_custom kelompok_pairwise               estimate         SE  df  lower.CL
##  M3-M0        Kapsul Gelatin - Teh Daun Kelor    -0.86 0.03540233 138 -0.945798
##  M3-M0        Kapsul Gelatin - Tablet Fe         -1.20 0.03540233 138 -1.285798
##  M3-M0        Teh Daun Kelor - Tablet Fe         -0.34 0.03540233 138 -0.425798
##   upper.CL t.ratio p.value
##  -0.774202 -24.292 <0.0001
##  -1.114202 -33.896 <0.0001
##  -0.254202  -9.604 <0.0001
## 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 3 estimates 
## P value adjustment: holm method for 3 tests 
##  waktu_custom  kelompok_pairwise                 estimate         SE  df
##  linear_minggu Kapsul Gelatin - Teh Daun Kelor -0.6842368 0.03020487 138
##  linear_minggu Kapsul Gelatin - Tablet Fe      -0.9861060 0.03020487 138
##  linear_minggu Teh Daun Kelor - Tablet Fe      -0.3018692 0.03020487 138
##    lower.CL   upper.CL t.ratio p.value
##  -0.7574387 -0.6110349 -22.653 <0.0001
##  -1.0593079 -0.9129041 -32.647 <0.0001
##  -0.3750711 -0.2286673  -9.994 <0.0001
## 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 3 estimates 
## P value adjustment: holm method for 3 tests
## 
## >>> 11. Linear Mixed Model (LMM)
##                    model n_observasi       AIC       BIC singular konvergensi
## 1       random_intercept         564 -307.2290 -246.5382    FALSE            
## 2 random_intercept_slope         564 -487.0326 -417.6718    FALSE            
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: hb ~ kelompok * waktu + (1 + minggu | id)
##    Data: long_obs
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: -519
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9300 -0.3602  0.0089  0.3759  3.6133 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  id       (Intercept) 0.091247 0.30207       
##           minggu      0.003229 0.05682  0.67 
##  Residual             0.005294 0.07276       
## Number of obs: 564, groups:  id, 141
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       11.487500   0.030880 137.999983 372.009  < 2e-16 ***
## kelompok1         -0.232500   0.043670 137.999982  -5.324 4.01e-07 ***
## kelompok2          0.057500   0.043670 137.999982   1.317  0.19013    
## waktu1            -0.527500   0.008927 184.675436 -59.091  < 2e-16 ***
## waktu2            -0.250833   0.005821 392.996897 -43.089  < 2e-16 ***
## waktu3             0.209167   0.005821 392.996897  35.931  < 2e-16 ***
## kelompok1:waktu1   0.322500   0.012625 184.675435  25.545  < 2e-16 ***
## kelompok2:waktu1  -0.087500   0.012625 184.675436  -6.931 6.77e-11 ***
## kelompok1:waktu2   0.235833   0.008233 392.996897  28.647  < 2e-16 ***
## kelompok2:waktu2  -0.024167   0.008233 392.996897  -2.936  0.00353 ** 
## kelompok1:waktu3  -0.194167   0.008233 392.996898 -23.585  < 2e-16 ***
## kelompok2:waktu3   0.025833   0.008233 392.996898   3.138  0.00183 ** 
## ---
## 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
## kelompok1    0.000                                                        
## kelompok2    0.000 -0.500                                                 
## waktu1      -0.632  0.000  0.000                                          
## waktu2      -0.323  0.000  0.000  0.150                                   
## waktu3       0.323  0.000  0.000 -0.511 -0.446                            
## klmpk1:wkt1  0.000 -0.632  0.316  0.000  0.000  0.000                     
## klmpk2:wkt1  0.000  0.316 -0.632  0.000  0.000  0.000 -0.500              
## klmpk1:wkt2  0.000 -0.323  0.162  0.000  0.000  0.000  0.150 -0.075       
## klmpk2:wkt2  0.000  0.162 -0.323  0.000  0.000  0.000 -0.075  0.150 -0.500
## klmpk1:wkt3  0.000  0.323 -0.162  0.000  0.000  0.000 -0.511  0.256 -0.446
## klmpk2:wkt3  0.000 -0.162  0.323  0.000  0.000  0.000  0.256 -0.511  0.223
##             klm2:2 klm1:3
## kelompok1                
## kelompok2                
## waktu1                   
## waktu2                   
## waktu3                   
## klmpk1:wkt1              
## klmpk2:wkt1              
## klmpk1:wkt2              
## klmpk2:wkt2              
## klmpk1:wkt3  0.223       
## klmpk2:wkt3 -0.446 -0.500 
##  Groups   Name        Std.Dev. Corr  
##  id       (Intercept) 0.302071       
##           minggu      0.056825 0.672 
##  Residual             0.072763        
##             efek     Sum Sq    Mean Sq NumDF    DenDF    F value        Pr(>F)
## 1       kelompok  0.1628456 0.08142279     2 138.0000   15.37888  9.342426e-07
## 2          waktu 25.2930004 8.43100013     3 294.6541 1587.81207 1.674382e-181
## 3 kelompok:waktu  7.8754406 1.31257343     6 328.7935  247.02195 1.417505e-118
## # Intraclass Correlation Coefficient
## 
##     Adjusted ICC: 0.925
##   Unadjusted ICC: 0.333 
##  waktu_custom kelompok_pairwise               estimate         SE     df
##  M3-M0        Kapsul Gelatin - Teh Daun Kelor    -0.86 0.04107627 145.62
##  M3-M0        Kapsul Gelatin - Tablet Fe         -1.20 0.04107627 145.62
##  M3-M0        Teh Daun Kelor - Tablet Fe         -0.34 0.04107627 145.62
##    lower.CL   upper.CL t.ratio p.value
##  -0.9594847 -0.7605153 -20.937 <0.0001
##  -1.2994847 -1.1005153 -29.214 <0.0001
##  -0.4394847 -0.2405153  -8.277 <0.0001
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## Conf-level adjustment: bonferroni method for 3 estimates 
## P value adjustment: holm method for 3 tests 
## waktu = M0:
##  kelompok       emmean         SE     df lower.CL upper.CL
##  Kapsul Gelatin  11.05 0.04532188 142.64 10.96041 11.13959
##  Teh Daun Kelor  10.93 0.04532188 142.64 10.84041 11.01959
##  Tablet Fe       10.90 0.04532188 142.64 10.81041 10.98959
## 
## waktu = M1:
##  kelompok       emmean         SE     df lower.CL upper.CL
##  Kapsul Gelatin  11.24 0.05112505 146.65 11.13896 11.34104
##  Teh Daun Kelor  11.27 0.05112505 146.65 11.16896 11.37104
##  Tablet Fe       11.20 0.05112505 146.65 11.09896 11.30104
## 
## waktu = M2:
##  kelompok       emmean         SE     df lower.CL upper.CL
##  Kapsul Gelatin  11.27 0.05754021 144.77 11.15627 11.38373
##  Teh Daun Kelor  11.78 0.05754021 144.77 11.66627 11.89373
##  Tablet Fe       12.04 0.05754021 144.77 11.92627 12.15373
## 
## waktu = M3:
##  kelompok       emmean         SE     df lower.CL upper.CL
##  Kapsul Gelatin  11.46 0.06438469 140.27 11.33271 11.58729
##  Teh Daun Kelor  12.20 0.06438469 140.27 12.07271 12.32729
##  Tablet Fe       12.51 0.06438469 140.27 12.38271 12.63729
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95
## 
## >>> 12. Diagnostik LMM

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/12_qq_residual.png

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/12_residual_prediksi.png

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/12_residual_per_sel.png
## [1] FALSE 
## [1] TRUE
## attr(,"gradient")
## [1] 3.823238e-07
## 
## >>> 13. Grafik rerata prediksi LMM

## Grafik tersimpan: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/13_profil_prediksi_lmm.png
## 
## >>> 14. LMM pada peserta lengkap: pembanding ANOVA
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: hb ~ kelompok * waktu + (1 + minggu | id)
##    Data: long_cc
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: -519
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9300 -0.3602  0.0089  0.3759  3.6133 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  id       (Intercept) 0.091247 0.30207       
##           minggu      0.003229 0.05682  0.67 
##  Residual             0.005294 0.07276       
## Number of obs: 564, groups:  id, 141
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       11.487500   0.030880 137.999983 372.009  < 2e-16 ***
## kelompok1         -0.232500   0.043670 137.999982  -5.324 4.01e-07 ***
## kelompok2          0.057500   0.043670 137.999982   1.317  0.19013    
## waktu1            -0.527500   0.008927 184.675436 -59.091  < 2e-16 ***
## waktu2            -0.250833   0.005821 392.996897 -43.089  < 2e-16 ***
## waktu3             0.209167   0.005821 392.996897  35.931  < 2e-16 ***
## kelompok1:waktu1   0.322500   0.012625 184.675435  25.545  < 2e-16 ***
## kelompok2:waktu1  -0.087500   0.012625 184.675436  -6.931 6.77e-11 ***
## kelompok1:waktu2   0.235833   0.008233 392.996897  28.647  < 2e-16 ***
## kelompok2:waktu2  -0.024167   0.008233 392.996897  -2.936  0.00353 ** 
## kelompok1:waktu3  -0.194167   0.008233 392.996898 -23.585  < 2e-16 ***
## kelompok2:waktu3   0.025833   0.008233 392.996898   3.138  0.00183 ** 
## ---
## 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
## kelompok1    0.000                                                        
## kelompok2    0.000 -0.500                                                 
## waktu1      -0.632  0.000  0.000                                          
## waktu2      -0.323  0.000  0.000  0.150                                   
## waktu3       0.323  0.000  0.000 -0.511 -0.446                            
## klmpk1:wkt1  0.000 -0.632  0.316  0.000  0.000  0.000                     
## klmpk2:wkt1  0.000  0.316 -0.632  0.000  0.000  0.000 -0.500              
## klmpk1:wkt2  0.000 -0.323  0.162  0.000  0.000  0.000  0.150 -0.075       
## klmpk2:wkt2  0.000  0.162 -0.323  0.000  0.000  0.000 -0.075  0.150 -0.500
## klmpk1:wkt3  0.000  0.323 -0.162  0.000  0.000  0.000 -0.511  0.256 -0.446
## klmpk2:wkt3  0.000 -0.162  0.323  0.000  0.000  0.000  0.256 -0.511  0.223
##             klm2:2 klm1:3
## kelompok1                
## kelompok2                
## waktu1                   
## waktu2                   
## waktu3                   
## klmpk1:wkt1              
## klmpk2:wkt1              
## klmpk1:wkt2              
## klmpk2:wkt2              
## klmpk1:wkt3  0.223       
## klmpk2:wkt3 -0.446 -0.500 
##             efek     Sum Sq    Mean Sq NumDF    DenDF    F value        Pr(>F)
## 1       kelompok  0.1628456 0.08142279     2 138.0000   15.37888  9.342426e-07
## 2          waktu 25.2930004 8.43100013     3 294.6541 1587.81207 1.674382e-181
## 3 kelompok:waktu  7.8754406 1.31257343     6 328.7935  247.02195 1.417505e-118
## 
## >>> 15. Informasi sesi dan batas interpretasi
## 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_Indonesia.utf8  LC_CTYPE=English_Indonesia.utf8   
## [3] LC_MONETARY=English_Indonesia.utf8 LC_NUMERIC=C                      
## [5] LC_TIME=English_Indonesia.utf8    
## 
## time zone: Asia/Makassar
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] tibble_3.3.1       base64enc_0.1-6    htmltools_0.5.9    knitr_1.51        
##  [5] ggpubr_1.0.0       performance_0.18.2 pbkrtest_0.5.5     lmerTest_3.2-1    
##  [9] effectsize_1.0.3   car_3.1-5          carData_3.0-6      rstatix_1.1.0     
## [13] emmeans_2.0.4      afex_1.5-1         lme4_2.0-6         Matrix_1.7-5      
## [17] ggplot2_4.0.3      tidyr_1.3.2        dplyr_1.2.1       
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.2.1    farver_2.1.2        S7_0.2.2           
##  [4] fastmap_1.2.0       bayestestR_0.19.0   rpart_4.1.27       
##  [7] digest_0.6.39       estimability_2.0.0  lifecycle_1.0.5    
## [10] cluster_2.1.8.2     magrittr_2.0.5      compiler_4.6.1     
## [13] rlang_1.3.0         Hmisc_5.3-0         sass_0.4.10        
## [16] tools_4.6.1         yaml_2.3.12         data.table_1.18.6.1
## [19] ggsignif_0.6.4      labeling_0.4.3      htmlwidgets_1.6.4  
## [22] plyr_1.8.9          RColorBrewer_1.1-3  abind_1.4-8        
## [25] foreign_0.8-91      withr_3.0.3         purrr_1.2.2        
## [28] numDeriv_2016.8-1.1 stats4_4.6.1        nnet_7.3-20        
## [31] grid_4.6.1          datawizard_1.4.0    colorspace_2.1-3   
## [34] scales_1.4.0        MASS_7.3-65         insight_1.5.4      
## [37] cli_3.6.6           mvtnorm_1.4-2       rmarkdown_2.31     
## [40] ragg_1.5.2          reformulas_0.4.4    generics_0.1.4     
## [43] otel_0.2.0          rstudioapi_0.19.0   reshape2_1.4.5     
## [46] parameters_0.29.3   readxl_1.5.0.1      minqa_1.2.8        
## [49] cachem_1.1.0        stringr_1.6.0       splines_4.6.1      
## [52] parallel_4.6.1      cellranger_1.1.0    vctrs_0.7.3        
## [55] boot_1.3-32         jsonlite_2.0.0      htmlTable_2.5.0    
## [58] Formula_1.2-6       systemfonts_1.3.2   jquerylib_0.1.4    
## [61] glue_1.8.1          nloptr_2.2.1        stringi_1.8.9      
## [64] gtable_0.3.6        pillar_1.11.1       R6_2.6.1           
## [67] textshaping_1.0.5   Rdpack_2.6.6        evaluate_1.0.5     
## [70] lattice_0.22-9      rbibutils_2.4.1     backports_1.5.1    
## [73] broom_1.0.13        bslib_0.12.0        Rcpp_1.1.2         
## [76] checkmate_2.3.4     gridExtra_2.3.1     nlme_3.1-169       
## [79] xfun_0.60           pkgconfig_2.0.3     
##                                                       bagian  status
## 1                    1. Sumber, desain, dan kelengkapan data Selesai
## 2                    2. Statistik deskriptif dan visualisasi Selesai
## 3                 3. Pemeriksaan asumsi pada peserta lengkap Selesai
## 4             4. RM ANOVA satu arah: Kelompok Teh Daun Kelor Selesai
## 5  5. Post hoc perubahan waktu dalam kelompok Teh Daun Kelor Selesai
## 6         6. Pembanding nonparametrik: Friedman dan Wilcoxon Selesai
## 7                    7. Mixed Design ANOVA: Kelompok × Waktu Selesai
## 8                  8. Visualisasi interaksi Kelompok × Waktu Selesai
## 9               9. Efek sederhana dan post hoc antarkelompok Selesai
## 10          10. Kontras perubahan baseline–minggu 3 dan tren Selesai
## 11                              11. Linear Mixed Model (LMM) Selesai
## 12                                        12. Diagnostik LMM Selesai
## 13                            13. Grafik rerata prediksi LMM Selesai
## 14            14. LMM pada peserta lengkap: pembanding ANOVA Selesai
## 15                 15. Informasi sesi dan batas interpretasi Selesai
##                                                                                                                                       peringatan
## 1                                                                                                                                               
## 2                                                                                                                                               
## 3                                                                                                                                  NaNs produced
## 4                                                                                                                                               
## 5                                                                                                                                               
## 6                                                                                                                                               
## 7                                                                                                                                               
## 8  Panel(s) show a mixed within-between-design.\nError bars do not allow comparisons across all means.\nSuppress error bars with: error = "none"
## 9                                                                                                                                  NaNs produced
## 10                                                                                                                                              
## 11                                                                                                                                              
## 12                                                                                                                                              
## 13                                                                                                                                              
## 14                                                                                                                                              
## 15
## 
## Laporan tersedia: D:/S2 MKM/KULIAH/BIOSTATISTIK/tugas pak fathur/revisi/Analisis teh daun kelor/ke-2/hasil analisis teh daun kelor/laporan_analisis_hb_teh_daun_kelor.html
## Durasi: 42.7 detik.