Package {autotestR}


Title: Automated Functions for Basic Statistical Tests
Version: 1.3.0
Description: Provides simple and intuitive functions for basic statistical analyses. Methods include the t-test (Student 1908 <doi:10.1093/biomet/6.1.1>), the Mann-Whitney U test (Mann and Whitney 1947 <doi:10.1214/aoms/1177730491>), Pearson's correlation (Pearson 1895 <doi:10.1098/rspl.1895.0041>), and analysis of variance (Fisher 1925, <doi:10.1007/978-1-4612-4380-9_5>). Functions are compatible with 'ggplot2' and 'dplyr'.
License: MIT + file LICENSE
Depends: R (≥ 4.1.0)
Encoding: UTF-8
RoxygenNote: 7.3.2
Imports: car, crayon, dplyr, FSA, ggplot2, ggdist, ggExtra, nortest, purrr, RColorBrewer, scales, stats, tibble, tidyr, tidyselect, utils, vcd
NeedsCompilation: no
Maintainer: Luiz Garcia <luiz.cardoso@ufpr.br>
Packaged: 2026-10-26 17:27:38 UTC; Seu Computador
Author: Luiz Garcia ORCID iD [aut, cre]
Repository: CRAN
Date/Publication: 2026-10-26 18:00:08 UTC

autotestR

Description

designed to simplify the execution of the main statistical tests commonly used in the life sciences. It provides user-friendly functions that automatically generate plots and clear explanations, making statistical analysis more accessible for researchers and students.

Main features

Basic usage

library(autotestR)

Independent t test

group1 <- rnorm(30, 10, 2) group2 <- rnorm(30, 12, 2) test_t(group1, group2)

Chi-squared test

var1 <- sample(c("A", "B"), 100, replace = TRUE) var2 <- sample(c("Yes", "No"), 100, replace = TRUE) test_chi(var1, var2)

Multiple test (t test or Mann–Whitney)

df <- data.frame( control = rnorm(30, 10), treatment = rnorm(30, 12), test1 = rnorm(30, 11), test2 = rnorm(30, 15) ) test_t_multi(df)

ANOVA with post hoc test

g1 <- rnorm(20, 5) g2 <- rnorm(20, 7) g3 <- rnorm(20, 6) test_anova(g1, g2, g3)

Correlation test

x <- rnorm(30) y <- x + rnorm(30, 0, 1) test_correlation(x, y)

Author(s)

Maintainer: Luiz Garcia luiz.cardoso@ufpr.br (ORCID)


pre_test — Automatic statistical test suggestion

Description

Automatically identifies whether the input data are numeric or categorical and suggests the most appropriate statistical test.

Usage

pre_test(..., alpha = 0.05, help = FALSE, verbose = TRUE)

Arguments

...

Two or more vectors (numeric or categorical), or a data.frame with >= 2 columns

alpha

Significance level. Default = 0.05

help

Logical. If TRUE, shows detailed help

verbose

Logical. If TRUE, prints informative messages

Value

Invisible list with normality results, homogeneity or contingency table, and test recommendation


ANOVA test with automated assumption checking

Description

Performs ANOVA (and Tukey HSD) if data meet normality and homogeneity assumptions. Otherwise, automatically recommends Kruskal-Wallis/Dunn.

Usage

test_anova(
  ...,
  title = "ANOVA/Tukey HSD",
  xlab = "Group",
  ylab = "Value",
  style = c("boxplot", "violin", "mono", "halfeye"),
  help = FALSE,
  verbose = TRUE
)

Arguments

...

Vectors or a data.frame with >= 2 columns.

title

Plot title.

xlab

X-axis label.

ylab

Y-axis label.

style

Aesthetic style of the generated plot.

help

If TRUE, shows help.

verbose

If TRUE, shows detailed messages.

Value

An aov object or a recommendation message.

Examples

df <- data.frame(
  control = rnorm(30, 10),
  treatment = rnorm(30, 12),
  test = rnorm(30, 11)
)
test_anova(df)

Chi-square test

Description

