Performs Welch's independent two-sample t-test.
t_test_welch(data, alternative = "two.sided", ci_level = NULL, mean_null = 0)
A list with the following elements:
Slot | Subslot | Name | Description |
1 | t | Value of the t-statistic. | |
2 | df | Degrees of freedom for the t-statistic. | |
3 | p | p-value. | |
4 | diff_mean | Estimated difference of means (group 2 – group 1). | |
4 | 1 | estimate | Point estimate. |
4 | 2 | lower | Confidence interval lower bound. |
4 | 3 | upper | Confidence interval upper bound. |
5 | mean1 | Estimated mean of group 1. | |
6 | mean2 | Estimated mean of group 2. | |
7 | n1 | Sample size of group 1. | |
8 | n2 | Sample size of group 2. | |
9 | method | Method used for the results. | |
10 | alternative | The alternative hypothesis. | |
11 | ci_level | The confidence level. | |
12 | mean_null | Assumed population difference of the means under the null hypothesis. |
(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()
.
(string: "two.sided"
)
The alternative hypothesis. Must be one of "two.sided"
, "greater"
,
or "less"
. See 'Details' for additional information.
(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.
(Scalar numeric: 0
; (-Inf, Inf)
)
The difference of means assumed under the null hypothesis. See
'Details' for additional information.
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.
julious_2004depower
hauschke_1992depower
johnson_1994depower
#----------------------------------------------------------------------------
# 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