The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {enhancedTtest}


Title: Enhanced T-Test with Automatic Selection and APA Formatting
Version: 0.1.0
Description: Provides enhanced t-test functionality with automatic assumption checking, non-parametric fallbacks, effect size calculation, and APA-formatted tables that can be exported to Word documents. Supports one-sample, two-sample, and paired t-tests with intelligent test selection. Effect size interpretations follow Cohen (1988) <doi:10.4324/9780203771587> and APA formatting follows the Publication Manual of the American Psychological Association, 7th edition (2020) <doi:10.1037/0000165-000>.
License: GPL-3
Encoding: UTF-8
Depends: R (≥ 3.5.0)
Imports: car (≥ 3.0-0), dplyr (≥ 1.0.0), flextable (≥ 0.7.0), htmltools (≥ 0.5.0), nortest (≥ 1.0-4), officer (≥ 0.4.0), rlang (≥ 1.0.0), stats, utils
Suggests: ggplot2, knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
Config/roxygen2/version: 8.1.0
NeedsCompilation: no
Packaged: 2026-10-15 12:47:34 UTC; DELL
Author: Martin Nyamu [aut, cre]
Maintainer: Martin Nyamu <analystnyamu79@gmail.com>
Repository: CRAN
Date/Publication: 2026-10-27 15:20:07 UTC

enhancedTtest: Enhanced T-Test with Automatic Selection and APA Formatting

Description

Provides enhanced t-test functionality with automatic assumption checking, non-parametric fallbacks, effect size calculation, and APA-formatted tables that can be exported to Word documents. Supports one-sample, two-sample, and paired t-tests with intelligent test selection. Effect size interpretations follow Cohen (1988) doi:10.4324/9780203771587 and APA formatting follows the Publication Manual of the American Psychological Association, 7th edition (2020) doi:10.1037/0000165-000.

Author(s)

Maintainer: Martin Nyamu analystnyamu79@gmail.com

Authors:


Calculate Effect Size for Any Test

Description

Calculate Effect Size for Any Test

Usage

calculate_effect_size(result)

Arguments

result

Test result object

Value

Effect size with interpretation


Complete Assumption Checking for All Test Types

Description

Complete Assumption Checking for All Test Types

Usage

check_complete_assumptions(data, response_var, group_var, test_type)

Arguments

data

Data frame

response_var

Name of response variable

group_var

Name of grouping variable (NULL for one-sample)

test_type

Character, "one_sample", "two_sample", or "paired"

Value

List with assumption check results


Check Homogeneity of Variance

Description

Check Homogeneity of Variance

Usage

check_homogeneity(
  data,
  response_var,
  group_var,
  method = "levene",
  alpha = 0.05
)

Arguments

data

Data frame

response_var

Name of response variable

group_var

Name of grouping variable

method

Character, "levene" or "bartlett"

alpha

Significance level

Value

List with variance homogeneity results


Check Normality with Multiple Methods

Description

Check Normality with Multiple Methods

Usage

check_normality(x, method = "shapiro", alpha = 0.05)

Arguments

x

Numeric vector

method

Character, "shapiro", "anderson", or "both"

alpha

Significance level

Value

List with normality check results


Complete T-Test Analysis with Automatic Selection

Description

Performs one-sample, two-sample, or paired t-tests with automatic non-parametric fallbacks when assumptions are violated. Handles input validation, assumption checking, effect size calculation, and produces APA-formatted output.

Usage

complete_ttest(
  data,
  formula,
  paired = FALSE,
  alternative = "two.sided",
  mu = 0,
  auto_select = TRUE,
  apa_table = TRUE,
  export_word = FALSE,
  filename = "ttest_results.docx"
)

Arguments

data

A data frame containing the variables.

formula

A formula specifying the model:

  • One-sample: response ~ 1

  • Two-sample: response ~ group

  • Paired: response ~ group with paired = TRUE

paired

Logical, whether to perform a paired t-test (default FALSE).

alternative

Character string specifying the alternative hypothesis. Must be one of "two.sided" (default), "less", or "greater".

mu

Numeric, the hypothesized mean for one-sample tests (default 0). Ignored for two-sample and paired tests.

auto_select

Logical, if TRUE (default) automatically selects a parametric or non-parametric test based on assumption checks (normality and homogeneity of variance). If FALSE, always performs the parametric test.

apa_table

Logical, if TRUE (default) creates an APA-formatted flextable object.

export_word

