Data

# 1. Definisi Data
n_tenso <- 400      # jumlah pasien Tenso понижена
x_tenso <- 48       # jumlah pasien dengan batuk kering

n_normo <- 500      # jumlah pasien Normopress
x_normo <- 45       # jumlah pasien dengan batuk kering

alpha <- 0.01       # tingkat signifikansi

Melakukan Uji proporsi dua sampel

# 2. Uji proporsi dua sampel (one‑sided: p1 > p2)
#    gunakan prop.test tanpa continuity correction agar Z-test murni
pt <- prop.test(
  x       = c(x_tenso, x_normo),
  n       = c(n_tenso, n_normo),
  alternative = "greater",
  correct     = FALSE,
  conf.level  = 1 - alpha
)

Ringkasan Hasil

# 3. Ringkas hasil via broom
res <- tidy(pt) %>%
  rename(
    p1        = estimate1,
    p2        = estimate2,
    chi_sq    = statistic,
    p_value   = p.value,
    conf_low  = conf.low,
    conf_high = conf.high
  ) %>%
  mutate(
    p_diff     = p1 - p2,
    pooled_p   = (x_tenso + x_normo)/(n_tenso + n_normo),
    z_stat     = (p1 - p2) /
                 sqrt(pooled_p*(1-pooled_p)*(1/n_tenso + 1/n_normo)),
    z_crit     = qnorm(1 - alpha),
    conf.level = paste0((1-alpha)*100, "%")
  )

Menampilkan Tabel

# 4. Cetak tabel ringkas
res %>%
  select(
    method, p1, p2, pooled_p, p_diff,
    z_stat, z_crit, chi_sq, p_value, conf_low, conf_high, conf.level
  ) %>%
  kable(digits = 4,
        caption = "Hasil Uji Proporsi Dua Sampel (Tenso понижена > Normopress)")
Hasil Uji Proporsi Dua Sampel (Tenso понижена > Normopress)
method p1 p2 pooled_p p_diff z_stat z_crit chi_sq p_value conf_low conf_high conf.level
2-sample test for equality of proportions without continuity correction 0.12 0.09 0.1033 0.03 1.4692 2.3263 2.1585 0.0709 -0.0181 1 99%

Interpretasi Hasil

cat("**Hipotesis Nol (H0):** p₁ ≤ p₂  (Tenso понижена tidak lebih berisiko batuk kering)\n")
## **Hipotesis Nol (H0):** p₁ ≤ p₂  (Tenso понижена tidak lebih berisiko batuk kering)
cat("**Hipotesis Alternatif (H1):** p₁ > p₂  (Tenso понижена lebih berisiko)\n\n")
## **Hipotesis Alternatif (H1):** p₁ > p₂  (Tenso понижена lebih berisiko)
cat(sprintf("- Proporsi Tenso понижена (p₁): %.4f\n", res$p1_manual))
cat(sprintf("- Proporsi Normopress    (p₂): %.4f\n", res$p2_manual))
cat(sprintf("- Proporsi gabungan       : %.4f\n\n", res$pooled_p))
## - Proporsi gabungan       : 0.1033
cat(sprintf("- Z‑hitung                : %.4f\n", res$z_stat))
## - Z‑hitung                : 1.4692
cat(sprintf("- Z‑kritis (α = %.2f)      : %.4f\n", alpha, res$z_crit))
## - Z‑kritis (α = 0.01)      : 2.3263
cat(sprintf("- χ² statistic            : %.4f (sekunder dari prop.test)\n", res$chi_sq))
## - χ² statistic            : 2.1585 (sekunder dari prop.test)
cat(sprintf("- P‑value                 : %.4f\n\n", res$p_value))
## - P‑value                 : 0.0709
if (res$p_value <= alpha) {
  cat("**Keputusan:** Tolak H₀  \n",
      "Terdapat bukti statistik (α = 1%) bahwa obat Tenso понижена\n",
      "meningkatkan risiko batuk kering dibandingkan Normopress.\n")
} else {
  cat("**Keputusan:** Gagal tolak H₀  \n",
      "Tidak terdapat bukti cukup (α = 1%) bahwa Tenso понижена\n",
      "lebih berisiko daripada Normopress.\n")
}
## **Keputusan:** Gagal tolak H₀  
##  Tidak terdapat bukti cukup (α = 1%) bahwa Tenso понижена
##  lebih berisiko daripada Normopress.