ttest: Student and Welch t Tests

View source: R/statistics.R View source: R/zzz-r4vn-inference.R

ttestiR Documentation

Student and Welch t Tests

Description

ttesti() calculates one- or two-sample t tests from summary statistics. ttest() performs the same analysis from variables and reports group sample size, mean, standard error, standard deviation, and confidence interval. ttest(..., effect = TRUE) additionally reports Cohen's d and Hedges' g. With by = vars(province, sex, treatment), province and sex are nested strata and treatment is the innermost two-group comparison.

Usage

ttesti(
  n1,
  mean1,
  sd1,
  n2 = NULL,
  mean2 = NULL,
  sd2 = NULL,
  mu = 0,
  equal = FALSE,
  paired = FALSE,
  r = NULL,
  alternative = c("two.sided", "less", "greater"),
  level = 0.95,
  digits = 3,
  p_digits = 3,
  show = TRUE,
  console = FALSE
)

ttesti(
  n1, mean1, sd1, n2 = NULL, mean2 = NULL, sd2 = NULL, mu = 0, equal = FALSE,
  paired = FALSE, r = NULL, alternative = c("two.sided", "less", "greater"),
  level = 0.95, digits = 3, p_digits = 3, show = TRUE, console = FALSE
)

ttest(
  x, y = NULL, by = NULL, data = NULL, mu = 0, equal = FALSE, paired = FALSE,
  alternative = c("two.sided", "less", "greater"), level = 0.95,
  effect = FALSE, digits = 3, p_digits = 3, show = TRUE, console = FALSE
)

ttest(
  x,
  y = NULL,
  by = NULL,
  data = NULL,
  mu = 0,
  equal = FALSE,
  paired = FALSE,
  alternative = c("two.sided", "less", "greater"),
  level = 0.95,
  effect = FALSE,
  digits = 3,
  p_digits = 3,
  show = TRUE,
  console = FALSE
)

Arguments

n1, mean1, sd1

Sample size, mean, and standard deviation for group 1.

n2, mean2, sd2

Optional sample size, mean, and standard deviation for group 2.

mu

Null mean or null mean difference.

equal

Use the equal-variance two-sample t test.

paired

Perform a paired analysis.

r

Correlation between paired measurements when only summaries are available.

alternative

Alternative hypothesis: "two.sided", "less", or "greater".

level

Confidence level as a proportion.

digits, p_digits

Decimal places for estimates and p-values.

show

Logical; open the formatted result in the Viewer. Default TRUE.

console

Logical; also print the traditional text result in the Console. Default FALSE.

x, y

Numeric variables. y is optional.

by

Optional two-level grouping variable. by = vars(a, b, group) performs the test within nested a > b strata using group as the innermost comparison.

data

Data frame. If NULL, the active data set is used.

effect

Logical; for ttest(), add standardized effect sizes.

Value

Invisibly returns an object of class r4vn_stat.

Examples

ttesti(40, 12, 3, mu = 10)
ttesti(40, 12, 3, 35, 14, 4)

d <- data.frame(score = c(10,12,11,18,17,20,9,13,12,19,21,18),
                treatment = rep(c("Control","Intervention"), each = 6),
                province = rep(c("A","B"), each = 3, times = 2))
ttest(score, by = treatment, data = d, effect = TRUE)
ttest(score, by = vars(province, treatment), data = d, effect = TRUE)


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.