Logical, if TRUE exports the APA table to a Word document (default FALSE).

filename

Character string, output filename for Word export. Only used when export_word = TRUE.

Value

An object of class complete_ttest (also inheriting from enhanced_ttest), which is a named list containing the following components:

raw

The raw test result object returned by t.test or wilcox.test. Contains the test statistic, degrees of freedom, p-value, confidence interval, and estimates.

method

Character string naming the test performed (e.g., "Welch's t-test", "Mann-Whitney U test").

parametric

Logical; TRUE if a parametric test was used, FALSE if a non-parametric alternative was selected.

test_type

Character string indicating the test type: "one_sample", "two_sample", or "paired".

response_var

Character string with the name of the response variable from the formula.

group_var

Character string with the name of the grouping variable from the formula, or NULL for one-sample tests.

data

The processed data frame used in the analysis, after removing missing values and converting the grouping variable to a factor (if applicable).

alternative

Character string with the alternative hypothesis used.

mu

Numeric value of the hypothesized mean (for one-sample tests).

descriptive_stats

Data frame with descriptive statistics by group (or overall for one-sample tests). Contains columns: group, N, Mean, SD, SE for parametric tests; or group, N, Median, IQR for non-parametric tests.

effect_size

A named list describing the effect size with elements:

  • value: Numeric effect size value.

  • name: Character string, either "Cohen's d" (parametric) or "r" (non-parametric).

  • interpretation: Character string describing the magnitude (e.g., "Small", "Medium", "Large").

assumptions

A named list with results of assumption checks, including normality_passed, normality_p_value, variance_passed, variance_p_value, plus warnings and recommendations character vectors.

apa_table

A flextable object containing the publication-ready APA-formatted table, or NULL if apa_table = FALSE or table creation failed.

recommendation

Character string with a plain-language summary of the analysis, including the test method used, assumption check results, significance, and effect size interpretation.

call

The matched function call, for reproducibility.

The object has S3 methods print.complete_ttest and summary.complete_ttest for displaying results.

See Also

create_complete_apa_table for building APA tables, export_apa_to_word for Word export, format_p_value for formatting p-values.

Examples


# One-sample t-test: test if mean mpg differs from 20
result <- complete_ttest(mtcars, mpg ~ 1, mu = 20)
print(result)

# Two-sample t-test: compare Sepal.Length between two species
iris_subset <- iris[iris$Species != "virginica", ]
iris_subset$Species <- droplevels(iris_subset$Species)
result <- complete_ttest(iris_subset, Sepal.Length ~ Species)
summary(result)

# Access components
result$method          # Test name
result$raw$p.value     # p-value
result$effect_size     # Effect size with interpretation
result$apa_table       # APA-formatted flextable



Create APA Table (Alias)

Description

Alias for create_complete_apa_table.

Usage

create_apa_table(result)

Arguments

result

A complete_ttest result object

Value

A flextable object


Create APA Table for complete_ttest Object

Description

Creates a publication-ready APA-formatted table from a complete_ttest result object. Automatically selects the correct table format based on the test type (one-sample, two-sample, or paired) and whether the test was parametric or non-parametric.

Usage

create_complete_apa_table(result)

Arguments

result

A complete_ttest result object

Value

A flextable object, or NULL if descriptive statistics are not available

Examples


result <- complete_ttest(
  iris[iris$Species != "virginica", ],
  Sepal.Length ~ Species
)
create_complete_apa_table(result)


Create Complete Report in Word

Description

Generates a comprehensive Word document containing descriptive statistics, inferential tests, and interpretations for multiple outcome variables.

Usage

create_complete_report(
  data,
  formula_list,
  group_var,
  paired = FALSE,
  title = "Statistical Analysis Report",
  filename = "apa_report.docx",
  include_descriptives = TRUE,
  include_interpretations = TRUE
)

Arguments

data

A data frame containing the variables

formula_list

A list of formulas (e.g., list(y1 ~ group, y2 ~ group))

group_var

Character, name of the grouping variable

paired

Logical, whether to perform paired tests

title

Character, report title

filename

Character, output filename (should end in .docx)

include_descriptives

Logical, include descriptive statistics table

include_interpretations

Logical, include APA interpretations

Value

Invisibly returns the path to the created file

Examples


formulas <- list(
  Sepal.Length ~ Species,
  Sepal.Width ~ Species
)
tmp <- tempfile(fileext = ".docx")
data_subset <- iris[iris$Species != "virginica", ]
data_subset$Species <- droplevels(data_subset$Species)
create_complete_report(
  data = data_subset,
  formula_list = formulas,
  group_var = "Species",
  filename = tmp
)


