Skip to contents

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

Usage

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

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.

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.

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 SA (2004). “Sample sizes for clinical trials with Normal data.” Statistics in Medicine, 23(12), 1921–1986. doi:10.1002/sim.1783 .

Hauschke D, Steinijans VW, Diletti E, Burke M (1992). “Sample size determination for bioequivalence assessment using a multiplicative model.” Journal of Pharmacokinetics and Biopharmaceutics, 20(5), 557–561. ISSN 0090-466X, doi:10.1007/BF01061471 .

Johnson NL, Kotz S, Balakrishnan N (1994). Continuous univariate distributions, Wiley series in probability and mathematical statistics, 2nd ed edition. Wiley, New York. ISBN 9780471584957 9780471584940.

See also

Examples

#----------------------------------------------------------------------------
# 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)
#> $t
#> [1] 5.13445
#> 
#> $df
#> [1] 77.13181
#> 
#> $p
#> [1] 2.064624e-06
#> 
#> $diff_mean
#> $diff_mean$estimate
#> [1] 0.3708989
#> 
#> $diff_mean$lower
#> [1] 0.22706
#> 
#> $diff_mean$upper
#> [1] 0.5147379
#> 
#> 
#> $mean1
#> [1] -0.004175314
#> 
#> $mean2
#> [1] 0.3667236
#> 
#> $n1
#> [1] 40
#> 
#> $n2
#> [1] 40
#> 
#> $method
#> [1] "Welch's two-sample t-test for 'two-sided' alternative"
#> 
#> $alternative
#> [1] "two.sided"
#> 
#> $ci_level
#> [1] 0.95
#> 
#> $mean_null
#> [1] 0
#>