Learn R Programming

depower (version 2025.1.20)

t_test_welch: Welch's t-Test

Description

Performs Welch's independent two-sample t-test.

Usage

t_test_welch(data, alternative = "two.sided", ci_level = NULL, mean_null = 0)

Value

A list with the following elements:

SlotSubslotNameDescription
1tValue of the t-statistic.
2dfDegrees of freedom for the t-statistic.
3pp-value.
4diff_meanEstimated difference of means (group 2 – group 1).
41estimatePoint estimate.
42lowerConfidence interval lower bound.
43upperConfidence interval upper bound.
5mean1Estimated mean of group 1.
6mean2Estimated mean of group 2.
7n1Sample size of group 1.
8n2Sample size of group 2.
9methodMethod used for the results.
10alternativeThe alternative hypothesis.
11ci_levelThe confidence level.
12mean_nullAssumed population difference of the means under the null hypothesis.

Arguments

data

(list)
A list whose first element is the vector of normal values from group 1 and the second element is the vector of normal values from group 2. NAs are silently excluded. The default output from sim_log_lognormal().

alternative

(string: "two.sided")
The alternative hypothesis. Must be one of "two.sided", "greater", or "less". See 'Details' for additional information.

ci_level

(Scalar numeric: NULL; (0, 1))
If NULL, confidence intervals are set as NA. If in (0, 1), confidence intervals are calculated at the specified level.

mean_null

(Scalar numeric: 0; (-Inf, Inf))
The difference of means assumed under the null hypothesis. See 'Details' for additional information.

Details

This function is primarily designed for speed in simulation. Missing values are silently excluded.

The hypotheses for Welch's independent two-sample t-test are

$$ \begin{aligned} H_{null} &: \mu_2 - \mu_1 = \mu_{null} \\ H_{alt} &: \begin{cases} \mu_2 - \mu_1 \neq \mu_{null} & \text{two-sided}\\ \mu_2 - \mu_1 > \mu_{null} & \text{greater than}\\ \mu_2 - \mu_1 < \mu_{null} & \text{less than} \end{cases} \end{aligned} $$

where \(\mu_1\) is the population mean of group 1, \(\mu_2\) is the population mean of group 2, and \(\mu_{null}\) is a constant for the assumed difference of population means (usually \(\mu_{null} = 0\)).

The test statistic is

$$ T = \frac{(\bar{x}_2 - \bar{x}_1) - \mu_{null}}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}} $$

where \(\bar{x}_1\) and \(\bar{x}_2\) are the sample means, \(\mu_{null}\) is the difference of population means assumed under the null hypothesis, \(n_1\) and \(n_2\) are the sample sizes, and \(s_1^2\) and \(s_2^2\) are the sample variances.

The critical value of the test statistic uses the Welch–Satterthwaite degrees of freedom

$$ v = \frac{\left( \frac{s_1^2}{n_1} + \frac{s_2^2}{n_2} \right)^2} {(N_1 - 1)^{-1}\left( \frac{s_1^2}{n_1} \right)^2 + (N_2 - 1)^{-1}\left( \frac{s_2^2}{n_2} \right)^2} $$

and the p-value is calculated as

$$ \begin{aligned} p &= \begin{cases} 2 \text{min} \{P(T \geq t_{v} \mid H_{null}), P(T \leq t_{v} \mid H_{null})\} & \text{two-sided}\\ P(T \geq t_{v} \mid H_{null}) & \text{greater than}\\ P(T \leq t_{v} \mid H_{null}) & \text{less than} \end{cases} \end{aligned} $$

Let \(GM(\cdot)\) be the geometric mean and \(AM(\cdot)\) be the arithmetic mean. For independent lognormal variables \(X_1\) and \(X_2\) it follows that \(\ln X_1\) and \(\ln X_2\) are independent normally distributed variables. Defining \(\mu_{X_2} - \mu_{X_1} = AM(\ln X_2) - AM(\ln X_1)\) we have

$$ e^{\mu_{X_2} - \mu_{X_1}} = \frac{GM(X_2)}{GM(X_1)} $$

This forms the basis for making inference about the ratio of geometric means of the original lognormal data using the difference of means of the log transformed normal data.

References

julious_2004depower

hauschke_1992depower

johnson_1994depower

See Also

Examples

Run this code
#----------------------------------------------------------------------------
# t_test_welch() examples
#----------------------------------------------------------------------------
library(depower)

# Welch's t-test
set.seed(1234)
sim_log_lognormal(
  n1 = 40,
  n2 = 40,
  ratio = 1.5,
  cv1 = 0.4,
  cv2 = 0.4
) |>
  t_test_welch(ci_level = 0.95)

Run the code above in your browser using DataLab