Export APA Table to HTML

Description

Exports an APA-formatted flextable to an HTML file.

Usage

export_apa_to_html(
  ft,
  filename = "ttest_results.html",
  include_interpretation = TRUE,
  interpretation_text = NULL
)

Arguments

ft

A flextable object containing the APA-formatted table

filename

Character, output filename (should end in .html)

include_interpretation

Logical, include interpretation section

interpretation_text

Character, interpretation text to include

Value

Invisibly returns the path to the created file

Examples


result <- complete_ttest(
  iris[iris$Species != "virginica", ],
  Sepal.Length ~ Species
)
tmp <- tempfile(fileext = ".html")
export_apa_to_html(result$apa_table, tmp)


Export APA Table to Word

Description

Exports an APA-formatted flextable to a Word document with proper formatting. Attempts to use flextable::save_as_docx() first, with a fallback to officer for older flextable versions.

Usage

export_apa_to_word(
  apa_table,
  filename = "ttest_results.docx",
  title = "T-Test Results"
)

Arguments

apa_table

A flextable object containing the APA-formatted table

filename

Character, output filename (should end in .docx)

title

Character, optional title for the document

Value

Invisibly returns the path to the created file

Examples


result <- complete_ttest(
  iris[iris$Species != "virginica", ],
  Sepal.Length ~ Species
)
tmp <- tempfile(fileext = ".docx")
export_apa_to_word(result$apa_table, tmp)


Format p-value for APA style

Description

Format p-value for APA style

Usage

format_p_value(p, include_stars = TRUE)

Arguments

p

Numeric p-value

include_stars

Logical, include significance stars (default TRUE)

Value

Character string with formatted p-value

Examples

format_p_value(0.0001)
format_p_value(0.03)
format_p_value(0.5)

Generate random test data

Description

Generate random test data

Usage

generate_test_data(
  n = 50,
  mean = 10,
  sd = 2,
  group1_name = "A",
  group2_name = "B",
  seed = 123
)

Arguments

n

Sample size per group (default 50)

mean

Mean of first group (default 10)

sd

Standard deviation (default 2)

group1_name

Name of first group (default "A")

group2_name

Name of second group (default "B")

seed

Random seed (default 123)

Value

A data frame with columns value and group

Examples

df <- generate_test_data()

Interpret Cohen's d

Description

Interpret Cohen's d

Usage

interpret_cohens_d(d)

Arguments

d

Numeric Cohen's d value

Value

Character string with interpretation

Examples

interpret_cohens_d(0.3)

Interpret r (for non-parametric tests)

Description

Interpret r (for non-parametric tests)

Usage

interpret_r(r)

Arguments

r

Numeric r value

Value

Character string with interpretation

Examples

interpret_r(0.4)

Print method for complete_ttest objects

Description

Formats and prints a complete_ttest object to the console in a human-readable format. The output includes the test type, method used, assumption check results, descriptive statistics, test statistics, effect size, and (if present) the APA-formatted table.

Usage

## S3 method for class 'complete_ttest'
print(x, ...)

Arguments

x

A complete_ttest object returned by complete_ttest.

...

Additional arguments passed to print. Currently ignored.

Value

Invisibly returns the input object x, unchanged. This function is called primarily for its side effect of printing a formatted summary of the t-test analysis to the console.

The printed output includes:

See Also

summary.complete_ttest for a condensed summary with an APA-style interpretation, complete_ttest for the main analysis function.

Examples


result <- complete_ttest(mtcars, mpg ~ 1, mu = 20)
print(result)



Summary method for complete_ttest objects

Description

Provides a condensed summary of a complete_ttest object, including all the information shown by print.complete_ttest plus a plain-language, APA-style interpretation of the results.

Usage

## S3 method for class 'complete_ttest'
summary(object, ...)

Arguments

object

A complete_ttest object returned by complete_ttest.

...

Additional arguments passed to summary. Currently ignored.

Value

Invisibly returns the input object object, unchanged. This function is called primarily for its side effect of printing a detailed summary of the t-test analysis to the console.

The printed output includes everything from print.complete_ttest plus:

See Also

print.complete_ttest, complete_ttest.

Examples


result <- complete_ttest(mtcars, mpg ~ 1, mu = 20)
summary(result)


These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.