# 1. Two groups with different variances:
set.seed(113)
x <- rnorm(20, mean = 100, sd = 15)
y <- rnorm(20, mean = 110, sd = 25)
welch_t(x, y)
# 2. One-sided test:
welch_t(x, y, alternative = "less")
# 3. Side-by-side comparison with base R's stats::t.test().
# The two functions implement the same Welch / Satterthwaite test, so
# the t-statistic, Satterthwaite degrees of freedom, p-value, and the
# CI on the mean difference match exactly. welch_t() differs only in
# what it returns: a data.frame(term, value) rather than a list-
# like htest object. The return composes with dplyr / ggplot2
# pipelines and avoids stringly-typed access like $statistic.
set.seed(113)
a <- rnorm(15, mean = 0, sd = 1)
b <- rnorm(20, mean = 0.5, sd = 2)
# DMAR (data.frame):
dmar_res <- welch_t(a, b, conf_level = 0.95)
dmar_res
# Base R (htest list):
base_res <- stats::t.test(a, b, var.equal = FALSE, conf.level = 0.95)
base_res
# Verify the four key statistics agree numerically:
pick <- function(term) dmar_res$value[dmar_res$term == term]
stopifnot(
all.equal(pick("t_statistic"), unname(base_res$statistic)),
all.equal(pick("df"), unname(base_res$parameter)),
all.equal(pick("p_value"), base_res$p.value),
all.equal(pick("lower_limit"), base_res$conf.int[1]),
all.equal(pick("upper_limit"), base_res$conf.int[2])
)
Run the code above in your browser using DataLab