Paired t-test

Paired t-test in R

The Paired t-test is used when two samples are naturally correlated. In the Paired t-test, the difference of the means between the two samples is compared to a given number that represents the null hypothesis. For a Paired t-test, the number of observations in each sample must be equal.

In R, a Paired t-test can be performed using the Base R t.test() from the stats package or the proc_ttest() function from the procs package.

Normal Data

By default, the R paired t-test functions assume normality in the data and use a classic Student’s t-test.

Data Used

The following data was used in this example.

# Create sample data
pressure <- tibble::tribble(
  ~SBPbefore, ~SBPafter,
  120, 128,   
  124, 131,   
  130, 131,   
  118, 127,
  140, 132,   
  128, 125,   
  140, 141,   
  135, 137,
  126, 118,   
  130, 132,   
  126, 129,   
  127, 135
)

Base R

Code

The following code was used to test the comparison in Base R.

  # Perform t-test
  t.test(pressure$SBPbefore, pressure$SBPafter, paired = TRUE)

    Paired t-test

data:  pressure$SBPbefore and pressure$SBPafter
t = -1.0896, df = 11, p-value = 0.2992
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 -5.536492  1.869825
sample estimates:
mean difference 
      -1.833333 

Procs Package

Code

The following code from the procs package was used to perform a paired t-test.

  library(procs)

  # Perform t-test
  proc_ttest(pressure,
     paired = "SBPbefore*SBPafter")
$Statistics
       VAR1     VAR2               DIFF  N      MEAN      STD   STDERR MIN MAX
1 SBPbefore SBPafter SBPbefore-SBPafter 12 -1.833333 5.828353 1.682501  -9   8

$ConfLimits
       VAR1     VAR2               DIFF      MEAN      LCLM     UCLM      STD
1 SBPbefore SBPafter SBPbefore-SBPafter -1.833333 -5.536492 1.869825 5.828353
   LCLMSTD  UCLMSTD
1 4.128777 9.895832

$TTests
       VAR1     VAR2               DIFF DF         T     PROBT
1 SBPbefore SBPafter SBPbefore-SBPafter 11 -1.089648 0.2991635

Viewer Output:

Lognormal Data

The Base R t.test() function does not have an option for lognormal data. Likewise, the procs proc_ttest() function also does not have an option for lognormal data.

One possibility may be the tTestLnormAltPower() function from the EnvStats package. This package has not been evaluated yet.