Applies the Pearson chi-square test or Fisher's exact test to assess association between two categorical variables.

Usage

test_chi(
  x,
  y = NULL,
  title = "Chi-square Test",
  xlab = NULL,
  ylab = "Proportion",
  style = c("stacked", "barplot", "mosaic", "pie"),
  colors = NULL,
  show_table = TRUE,
  help = FALSE,
  verbose = TRUE
)

Arguments

x

Categorical vector or data frame with two columns group 1 and group 2.

y

Categorical vector (group 2). Required if x is a vector.

title

Plot title (string). Default: "Chi-square Test".

xlab

X-axis label in the plot (string). Default: NULL (uses variable name).

ylab

Y-axis label in the plot (string). Default: "Proportion".

style

Plot style generated by the function.

colors

Character. Optional plot colors.

show_table

Logical. If TRUE, prints the contingency table to the console. Default: TRUE.

help

Logical. If TRUE, displays a detailed explanation of the function. Default: FALSE.

verbose

Logical. If TRUE, prints messages about the test and expected frequencies. Default: TRUE.

Value

Test result and contingency table.

Examples


data <- data.frame(
  control = c(rep("healthy", 50), rep("sick", 150)),
  treatment = c(rep("healthy", 100), rep("sick", 100))
)
test_chi(data)

Correlation Analysis with Automatic Method Selection

Description

Performs correlation analysis between two numeric variables using Pearson, Spearman, or Kendall methods. When method = "auto", the function automatically selects the most appropriate method based on normality, presence of ties, and proportion of outliers.

Usage

test_correlation(
  x,
  y = NULL,
  style = c("simple", "inference", "structure", "density", "distribution"),
  method = "auto",
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  plot_normality = FALSE,
  line_col = NULL,
  point_col = NULL,
  ci_fill = NULL,
  help = FALSE,
  verbose = TRUE
)

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

Arguments

x

Numeric vector or data frame with exactly two numeric columns.

y

Numeric vector (optional if x is a data frame).

style

Plot style: "simple" (default), "inference", "structure", "density", or "distribution".

method

Correlation method: "auto" (default), "pearson", "spearman", or "kendall".

main

Plot title. If NULL, an automatic title is generated. If FALSE, no title is displayed.

xlab

Label for the x-axis. If NULL, a label is inferred from the input. If FALSE, no label is shown.

ylab

Label for the y-axis. If NULL, a label is inferred from the input. If FALSE, no label is shown.

plot_normality

Logical. If TRUE, displays QQ-plots for normality assessment.

line_col

Character. Optional fitted line color. Default: "#2F5D8A".

point_col

Character. Optional point color. Default: "grey40".

ci_fill

Character. Optional confidence interval area. Default: "#2F5D8A".

help

Logical. If TRUE, displays a detailed usage guide.

verbose

Logical. If TRUE, prints information about method selection and diagnostics.

...

Additional arguments passed to other print methods (currently ignored)

Details

In addition to hypothesis testing, the function provides diagnostic information, effect size interpretation, and publication-ready visualizations.

Method selection in automatic mode follows these rules:

Normality is assessed using Shapiro-Wilk (n <= 50), Anderson-Darling (50 < n <= 300), or Kolmogorov-Smirnov (n > 300) tests.

Value

An object of class "test_correlation" containing:

See Also

cor.test, ggplot

Examples

# Pearson (approximately normal data)
set.seed(123)
x <- rnorm(50, sd = 0.1)
y <- x + rnorm(50, sd = 0.1)
test_correlation(x, y)

# Spearman (non-normal data)
set.seed(123)
x <- runif(300)
y <- log(x + 0.1) + rnorm(300, sd = 0.5)
test_correlation(x, y)

# Kendall (ties and outliers)
set.seed(123)
x <- runif(1000, 1, 100)
y <- sin(x) * 30 + rnorm(1000, 0, 10)
x[sample(1:500, 50)] <- 50
y[sample(1:500, 50)] <- 0
x_out <- runif(100, 10, 20)
y_out <- runif(100, 80, 120)
x <- c(x, x_out)
y <- c(y, y_out)
test_correlation(x, y)


