htest-helpers: Helper Functions for Working with 'htest' Objects

htest-helpersR Documentation

Helper Functions for Working with 'htest' Objects

Description

A collection of utility functions designed to help interpret, display, and standardize information from objects of class 'htest' (hypothesis test results). These functions make it easier to extract, format, and report statistical results from various test functions in R.

Usage

df_htest(htest, test_statistics = TRUE, show_ci = TRUE, extract_names = TRUE)

describe_htest(htest, alpha = NULL, digits = 3)

Arguments

htest

An S3 object of class 'htest', such as (but not limited to) output from t.test(), cor.test(), wilcox.test(), or TOSTER functions converted with as_htest().

test_statistics

A logical variable indicating whether to display the test statistics in the output (default = TRUE).

show_ci

A logical variable indicating whether to display the confidence interval in the output (default = TRUE).

extract_names

A logical variable indicating whether to take the names from the S3 object (i.e., statistic for t.test() would be "t") (default = TRUE).

alpha

The significance level to use for determining statistical significance. If NULL (default), it will be extracted from the confidence interval of the htest object or default to 0.05.

digits

Integer indicating the number of decimal places to display in the output (default = 3).

Details

The package provides two main helper functions:

  1. df_htest(): Converts an 'htest' object to a data frame with standardized columns, making it easier to combine multiple test results or export them for further analysis.

  2. describe_htest(): Generates a formatted text description of the test results, following APA style guidelines and providing a complete statistical report with test statistics, p-values, effect sizes, and confidence intervals.

These functions work with standard R hypothesis tests (e.g., t.test(), wilcox.test(), cor.test()) as well as TOSTER-specific tests that have been converted to 'htest' format using the as_htest() function.

Value

  • df_htest(): Returns a data frame containing the formatted test information.

  • describe_htest(): Returns a character string with a formatted description of the test results.

See Also

Other htest: as_htest(), simple_htest()

Examples

# Example 1: Working with a standard t-test
t_result <- t.test(extra ~ group, data = sleep)

# Convert to data frame
df_htest(t_result)

# Generate formatted description
describe_htest(t_result)

# Example 2: Working with a TOST result
tost_result <- t_TOST(extra ~ group, data = sleep, eqb = 1)
htest_conv <- as_htest(tost_result)
describe_htest(htest_conv)

# Example 3: Customizing output format
df_htest(t_result, test_statistics = TRUE, show_ci = FALSE)
describe_htest(t_result, alpha = 0.01, digits = 2)

# Example 4: Working with correlation tests
cor_result <- cor.test(mtcars$mpg, mtcars$wt)
df_htest(cor_result)
describe_htest(cor_result)


Lakens/TOSTER documentation built on June 9, 2025, 8:57 p.m.