View source: R/t_test_paired.r
t_test_paired | R Documentation |
Performs paired and one-sample t-Tests.
t_test_paired(data, alternative = "two.sided", ci_level = NULL, mean_null = 0)
data |
(list) |
alternative |
(string: |
ci_level |
(Scalar numeric: |
mean_null |
(Scalar numeric: |
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.
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. |
julious_2004depower
\insertRefhauschke_1992depower
\insertRefjohnson_1994depower
stats::t.test()
#----------------------------------------------------------------------------
# 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
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.