Fisher's Exact Test

Description

Performs Fisher's Exact Test using two categorical vectors or a data frame with two columns, constructing a contingency table and optionally generating graphical visualizations.

Usage

test_fisher(
  x,
  y = NULL,
  title = "Fisher's Exact Test",
  xlab = NULL,
  ylab = NULL,
  style = c("stacked", "barplot", "mosaic", "pie"),
  colors = NULL,
  show_table = TRUE,
  help = FALSE,
  verbose = TRUE
)

Arguments

x

Categorical vector or data frame with two columns.

y

Categorical vector (required if x_var is a vector).

title

Plot title (string). Default: "Fisher's Exact Test"

xlab

Name of the x-axis in the plot (string). Default: NULL (uses variable name).

ylab

Name of the y-axis in the plot (string). Default: "Proportion".

style

Plot style. Controls the visualization type.

colors

Character. Optional plot colors.

show_table

Logical. If TRUE, prints the contingency table to the console. Default: TRUE.

help

Logical. If TRUE, shows detailed function explanation. Default: FALSE.

verbose

Logical. If TRUE, prints detailed test messages. Default: TRUE.

Value

Invisible object containing the Fisher test result.

Examples

data <- data.frame(control = c(rep("healthy", 1), rep("sick", 5)),
                   treatment = c(rep("healthy", 5), rep("sick", 1)))
test_fisher(data)

Test for interaction between a continuous predictor and a grouping variable

Description

Fits a linear model of the form y ~ x * by to evaluate whether the association between a continuous predictor and an outcome differs across groups. Optionally produces a publication-ready visualization of group-specific regression lines.

Usage

test_interaction(
  y,
  x,
  by,
  title = NULL,
  xlab = NULL,
  ylab = NULL,
  plot = TRUE,
  style = c("clean", "CI", "facet"),
  conf.level = 0.95,
  colors = NULL,
  verbose = TRUE,
  help = FALSE
)

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

Arguments

y

Numeric vector representing the continuous predictor.

x

Numeric vector representing the continuous outcome.

by

Grouping variable defining the interaction. Must be coercible to a factor with at least two levels.

title

Optional title title for the plot.

xlab

Optional x-axis label.

ylab

Optional y-axis label.

plot

Logical. Should a plot be generated?

style

Plot style. One of "clean", "CI" or "facet".

conf.level

Confidence level for the interaction interval (default: 0.95).

colors

Character. Optional point and line colors.

verbose

Logical. If TRUE, prints detailed messages. Default: TRUE.

help

Logical. If TRUE, shows a detailed explanation of the function. Default: FALSE.

...

Additional arguments passed to other print methods (currently ignored)

Details

The interaction coefficient (\beta) represents the difference in regression slopes between groups, conditional on the reference level of by. The sign and magnitude of this coefficient depend on the chosen reference group.

Confidence intervals are emphasized as the primary inferential quantity.

Value

An object of class "test_interaction" containing:

Examples


# Simple example: different trends between groups

set.seed(125)

n <- 60
df_bio <- data.frame(
  response = rnorm(n, mean = 10, sd = 2),
  group    = rep(c('Control', 'Treatment'), each = n / 2)
)

df_bio$marker <- with(
  df_bio,
  ifelse(
    group == 'Control',
    2 + 1.3 * response + rnorm(n, 0, 2),
    2 + 1.2 * response + rnorm(n, 0, 1)
  )
)

test_interaction(
  x  = df_bio$marker,
  y  = df_bio$response,
  by = df_bio$group)


Kruskal-Wallis Test with Dunn Post-hoc

Description

Performs the Kruskal-Wallis rank-sum test for comparing three or more independent groups, followed by Dunn's post-hoc test with multiple comparison adjustment.

Usage

