Paired and one-sample t-Tests
t_test_paired.RdPerforms paired and one-sample t-Tests.
Arguments
- data
(list)
A list whose first element is the vector of normal values from sample 1 and the second element is the vector of normal values from sample 2. Both vectors must be the same sample size and sorted by the subject/item index. Iflength(data) == 1L, the one-sample test is used. NAs are silently excluded. The default output fromsim_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))
IfNULL, confidence intervals are set asNA. If in(0, 1), confidence intervals are calculated at the specified level.- mean_null
(Scalar numeric:
0;(-Inf, Inf))
The mean or mean difference assumed under the null hypothesis. See 'Details' for additional information.
Value
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 | mean_diff | Estimated mean or mean of the differences (sample 2 – sample 1). | |
| 4 | 1 | estimate | Point estimate. |
| 4 | 2 | lower | Confidence interval lower bound. |
| 4 | 3 | upper | Confidence interval upper bound. |
| 5 | n | Number of paired observations. | |
| 6 | method | Method used for the results. | |
| 7 | alternative | The alternative hypothesis. | |
| 8 | ci_level | The confidence level. | |
| 9 | mean_null | Assumed population mean of the differences under the null hypothesis. |
Details
This function is primarily designed for speed in simulation. Missing values are silently excluded.
The one-sample test is used for both the true one-sample scenario and for the paired differences from a dependent two-sample scenario. Below we use paired difference language as that is the most common case. The hypotheses for the paired t-test are
$$ \begin{aligned} H_{null} &: \mu_{diff} = \mu_{null} \\ H_{alt} &: \begin{cases} \mu_{diff} \neq \mu_{null} & \text{two-sided}\\ \mu_{diff} > \mu_{null} & \text{greater than}\\ \mu_{diff} < \mu_{null} & \text{less than} \end{cases} \end{aligned} $$
where \(\mu_{diff} = AM(X_2 - X_1)\) is the arithmetic mean of the paired differences (sample 2 - sample 1) and \(\mu_{null}\) is a constant for the assumed population mean difference (usually \(\mu_{null} = 0\)).
The test statistic is
$$ T = \frac{\bar{x}_{diff} - \mu_{null}}{\sqrt{\frac{s^2}{n}}} $$
where \(\bar{x}_{diff}\) is the sample mean of the differences, \(\mu_{null}\) is the population mean difference assumed under the null hypothesis, \(n\) is the sample size of the differences, and \(s^2\) is the sample variance.
The critical value of the test statistic has degrees of freedom
$$ df = n-1 $$
and the p-value is calculated as
$$ \begin{aligned} p &= \begin{cases} 2 \text{min} \{P(T \geq t_{n-1} \mid H_{null}), P(T \leq t_{n-1} \mid H_{null})\} & \text{two-sided}\\ P(T \geq t_{n-1} \mid H_{null}) & \text{greater than}\\ P(T \leq t_{n-1} \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 dependent lognormal samples \(X_1\) and \(X_2\) it follows that \(\ln X_1\) and \(\ln X_2\) are dependent normally distributed variables. Setting \(\mu_{diff} = AM(\ln X_2 - \ln X_1)\) we have
$$ e^{\mu_{diff}} = GM\left( \frac{X_2}{X_1} \right) $$
This forms the basis for making inference about the geometric mean ratio of the original lognormal data using the mean difference 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.
Examples
#----------------------------------------------------------------------------
# t_test_paired() examples
#----------------------------------------------------------------------------
library(depower)
# One-sample t-test
set.seed(1234)
t_test1 <- sim_log_lognormal(
n1 = 40,
ratio = 1.5,
cv1 = 0.4
) |>
t_test_paired(ci_level = 0.95)
t_test1
#> $t
#> [1] 4.424455
#>
#> $df
#> [1] 39
#>
#> $p
#> [1] 7.547239e-05
#>
#> $mean_diff
#> $mean_diff$estimate
#> [1] 0.2460215
#>
#> $mean_diff$lower
#> [1] 0.1335499
#>
#> $mean_diff$upper
#> [1] 0.3584931
#>
#>
#> $n
#> [1] 40
#>
#> $method
#> [1] "One-sample t-test for 'two-sided' alternative"
#>
#> $alternative
#> [1] "two.sided"
#>
#> $ci_level
#> [1] 0.95
#>
#> $mean_null
#> [1] 0
#>
# Paired t-test using two dependent samples
set.seed(1234)
t_test2 <- sim_log_lognormal(
n1 = 40,
n2 = 40,
ratio = 1.5,
cv1 = 0.4,
cv2 = 0.2,
cor = 0.3
) |>
t_test_paired(ci_level = 0.95)
t_test2
#> $t
#> [1] 8.418634
#>
#> $df
#> [1] 39
#>
#> $p
#> [1] 2.639548e-10
#>
#> $mean_diff
#> $mean_diff$estimate
#> [1] 0.3900445
#>
#> $mean_diff$lower
#> [1] 0.296331
#>
#> $mean_diff$upper
#> [1] 0.483758
#>
#>
#> $n
#> [1] 40
#>
#> $method
#> [1] "One-sample t-test for 'two-sided' alternative"
#>
#> $alternative
#> [1] "two.sided"
#>
#> $ci_level
#> [1] 0.95
#>
#> $mean_null
#> [1] 0
#>