print_ttest: Print the results of a t-test

View source: R/print_ttest.R

print_ttestR Documentation

Print the results of a t-test

Description

Print the results of a t-test

Usage

print_ttest(
  t_object,
  d_object = NULL,
  decimals = 2,
  decimals_p = 3,
  confidence = FALSE
)

Arguments

t_object

An object of class "htest" returned by t.test.

d_object

An effect size table returned by cohens_d from package effectsize. Optional argument.

decimals

How many decimals should be printed for the t-value (defaults to 2).

decimals_p

How many decimals should be printed for the p-value (defaults to 3).

confidence

Logical. Whether a confidence interval for the effectsize should be printed or not. Can only be TRUE if d_object is provided.

Details

To use this function, you need to install the R package effectsize to compute Cohen's d; pass this object as the second argument.

Value

A string describing the t-test; to be included in an R markdown document.

Author(s)

Martin Papenberg martin.papenberg@hhu.de

References

Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsale, NJ: Lawrence Erlbaum.

Examples


ttest <- t.test(1:10, y = c(7:20), var.equal = TRUE)
library("effectsize") # for Cohen's d
cohend <- cohens_d(1:10, c(7:20))
print_ttest(ttest, cohend) # include this call in Rmd inline code

# An example for paired data:
data(sleep) # ?sleep
tt <- t.test(sleep$extra[sleep$group == 1], 
             sleep$extra[sleep$group == 2], paired = TRUE)
cd <- cohens_d(sleep$extra[sleep$group == 1], 
               sleep$extra[sleep$group == 2], paired = TRUE)
print_ttest(tt, cd)
# Print the confidence interval
print_ttest(tt, cd, confidence = TRUE)
# The information about the CI is taken from the effectsize object:
cd <- cohens_d(sleep$extra[sleep$group == 1], 
               sleep$extra[sleep$group == 2], paired = TRUE, ci = .8)
print_ttest(tt, cd, confidence = TRUE)
# effect size object can be left out:
print_ttest(tt)


m-Py/prmisc documentation built on Aug. 23, 2023, 1:20 a.m.