t_test_paired: Paired and one-sample t-Tests

View source: R/t_test_paired.r

t_test_pairedR Documentation

Paired and one-sample t-Tests

Description

Performs paired and one-sample t-Tests.

Usage

t_test_paired(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 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. If length(data) == 1L, the one-sample test is used. 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 mean or mean difference 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 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.

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.

References

\insertRef

julious_2004depower

\insertRef

hauschke_1992depower

\insertRef

johnson_1994depower

See Also

stats::t.test()

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

# 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


depower documentation built on April 3, 2025, 9:23 p.m.