make_paired_t_test_table: Create a one-row summary table of a paired t-test

View source: R/make_paired_t_test_table.R

make_paired_t_test_tableR Documentation

Create a one-row summary table of a paired t-test

Description

This function performs a paired t-test between two numeric variables in a data frame and returns a one-row summary table including means, mean difference, t-value, degrees of freedom, p-value, and confidence interval.

Usage

make_paired_t_test_table(
  data,
  var1,
  var2,
  var_name = NULL,
  alternative = "two.sided",
  conf.level = 0.95
)

Arguments

data

A data frame containing the two numeric variables.

var1

Character string. Name of the first variable (observation 1) in 'data'.

var2

Character string. Name of the second variable (observation 2) in 'data'.

var_name

Optional character string. Custom name for the variable to display in the table. Default is 'var1 vs var2'.

alternative

Character string specifying the alternative hypothesis. One of '"two.sided"', '"less"', or '"greater"'. Default is '"two.sided"'.

conf.level

Confidence level for the interval. Default is 0.95.

Value

A one-row data frame with columns:

  • 'Variable' - variable name

  • 'Mean_obs1' - mean of observation 1

  • 'Mean_obs2' - mean of observation 2

  • 'Mean_diff' - mean difference (obs1 - obs2)

  • 't_value' - t statistic

  • 'df' - degrees of freedom

  • 'p_value' - p-value

  • 'CI_lower' - lower bound of confidence interval

  • 'CI_upper' - upper bound of confidence interval

Examples

# example data
df <- data.frame(
  before = c(10, 12, 14, 15, 11),
  after  = c(11, 13, 13, 16, 12)
)

# Run the paired t-test summary
make_paired_t_test_table(df, var1 = "before", var2 = "after")

scaledescr documentation built on April 11, 2026, 5:07 p.m.