test_kruskal(
  ...,
  title = "Kruskal-Wallis + Dunn",
  xlab = "Group",
  ylab = "Value",
  style = c("boxplot", "violin", "mono", "halfeye"),
  adjust = c("bonferroni", "holm", "bh"),
  colors = NULL,
  help = FALSE,
  verbose = TRUE
)

Arguments

...

Numeric vectors representing groups, or a data frame with two or more columns (each column is treated as a group).

title

Character. Plot title.

xlab

Character. X-axis label.

ylab

Character. Y-axis label.

style

Character. Plot style. One of: "boxplot", "violin", "mono", or "halfeye".

adjust

Character. Method for p-value adjustment in Dunn's test. One of "bonferroni", "holm", or "bh".

colors

Character. Optional box colors.

help

Logical. If TRUE, displays a short help message and exits.

verbose

Logical. If TRUE, prints formatted statistical results to the console.

Details

This function is a non-parametric alternative to one-way ANOVA and is recommended when normality or homoscedasticity assumptions are violated.

Value

Invisibly returns a list with the following components:

type

Test type.

H

Kruskal-Wallis H statistic.

df

Degrees of freedom.

p

Global test p-value.

epsilon_sq

Epsilon-squared effect size.

epsilon_ci

Bootstrap confidence interval for effect size.

means_sd

Group means and standard deviations.

dunn

Dunn post-hoc results.

significant_pairs

Significant pairwise comparisons.

data

Long-format data used in the analysis.

Examples

set.seed(123)

n <- 25

df <- data.frame(
  control    = rexp(n, rate = 1),
  treatment1 = rexp(n, rate = 0.6),
  treatment2 = rgamma(n, shape = 2, scale = 1)
)

test_kruskal(df)


Student's t-test (with automatic diagnostics)

Description

Performs Student's t-test to compare the means of two independent groups, with automatic checks for normality and homogeneity of variances. If the assumptions are violated, the Mann-Whitney U test is applied automatically, without generating a plot.

Usage

test_t(
  ...,
  title = TRUE,
  title_text = "t-test",
  xlab = "Group",
  ylab = "Value",
  style = c("boxplot", "violin", "mono", "halfeye"),
  colors = NULL,
  help = FALSE,
  verbose = TRUE
)

Arguments

...

Two numeric vectors or a data frame containing exactly two columns.

title

Logical. If TRUE, adds a title to the plot.

title_text

Character string specifying the plot title. Default: t-test.

xlab

Character string specifying the x-axis label. Default: Group.

ylab

Character string specifying the y-axis label. Default: Value.

style

Character string specifying the plot style generated by the function. One of boxplot, violin, mono, or halfeye. Default: boxplot.

colors

Optional character vector specifying the box colors.

help

Logical. If TRUE, displays a detailed explanation of the function. Default: FALSE.

verbose

Logical. If TRUE, prints detailed messages. Default: TRUE.

Value

An object of class test_t containing the following components:

Examples

set.seed(123)
df <- data.frame(
  control = rnorm(30, mean = 10),
  treatment = rnorm(30, mean = 15)
)
test_t(df)

Paired t-test with advanced visualizations

Description

Performs a paired t-test to compare the means of two related measurements, such as before-and-after observations, using two numeric vectors of equal length or two numeric columns from a data frame. Includes four visualization styles: boxplot, violin, mono, and halfeye.

Usage

test_t_paired(
  ...,
  title = "Paired t-test",
  xlab = "",
  ylab = "Value",
  style = c("boxplot", "violin", "mono", "halfeye"),
  colors = NULL,
  connect = TRUE,
  help = FALSE,
  verbose = TRUE
)

Arguments

...

Two numeric vectors of equal length, or a data frame containing exactly two numeric columns.

title

Character string specifying whether to display a plot title or providing the title text, depending on the function implementation.

xlab

Character string specifying the x-axis label.

ylab

Character string specifying the y-axis label.

style

Character string specifying the plot style generated by the function. One of boxplot, violin, mono, or halfeye. Default: boxplot.

colors

Optional character vector specifying the plot colors.

connect

Logical. If TRUE, connects paired observations in the plot.

help

Logical. If TRUE, displays a detailed explanation of the function.

