Learn R Programming

DMAR (version 1.0.0)

summary_t_test: Two-Sample t Test From Summary Statistics

Description

Computes a two-sample t test (pooled or Welch) directly from the per-group means, standard deviations, and sample sizes, without requiring access to the raw observations. Returns the test statistic, degrees of freedom, p-value, and a CI on the mean difference in a data.frame. Useful for re-analyses from published papers that report only the summary numbers.

Usage

summary_t_test(
  mean_1,
  sd_1,
  n_1,
  mean_2,
  sd_2,
  n_2,
  mu = 0,
  var_equal = TRUE,
  alternative = c("two_sided", "less", "greater"),
  conf_level = 0.95
)

Value

A data.frame with rows for the mean difference, the t statistic, degrees of freedom, p-value, and the CI lower and upper limits on the mean difference.

Arguments

mean_1, mean_2

Group sample means.

sd_1, sd_2

Group sample standard deviations.

n_1, n_2

Group sample sizes.

mu

Null value of the mean difference \(\mu_1 - \mu_2\). Default 0.

var_equal

Logical. If TRUE (default), uses Student's pooled-variance t. If FALSE, uses Welch's separate- variance t with Satterthwaite degrees of freedom.

alternative

One of "two_sided" (default; the base-R spelling "two.sided" is accepted as an alias), "less", or "greater".

conf_level

Confidence level for the CI on the mean difference. Default 0.95.

Author

Ken Kelley [email protected]

Details

Pooled-variance t (Student, 1908). Under \(\sigma_1 = \sigma_2\), the pooled SD is \(s_p = \sqrt{((n_1 - 1) s_1^2 + (n_2 - 1) s_2^2) / (n_1 + n_2 - 2)}\), the test statistic is \(t = (\bar x_1 - \bar x_2 - \mu_0) / (s_p \sqrt{1 / n_1 + 1 / n_2})\), and \(df = n_1 + n_2 - 2\).

Welch's t (Welch, 1947). Under unequal variances, \(t = (\bar x_1 - \bar x_2 - \mu_0) / \sqrt{s_1^2 / n_1 + s_2^2 / n_2}\) with Satterthwaite degrees of freedom (see welch_t).

Choosing pooled vs Welch. Methodological reviews now recommend Welch as the default (Delacre, Lakens, & Leys, 2017; Ruxton, 2006). Pooled-variance t is preserved here primarily for reproducing analyses from older sources that used it.

References

Delacre, M., Lakens, D., & Leys, C. (2017). Why psychologists should by default use Welch's t-test instead of Student's t-test. International Review of Social Psychology, 30(1), 92--101. tools:::Rd_expr_doi("10.5334/irsp.82")

Ruxton, G. D. (2006). The unequal variance t-test is an underused alternative to Student's t-test and the Mann-Whitney U test. Behavioral Ecology, 17(4), 688--690. tools:::Rd_expr_doi("10.1093/beheco/ark016")

Snedecor, G. W., & Cochran, W. G. (1989). Statistical methods (8th ed.). Iowa State University Press.

Student. (1908). The probable error of a mean. Biometrika, 6(1), 1--25. tools:::Rd_expr_doi("10.2307/2331554")

Welch, B. L. (1947). The generalization of "Student's" problem when several different population variances are involved. Biometrika, 34(1/2), 28--35.

See Also

welch_t, t.test, smd

Other hypothesis tests: adjusted_means(), ancova(), anova_within(), ci_dunnett(), ci_scheffe(), ci_tukey_kramer(), compare_cov_structures(), contrast_test(), correlations_test(), equivalence_r(), equivalence_smd(), factorial_anova(), manova_split_plot(), mauchly_test(), mixed_anova(), obrien_test(), pairwise_within(), randomization_test(), randomization_test_paired(), regions_of_significance(), simple_effects_AB(), welch_t()

Examples

Run this code
# 1. Re-analysis from published summary statistics:
#        Group A: M = 100, SD = 15, n = 30
#        Group B: M = 108, SD = 18, n = 25
summary_t_test(mean_1 = 100, sd_1 = 15, n_1 = 30,
               mean_2 = 108, sd_2 = 18, n_2 = 25)

# 2. Welch version for the same data:
summary_t_test(mean_1 = 100, sd_1 = 15, n_1 = 30,
               mean_2 = 108, sd_2 = 18, n_2 = 25,
               var_equal = FALSE)

Run the code above in your browser using DataLab