verbose

Logical. If TRUE, prints progress messages.

Value

An invisible list containing the following components:

summary_table

Summary statistics, including group means and standard deviations.

test_result

Result object returned by stats::t.test, containing the paired t-test results.

data

Data frame containing the data used for plotting.

plot

Plot object generated using ggplot2.

Examples

before <- c(13, 12, 15, 14)
after <- c(9, 11, 10, 10)
test_t_paired(before, after)

Multiple pairwise comparisons with diagnostics

Description

Performs multiple pairwise comparisons using Student's t-test or the Mann-Whitney U test, with automatic diagnostic checks, effect size estimation, confidence intervals, multiple testing correction, and visualization.

Usage

test_tmulti(
  ...,
  comparisons = NULL,
  title = "Multiple comparisons (t / MW)",
  xlab = "",
  ylab = "Value",
  style = c("boxplot", "violin", "mono", "halfeye"),
  p_adjust = c("none", "holm", "BH", "bonferroni"),
  colors = NULL,
  help = FALSE,
  verbose = TRUE
)

Arguments

...

Numeric vectors or a data frame containing groups in columns.

comparisons

Optional list of character vectors specifying pairwise comparisons between groups. Each element should contain two group names, such as c("A", "B"). If NULL, all pairwise combinations are used.

title

Plot title.

xlab

Character string specifying the x-axis label.

ylab

Character string specifying the y-axis label.

style

Character string specifying the plot style generated by the function. One of boxplot, violin, mono, or halfeye. Default: boxplot.

p_adjust

Character string specifying the method used for multiple testing correction. Supported methods include none, holm, BH, and bonferroni.

colors

Optional character vector specifying the box colors.

help

Logical. If TRUE, displays usage examples.

verbose

Logical. If TRUE, prints results and plots.

Details

Normality is assessed using the Shapiro-Wilk test, and homogeneity of variances is assessed using Levene's test. When the assumptions are met, a pooled-variance Student's t-test is used. Otherwise, the Mann-Whitney U test is applied with bootstrap confidence intervals.

Effect sizes are calculated as follows:

Value

A list containing the following components:

results

A tibble containing the pairwise test results.

plot

A plot object generated using ggplot2.

data_long

Long-format data used for plotting.

Examples

set.seed(123)
df <- data.frame(
  control = rnorm(30, mean = 10),
  treatment = rnorm(30, mean = 12),
  test1 = rnorm(30, mean = 11),
  test2 = rnorm(30, mean = 15)
)

test_tmulti(
  df,
  comparisons = list(
    c("control", "treatment"),
    c("treatment", "test1")
  )
)


Mann-Whitney U Test

Description

Performs the Mann-Whitney U test (Wilcoxon rank-sum test) to compare two independent groups, providing a statistical summary and graphical visualization.

Usage

test_u(
  ...,
  title = "Mann-Whitney Test",
  xlab = "Group",
  ylab = "Value",
  style = c("boxplot", "violin", "mono", "halfeye"),
  colors = NULL,
  help = FALSE,
  verbose = TRUE
)

Arguments

...

Two numeric vectors or a data frame containing exactly two numeric columns.

title

Character string specifying the plot title. Default: Mann-Whitney Test.

xlab

Character string specifying the x-axis label. Default: Group.

ylab

Character string specifying the y-axis label. Default: Value.

style

Character string specifying the plot style generated by the function. One of boxplot, violin, mono, or halfeye. Default: boxplot.

colors

Optional character vector specifying the plot colors.

help

Logical. If TRUE, displays a detailed explanation of the function. Default: FALSE.

verbose

Logical. If TRUE, prints detailed messages. Default: TRUE.

Value

An invisible list containing the following components:

summary

Group-wise descriptive statistics.

test

An object of class htest containing the Mann-Whitney U test results.

plot

A plot object generated using ggplot2.

Examples

x <- c(1, 3, 5, 6)
y <- c(7, 8, 9, 12)
data <- data.frame(groupA = x, groupB = y)
test_u(data)