| Title: | One-Way Statistical Analyses |
| Version: | 0.0.2 |
| Description: | Performs one-way tests of assumptions (normality and homoscedasticity), analysis of variance, robust and nonparametric alternatives, multiple comparison procedures, effect size estimators, confidence intervals, and descriptive summaries. Functions are designed with a consistent interface to support reproducible and user-friendly statistical workflows. For more details see Howell (2010, ISBN:978-0-495-59784-1), Zar (2014, ISBN:978-0-13-100846-5), Hollander et al. (2014, ISBN:978-0-470-38737-5), Montgomery (2017, ISBN:978-1-119-11347-8), Lakens (2013) <doi:10.3389/fpsyg.2013.00863>, and Piepho (2004) <doi:10.1198/1061860043515>. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/P10911004-NPUST/oneway |
| BugReports: | https://github.com/P10911004-NPUST/oneway/issues |
| Encoding: | UTF-8 |
| Imports: | normality, outlying, varequal |
| Suggests: | ggplot2, testthat (≥ 3.0.0) |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-08 03:40:01 UTC; ABRC |
| Author: | Joon-Keat Lai |
| Maintainer: | Joon-Keat Lai <p10911004@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-15 13:20:02 UTC |
Effect size
Description
Calculate Cohen's d and Hedges' g introduced in Lakens (2013).
Usage
Cohen_d_s(
y1,
y2,
alternative = "two.sided",
alpha = 0.05,
mu = 0,
return_CI = FALSE
)
Hedges_g_s(
y1,
y2,
alternative = "two.sided",
alpha = 0.05,
mu = 0,
return_CI = FALSE
)
Arguments
y1 |
A numeric vector. |
y2 |
A numeric vector. |
alternative |
Character (default: |
alpha |
Numeric (default: 0.05). Significance level (0 - 1) for hypothesis testing. |
mu |
Numeric (default: 0). |
return_CI |
Logical (default: FALSE). Whether to return the confidence interval of the effect size. |
Details
Refer to Lakens (2013), the Cohen's d is the formula 1, the Hedges' g is the formula 4.
Their confidence interval (CI) were calculated based on formula 2, by transforming the d and g
back to t to fit the general confidence interval calculation.
For detailed and precise CI estimates, please use the effectsize package.
Value
A numeric scalar or a numeric vector of length 3, depends on return_CI.
References
Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4. https://doi.org/10.3389/fpsyg.2013.00863
Dunn's multiple comparison test
Description
Performs Dunn's multiple comparison procedure for all pairwise comparisons of groups following a significant Kruskal-Wallis test.
Usage
Dunn_test(
data,
formula = NULL,
alpha = 0.05,
p_adjust_method = "holm",
rounding = 4,
verbose = TRUE
)
Arguments
data |
A data frame, or an object returned by |
formula |
A two-sided formula specifying the response and grouping variables in the form
|
alpha |
A numeric value between 0 and 1 specifying the significance level.
The default is |
p_adjust_method |
A character string specifying the method used to adjust p-values for
multiple comparisons. Must be one of |
rounding |
An integer specifying the number of decimal places to display in the output.
The default is |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
Dunn's test is a nonparametric post hoc procedure that compares group mean ranks after a significant Kruskal-Wallis test. The test statistic follows a normal approximation with an adjustment for tied ranks when ties are present.
Because multiple pairwise comparisons are performed, p-values should be adjusted to control
the family-wise error rate or false discovery rate. The adjustment method is specified by
p_adjust_method and is passed to stats::p.adjust().
If the data satisfy the assumptions of one-way ANOVA, parametric procedures such as
Tukey_HSD_test(), REGWQ_test(), or Games_Howell_test() may be more appropriate.
Value
A list containing the following components:
- method
The name of the statistical procedure.
- data
The input data used in the analysis.
- pre_hoc
The Kruskal-Wallis test results.
- post_hoc
Results of all pairwise Dunn comparisons, including differences in mean ranks, confidence intervals, Z statistics, unadjusted and adjusted p-values, and effect sizes.
- summary
Descriptive statistics for each group, including compact letter displays (CLD).
References
Dinno, A. (2015). Nonparametric Pairwise Multiple Comparisons in Independent Groups using Dunn’s Test. The Stata Journal: Promoting Communications on Statistics and Stata, 15(1), 292-300. https://doi.org/10.1177/1536867X1501500117
Zar, J. H. (2014). Biostatistical analysis (5th edition). Pearson. Chapter 11: Multiple comparisons, pg. 255-256.
Examples
out <- Dunn_test(X_X_O, val ~ grp)
Games-Howell multiple comparison test
Description
Performs the Games-Howell multiple comparison procedure for all pairwise comparisons of group means. The Games-Howell test does not assume equal variances or equal sample sizes and is commonly used following a one-way analysis of variance when the homogeneity of variance assumption is violated.
Usage
Games_Howell_test(
data,
formula = NULL,
alpha = 0.05,
rounding = 4,
verbose = TRUE
)
Arguments
data |
A data frame, or an object returned by |
formula |
A two-sided formula specifying the response and grouping variables in the form
|
alpha |
A numeric value between 0 and 1 specifying the significance level.
The default is |
rounding |
An integer specifying the number of decimal places to display in the output.
The default is |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
The Games-Howell test is based on the studentized range distribution and uses Welch-Satterthwaite degrees of freedom for each pairwise comparison. Unlike Tukey's HSD test, it does not require equal variances or balanced sample sizes.
Value
A list containing the following components:
- method
The name of the statistical procedure.
- data
The input data used in the analysis.
- pre_hoc
The one-way analysis of variance results.
- post_hoc
Results of all pairwise Games-Howell comparisons, including mean differences, confidence intervals, test statistics, adjusted p-values, and effect sizes.
- summary
Descriptive statistics for each group, including compact letter displays (CLD).
References
Howell, D. C. (2013). Statistical Methods for Psychology (8th ed.). Cengage Learning. Chapter 12: Multiple comparisons among treatment means, Section 12.7: Tukey's test, pg. 395.
Zar, J. H. (2014). Biostatistical analysis (5th ed.). Pearson. Chapter 11: Multiple comparisons, pg. 246.
Examples
out <- Games_Howell_test(O_X_X, val ~ grp)
Kruskal–Wallis one-way analysis of variance by ranks
Description
Performs the Kruskal–Wallis rank-sum test for comparing the distributions of two or more independent groups. The test is a nonparametric alternative to one-way ANOVA and is based on the ranks of the observations rather than their original values.
Usage
Kruskal_Wallis_test(data, formula, alpha = 0.05, rounding = 4, verbose = TRUE)
Arguments
data |
A data frame containing the response and grouping variables. |
formula |
A two-sided formula specifying the response and grouping variables. |
alpha |
Numeric (default: 0.05). Significance level (range from 0 to 1). |
rounding |
Integer (default: 4). Number of decimal places displayed in the output. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
The Kruskal–Wallis test ranks all observations across groups and tests whether the mean ranks differ among groups. Under the null hypothesis, the test statistic approximately follows a chi-squared distribution with k - 1 degrees of freedom, where k is the number of groups. A correction for tied ranks is applied when ties are present.
Unlike classical one-way ANOVA, the Kruskal–Wallis test is not derived from a decomposition of variance into between-group and within-group sums of squares. Consequently, residual sums of squares and residual mean squares are not defined in the classical procedure.
Value
A data frame summarizing the Kruskal–Wallis test result in an ANOVA-like table:
- DF
Degrees of freedom.
- SS
Rank-based between-group sum of squares. Residual and total sums of squares are not defined for the classical Kruskal–Wallis test and are therefore returned as NA.
- MS
Rank-based mean square (SS / DF). Only the between-group value is defined.
- H
Observed Kruskal–Wallis H statistic.
- Hcrit
Critical chi-squared value at the specified significance level.
- Pvalue
P-value associated with the H statistic.
- signif
Significance code corresponding to the p-value.
- p_omega2
Effect size (currently returned as NA).
- method
Statistical method ("Kruskal-Wallis").
The rows correspond to the between-group effect ("Group"), residuals ("Residuals"), and total ("Total"). Only the between-group row contributes to the Kruskal–Wallis test statistic.
References
Kruskal, W. H., & Wallis, W. A. (1952). Use of ranks in one-criterion variance analysis. Journal of the American Statistical Association, 47(260), 583–621.
Howell, D. C. (2013). Statistical methods for psychology (8th edition). Cengage. Chapter 18, Section 18.9, pg. 678-679.
Hollander, M., Wolfe, D. A., & Chicken, E. (2014). Nonparametric Statistical Methods (3rd ed.). Wiley. Chapter 6, pg. 204-206.
Examples
lst <- list(
"depressant" = c(55, 0, 1, 0, 50, 60, 44),
"stimulant" = c(73, 85, 51, 63, 85, 85, 66, 69),
"placebo" = c(61, 54, 80, 47)
)
normality::is_normal(lst)
Kruskal_Wallis_test(lst)
Kruskal_Wallis_test(anorexia, weight_gain ~ therapy)
Ryan-Einot-Gabriel-Welsch Studentized Range (REGWQ) test
Description
Performs the Ryan-Einot-Gabriel-Welsch Studentized Range (REGWQ) multiple comparison procedure for all pairwise comparisons of group means following a one-way analysis of variance. REGWQ is a stepwise procedure based on the studentized range distribution that generally provides greater statistical power than Tukey's HSD while maintaining strong control of the family-wise error rate under balanced designs.
Usage
REGWQ_test(data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE)
Arguments
data |
A data frame, or an object returned by |
formula |
A two-sided formula specifying the response and grouping variables in the form
|
alpha |
A numeric value between 0 and 1 specifying the significance level.
The default is |
rounding |
An integer specifying the number of decimal places to display in the output.
The default is |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
The REGWQ procedure is a stepwise multiple comparison method based on the studentized range distribution. Group means are first ordered, after which pairwise comparisons are performed using significance levels that depend on the number of ordered means spanned by each comparison. This adaptive strategy generally yields greater statistical power than Tukey's HSD while maintaining control of the family-wise error rate.
The procedure assumes that observations are independent, residuals are approximately normally
distributed, and population variances are equal. It is intended primarily for balanced one-way
designs. When sample sizes are unequal but variances remain homogeneous, consider using
Tukey_Kramer_test(). When variances are unequal, consider using Games_Howell_test().
Value
A list containing the following components:
- method
The name of the statistical procedure.
- data
The input data used in the analysis.
- pre_hoc
The one-way analysis of variance results.
- post_hoc
Results of all pairwise REGWQ comparisons, including mean differences, confidence intervals, studentized range statistics, p-values, modified significance levels, and effect sizes.
- summary
Descriptive statistics for each group, including compact letter displays (CLD).
References
Howell, D. C. (2010). Statistical Methods for Psychology (7th ed.). Cengage Learning. Chapter 12: Multiple comparisons among treatment means, Section 12.6: Post hoc comparisons, pg. 393-394.
Examples
out <- REGWQ_test(morphine, tolerance ~ grp)
Tukey's Honestly Significant Difference (Tukey-HSD) test
Description
Performs Tukey's Honestly Significant Difference (HSD) multiple comparison procedure for all pairwise comparisons of group means following a one-way analysis of variance. The Tukey-HSD test controls the family-wise error rate and is appropriate when the assumptions of normality, homogeneity of variances, and balanced group sizes are reasonably satisfied.
Usage
Tukey_HSD_test(
data,
formula = NULL,
alpha = 0.05,
rounding = 4,
verbose = TRUE
)
Arguments
data |
A data frame, or an object returned by |
formula |
A two-sided formula specifying the response and grouping variables in the form
|
alpha |
A numeric value between 0 and 1 specifying the significance level.
The default is |
rounding |
An integer specifying the number of decimal places to display in the output.
The default is |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
Tukey's HSD test is based on the studentized range distribution and assumes
equal variances across groups. It provides simultaneous confidence intervals
and adjusted p-values that control the family-wise error rate for all
pairwise comparisons.
This implementation is intended primarily for balanced one-way designs. When sample sizes are
unequal but variances remain homogeneous, consider using Tukey_Kramer_test(). When variances
are unequal, consider using Games_Howell_test().
Value
A list containing the following components:
- method
The name of the statistical procedure.
- data
The input data used in the analysis.
- pre_hoc
The one-way analysis of variance results.
- post_hoc
Results of all pairwise Tukey-HSD comparisons, including mean differences, confidence intervals, studentized range statistics, adjusted p-values, and effect sizes.
- summary
Descriptive statistics for each group, including compact letter displays (CLD).
References
Howell, D. C. (2013). Statistical Methods for Psychology (8th ed.). Cengage Learning. Chapter 12: Multiple comparisons among treatment means, Section 12.7: Tukey's test, pg. 394.
Zar, J. H. (2014). Biostatistical analysis (5th edition). Pearson. Chapter 11: Multiple comparisons, pg. 241-243.
Examples
out <- Tukey_HSD_test(O_O_O, val ~ grp)
Tukey-Kramer test
Description
Represent significance statements resulting from all-pairwise comparisons.
Usage
Tukey_Kramer_test(
data,
formula = NULL,
alpha = 0.05,
rounding = 4,
verbose = TRUE
)
Arguments
data |
A data frame in which the variables specified in the formula will be found. |
formula |
A formula specifying the model. |
alpha |
Numeric value range from 0 to 1 (default: 0.05). The error tolerance. |
rounding |
Integer (default: 4). Rounding digits. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Value
A list with 4 elements:
- method
Statistical procedures that were conducted.
- data
The input data and possibly other transformed data.
- pre_hoc
a priori test result.
- post_hoc
Post-hoc test result.
- summary
Descriptive statistics.
References
Howell, D. C. (2013). Statistical Methods for Psychology (8th ed.). Cengage Learning. Chapter 12: Multiple comparisons among treatment means, Section 12.7: Tukey's test, pg. 394.
Zar, J. H. (2014). Biostatistical analysis (5th edition). Pearson. Chapter 11: Multiple comparisons, pg. 244-245.
Examples
out <- Tukey_Kramer_test(O_O_X, val ~ grp)
Weight Gain Following Therapy for Anorexia
Description
A dataset containing weight gain for young girls with anorexia following three different treatment conditions: a control group, cognitive-behavior therapy, and family therapy. The response variable is weight gain measured after treatment.
Usage
anorexia
Format
A data frame with 72 observations and 2 variables:
- therapy
A factor indicating the treatment group with three levels:
"control","cognitive", and"family".- weight_gain
A numeric vector giving the observed weight gain after treatment.
Group sample sizes are:
Control: 26
Cognitive-behavior therapy: 29
Family therapy: 17
References
Howell, D. C. (2013). Statistical methods for psychology (8th ed.). Cengage. Chapter 11, Table 11.5, pg. 342.
Compact Letter Display (CLD)
Description
Represent significance statements resulting from all-pairwise comparisons.
Usage
compact_letter_display(
x1,
x2,
pvalues,
grp_names,
centers,
alpha = 0.05,
descending = TRUE,
display_letters = base::letters,
display_null_letter = "",
misc = FALSE
)
Arguments
x1 |
Character vector. The names of the minuend. |
x2 |
Character vector. The names of the subtrahend. |
pvalues |
Numeric vector. The p-values for the differences of each |
grp_names |
Character vector. The group names (each factor levels). |
centers |
Numeric vector. Generally, the corresponding mean or median values of |
alpha |
Numeric (default: 0.05). Significance level, range from 0 to 1. |
descending |
Logical (default: TRUE). If |
display_letters |
Character vector (default: |
display_null_letter |
Character (default: ""). Symbol for filling the letter's gap. |
misc |
Logical (default: FALSE). Return other unimportant variables, not for users. |
Value
A character vector.
References
Piepho, H.-P. (2004). An algorithm for a letter-based representation of all-pairwise comparisons. Journal of Computational and Graphical Statistics, 13(2), 456–466. https://doi.org/10.1198/1061860043515
Piepho, H.-P. (2018). Letters in mean comparisons: What they do and don't mean. Agronomy Journal, 110(2), 431–434. https://doi.org/10.2134/agronj2017.10.0580
Examples
out <- Dunn_test(X_X_O, val ~ grp, verbose = FALSE)
tab <- row_arrange(out[["summary"]], "MED")
post <- out[["post_hoc"]]
print(post[, 1:7])
cld <- compact_letter_display(x1 = post$x1,
x2 = post$x2,
pvalues = post$`Padj (holm)`,
grp_names = tab$GROUP,
centers = tab$MED)
print(cld)
Descriptive statistics
Description
Compute and summarize descriptive statistics for one or more groups.
Usage
describe(data, formula, rounding = 2)
Arguments
data |
A data frame or a list. |
formula |
A formula with a dependent variable (DV) and an independent variable (IV).
For example: |
rounding |
Integer (default: 2). Rounding digits. |
Value
A data frame with 13 columns:
- GROUP
Group name.
- CLD
Compact letter display for multiple comparisons. This column is returned as an empty character vector and is intended to be filled by post hoc comparison functions. See
oneway::compact_letter_display.- N
Sample size.
- AVG
Arithmetic mean.
- SD
Sample standard deviation.
- MED
Median.
- MIN
Minimum observed value.
- MAX
Maximum observed value.
- CI (95%)
Two-sided 95% confidence interval for the population mean.
- SKEW (= 0)
Normal distribution has a skewness of 0. See
normality::skewness.- KURT (= 3)
Normal distribution has a kurtosis of 3. See
normality::kurtosis.- normality
Is the data normally distributed? See
normality::is_normal.- n_outliers
Number of possible outliers. See
outlying::Grubbs_test.
Examples
y1 <- c(stats::rnorm(20), 7)
y2 <- c(stats::rnorm(22), -7, 9)
describe(list("apple" = y1, "banana" = y2))
Convert a data frame from wide to long format
Description
Reshapes a data frame from wide format to long format by stacking one or more columns into
a pair of key-value columns. This increases the number of rows while reducing the number of
columns. For more advanced reshaping operations, consider using tidyr::pivot_longer().
Usage
df_wide_to_long(df, columns, names_to = "grp", values_to = "val", keep = FALSE)
Arguments
df |
A data frame. |
columns |
A numeric or character vector specifying the columns to pivot into long format. |
names_to |
A character string specifying the name of the new column
containing the original column names. Default is |
values_to |
A character string specifying the name of the new column
containing the values from the pivoted columns. Default is |
keep |
Logical. If |
Value
A data frame in long format. The output contains one column storing the
original column names (names_to) and another storing the corresponding
values (values_to). If keep = TRUE, non-pivoted columns are retained.
Examples
n <- 10
df0 <- data.frame(
G1 = stats::rnorm(n, 6, 1),
G2 = stats::rnorm(n, 6, 1),
G3 = stats::rnorm(n, 3, 1)
)
df_wide_to_long(df0, c("G1", "G2"))
Check Balance of Sample Sizes Among Groups
Description
Determines whether sample sizes are approximately balanced across groups. Sample sizes are considered balanced when the smallest and largest group sizes are within the specified tolerance range relative to the average sample size.
Usage
is_balance(data, formula, buffer_ratio = 0)
Arguments
data |
A data frame or a list containing observations from each group. |
formula |
A formula specifying the dependent variable (DV) and the
independent variable (IV) in the form |
buffer_ratio |
Numeric value between 0 and 1 (default: 0). The allowable
proportional deviation from the mean sample size.
For example, |
Details
The function compares each group's sample size with the mean sample size across groups. The sample sizes are considered balanced if:
(1-r) \leq \frac{\min(n)}{\bar{n}} \leq
\frac{\max(n)}{\bar{n}} \leq (1+r)
where \bar{n} is the mean sample size across groups and r is buffer_ratio.
Value
A logical value:
- TRUE
Sample sizes among groups are considered balanced.
- FALSE
At least one group has a sample size outside the specified tolerance range.
Examples
is_balance(list(rnorm(10), rnorm(13)), buffer_ratio = 0.2)
is_balance(list(rnorm(10), rnorm(13)), buffer_ratio = 0.1)
Morphine tolerance data
Description
A dataset containing morphine tolerance measurements from five experimental treatment groups. The data consist of tolerance values recorded for eight experimental units in each group, resulting in a balanced one-way design with 40 observations.
Usage
morphine
Format
A data frame with 40 rows and 2 columns:
- tolerance
A numeric variable containing the morphine tolerance measurement.
- grp
A factor identifying the experimental treatment group with five levels:
"MS","MM","SS","SM", and"McM".
Details
The treatment groups are coded as:
- MS
Morphine followed by saline.
- MM
Morphine followed by morphine.
- SS
Saline followed by saline.
- SM
Saline followed by morphine.
- McM
Morphine followed by challenge morphine.
The dataset represents a balanced one-way experimental design with five independent groups and eight observations per group. It is suitable for demonstrating one-way ANOVA, nonparametric alternatives, homogeneity of variance tests, post hoc comparisons, and effect size estimation.
References
Howell, D. C. (2013). Statistical methods for psychology (8th ed.). Cengage. Chapter 11, Table 12.1, pg. 375.
One-Way Analysis of Variance
Description
Performs a one-way analysis of variance (ANOVA) to compare the means of two or more independent groups. By default, the function automatically selects between the classical Fisher ANOVA and Welch's ANOVA according to whether the group variances are judged to be homogeneous.
Usage
oneway_anova(
data,
formula,
alpha = 0.05,
var_equal = NA,
rounding = 4,
verbose = TRUE
)
Arguments
data |
A data frame containing the response and grouping variables. |
formula |
A two-sided formula specifying the response and grouping variables. |
alpha |
Numeric (default: 0.05). Significance level (range from 0 to 1). |
var_equal |
A logical value indicating whether equal variances should be assumed.
If |
rounding |
Integer (default: 4). Number of decimal places displayed in the output. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
If var_equal = TRUE, Fisher's ANOVA is performed. If var_equal = FALSE, Welch's ANOVA is
performed. When var_equal = NA (the default), homogeneity of variances is assessed using
varequal::is_var_equal(), and the appropriate test is selected automatically.
Fisher's ANOVA assumes independent observations, normally distributed populations, and equal population variances. When the equal-variance assumption is violated, Welch's ANOVA provides a more robust alternative by adjusting the test statistic and denominator degrees of freedom.
Value
A data frame representing the ANOVA table with the following columns:
- DF
Degrees of freedom.
- SS
Sum of squares.
- MS
Mean square.
- Fvalue
Observed F statistic.
- Fcrit
Critical F value at the specified significance level.
- Pvalue
P-value associated with the F statistic.
- signif
Significance code corresponding to the p-value.
- p_omega2
Effect size. Partial omega squared.
- method
Show whether Fisher's or Welch's ANOVA was conducted.
The rows correspond to the treatment groups ("Group"), residual error ("Residuals"), and total variation ("Total").
References
Howell, D. C. (2013). Statistical methods for psychology (8th ed.). Cengage Learning. Chapter 11, pg. 325-345.
Montgomery, D. C. (2017). Design and analysis of experiments (Ninth edition). John Wiley & Sons, Inc.
Examples
# Automatically select the appropriate procedure
oneway_anova(O_X_X, val ~ grp)
# Classical one-way ANOVA
oneway_anova(O_O_X, val ~ grp, var_equal = TRUE)
# Welch's ANOVA
oneway_anova(O_X_X, val ~ grp, var_equal = FALSE)
One-Way Aligned Ranked Transformed Analysis of Variance (ART-ANOVA)
Description
Performs a one-way analysis of variance (ANOVA) to compare the means of two or more independent groups. By default, the function automatically selects between the classical Fisher ANOVA and Welch's ANOVA according to whether the group variances are judged to be homogeneous.
Usage
oneway_art(
data,
formula,
alpha = 0.05,
var_equal = NA,
rounding = 4,
verbose = TRUE
)
Arguments
data |
A data frame containing the response and grouping variables. |
formula |
A two-sided formula specifying the response and grouping variables. |
alpha |
Numeric (default: 0.05). Significance level (range from 0 to 1). |
var_equal |
A logical value passes into the |
rounding |
Integer (default: 4). Number of decimal places displayed in the output. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Details
If var_equal = TRUE, Fisher's ANOVA is performed on the transformed response variable.
If var_equal = FALSE, Welch's ANOVA is performed. When var_equal = NA (the default),
homogeneity of variances is assessed using varequal::is_var_equal(), and the appropriate
test is selected automatically.
Value
A data frame representing the ANOVA table with the following columns:
- DF
Degrees of freedom.
- SS
Sum of squares.
- MS
Mean square.
- Fvalue
Observed F statistic.
- Fcrit
Critical F value at the specified significance level.
- Pvalue
P-value associated with the F statistic.
- signif
Significance code corresponding to the p-value.
- method
A character specifying this is an ART-ANOVA procedure.
The rows correspond to the treatment groups ("Group"), residual error ("Residuals"), and total variation ("Total").
References
Wobbrock, J. O., Findlater, L., Gergle, D., & Higgins, J. J. (2011). The aligned rank transform for nonparametric factorial analyses using only ANOVA procedures. Proceedings of the SIGCHI Conference on Human Factors in Computing Systems, 2011, 143–146. https://doi.org/10.1145/1978942.1978963
Elkin, L. A., Kay, M., Higgins, J. J., & Wobbrock, J. O. (2021). An aligned rank transform procedure for multifactor contrast tests. Proceedings of the 34th Annual ACM Symposium on User Interface Software and Technology, 754–768. https://doi.org/10.1145/3472749.3474784
Examples
normality::is_normal(anorexia, weight_gain ~ therapy)
oneway_art(anorexia, weight_gain ~ therapy)
Multiple comparison procedure
Description
Performs a one-way analysis of variance followed by an appropriate post-hoc multiple pairwise comparison based on the distributional characteristics and design of the data. The procedure evaluates normality, homogeneity of variances, and sample-size balance to select an appropriate analysis protocol.
Usage
pairwise_comparison(
data,
formula,
alpha = 0.05,
rounding = 4,
verbose = TRUE,
p_adjust_method = "holm"
)
Arguments
data |
A data frame containing the response and grouping variables. |
formula |
A two-sided formula specifying the response and grouping variables in the form
of |
alpha |
A numeric significance level used for hypothesis testing. The default is 0.05. |
rounding |
An integer specifying the number of decimal places used when reporting numerical results. The default is 4. |
verbose |
A logical value indicating whether the results should be printed to the console.
If |
p_adjust_method |
A character string specifying the method used to adjust p-values for
Dunn's multiple-comparison test when the Kruskal-Wallis/Dunn protocol is selected. The
default is "holm". See |
Details
If the response variable is normally distributed, the post-hoc procedure is selected according to variance homogeneity and sample-size balance:
equal variances and balanced group sizes: REGWQ test;
equal variances and unbalanced group sizes: Tukey-Kramer test;
unequal variances: Games-Howell test.
If the response variable is not normally distributed, an aligned-rank-transform (ART) analysis is first attempted. Normality and variance homogeneity are then reassessed using the aligned-ranked response. If the aligned-ranked response is normally distributed, the same variance- and balance-based selection described above is applied. Otherwise, the procedure uses the Kruskal-Wallis test followed by Dunn's multiple-comparison test.
The resulting object contains the selected pre-hoc and post-hoc analysis results and identifies the complete analysis protocol in the method component.
The analysis proceeds according to the following decision sequence:
A preliminary one-way ANOVA is performed to assess normality and homoscedasticity.
If the response is normally distributed, the post-hoc procedure is selected according to variance homogeneity and sample-size balance.
If the response is not normally distributed, an ART analysis is performed.
Normality and variance homogeneity are reassessed using the aligned-ranked response from the ART analysis.
If the aligned-ranked response remains non-normal, the Kruskal-Wallis test followed by Dunn's test is used.
Otherwise, the REGWQ, Tukey-Kramer, or Games-Howell procedure is selected according to variance homogeneity and sample-size balance.
Thus, the possible analysis protocols are:
one-way ANOVA + REGWQ;
one-way ANOVA + Tukey-Kramer;
one-way ANOVA + Games-Howell;
ART-ANOVA + REGWQ;
ART-ANOVA + Tukey-Kramer;
ART-ANOVA + Games-Howell;
Kruskal-Wallis + Dunn's test.
The function is intended as a general-purpose adaptive procedure for one-factor experimental designs. The selected method depends on the diagnostic results obtained from the supplied data and should therefore be interpreted together with the underlying assumptions and study design.
Value
A list containing the results of the selected analysis protocol. The method component identifies the complete protocol, combining the a priori and post-hoc procedures. The object also contains the post-hoc results and summary produced by the selected procedure.
See Also
oneway_anova(), oneway_art(), REGWQ_test(),
Tukey_Kramer_test(), Games_Howell_test(),
Kruskal_Wallis_test(), Dunn_test()
Examples
# Normally distributed, variance equal, balanced groups
pairwise_comparison(O_O_O, val ~ grp)
# Normally distributed, variance equal, unbalanced groups
pairwise_comparison(O_O_X, val ~ grp)
# Normally distributed, variance unequal
pairwise_comparison(O_X_X, val ~ grp)
# Non-parametric
pairwise_comparison(X_X_X, val ~ grp)
Plasma Etching Experiment
Description
Etch Rate Data (in Å/min) from the Plasma Etching Experiment.
Usage
plasma_etching
Format
A data frame with 20 rows and 2 columns:
- power
A factor identifying the power (W) (160(20)220).
- etch_rate
A numeric response variable.
References
Montgomery, D. C. (2017). Design and analysis of experiments (Ninth edition). John Wiley & Sons, Inc.
Convert p-values to significance labels
Description
Converts numeric p-values into categorical significance labels according to user-defined thresholds. The function is commonly used to annotate statistical results in tables and figures.
Usage
pval2asterisk(
x,
break_points = c(0.055, 0.05, 0.01, 0.001, 0),
symbols = c("ns", ".", "*", "**", "***")
)
Arguments
x |
A numeric vector of p-values. |
break_points |
A numeric vector of significance thresholds in descending order. Each threshold defines the upper bound of a significance interval. The default values correspond to:
|
symbols |
A character vector of significance labels corresponding to |
Details
Each p-value is assigned to exactly one interval defined by break_points. Values greater
than the first threshold are assigned symbols[1], whereas values less than or equal to the
last threshold are assigned the last element of symbols. Intermediate intervals are matched
sequentially.
The function assumes that break_points are supplied in descending order.
Value
A character vector of the same length as x, where each element is the corresponding
significance label.
Examples
p <- c(0.20, 0.04, 0.008, 0.0005, 1e-6)
pval2asterisk(p)
# Custom significance labels
pval2asterisk(
p,
break_points = c(0.05, 0.01, 0),
symbols = c("Not significant", "Significant", "Highly significant")
)
Rearrange rows by the order of one or more columns
Description
Reorders the rows of a data frame according to user-specified ordering of
the values in one or more columns. If by_order is omitted, the unique
values in each selected column are sorted and used as the ordering levels.
Usage
row_arrange(data, cols, by_order)
Arguments
data |
A data frame. |
cols |
A character or numeric vector specifying the columns used to determine the row order. Character values are interpreted as column names, and numeric values as column indices. |
by_order |
A list specifying the ordering of values for each column in
|
Value
A data frame with the same columns as data, but with rows reordered
according to the specified column orderings.
Examples
fct_lvl <- c("A", "B", "C", "D")
df0 <- data.frame(
C1 = c("B", "D", "A", "A", "B", "C", "D"),
C2 = c("D", "C", "D", "A", "C", "B", "A"),
C3 = 1:7
)
row_arrange(df0, 1:2, list(fct_lvl, fct_lvl))
# Use the default ordering (sorted unique values)
row_arrange(df0, c("C2", "C3"))
Simulated datasets for statistical analysis
Description
A collection of six simulated datasets representing different combinations of distributional assumptions, variance homogeneity, and sample-size balance. These datasets are designed for demonstrating and evaluating statistical procedures under a range of common experimental conditions.
Usage
O_O_O
O_O_X
O_X_X
X_O_O
X_X_O
X_X_X
Format
Six data frames, each containing the following two variables:
grpCharacter vector identifying the experimental group.
valNumeric vector containing the simulated response values.
The number of observations differs according to the experimental design: balanced datasets contain 120 observations (20 per group), whereas unbalanced datasets contain 128 observations with group sizes of 27, 24, 16, 30, 11, and 20.
An object of class data.frame with 100 rows and 2 columns.
An object of class data.frame with 128 rows and 2 columns.
An object of class data.frame with 128 rows and 2 columns.
An object of class data.frame with 120 rows and 2 columns.
An object of class data.frame with 120 rows and 2 columns.
An object of class data.frame with 110 rows and 2 columns.
Details
All datasets contain six groups (G1 to G6) and two variables:
grpA character variable identifying the group.
valA numeric response variable.
The dataset names follow a three-character notation separated by
underscores: D_V_B, where each position describes a different property
of the data:
- First position (
D) Distribution.
Oindicates normally distributed data, whereasXindicates distribution-free or non-normally distributed data.- Second position (
V) Variance.
Oindicates homoscedasticity, whereasXindicates heteroscedasticity.- Third position (
B) Design balance.
Oindicates a balanced design, whereasXindicates an unbalanced design.
The six datasets are:
O_O_ONormally distributed, homoscedastic, and balanced-designed data. Each group contains 20 observations.
O_O_XNormally distributed, homoscedastic, and unbalanced-designed data. The group sample sizes are 27, 24, 16, 30, 11, and 20, respectively.
O_X_XNormally distributed, heteroscedastic, and unbalanced-designed data. The group sample sizes are 27, 24, 16, 30, 11, and 20, respectively.
X_O_ODistribution-free or non-normally distributed, homoscedastic, and balanced-designed data. Each group contains 20 observations.
X_X_ODistribution-free or non-normally distributed, heteroscedastic, and balanced-designed data. Each group contains 20 observations.
X_X_XDistribution-free or non-normally distributed, heteroscedastic, and unbalanced-designed data. The group sample sizes are 27, 24, 16, 30, 11, and 20, respectively.
The normally distributed datasets were generated using
stats::rnorm(). The distribution-free datasets were generated using
combinations of stats::rcauchy(), stats::runif(), and
stats::rgamma(), together with stats::rnorm(). Different location and
scale parameters were used to produce the intended distributional and
variance characteristics.
These datasets are intended for methodological examples, unit tests, demonstrations, and comparisons of statistical procedures under different combinations of assumptions. They should not be interpreted as empirical observations from a real population.
Dataset characteristics
| Dataset | Distribution | Variance | Design |
O_O_O | Normal | Homoscedastic | Balanced |
O_O_X | Normal | Homoscedastic | Unbalanced |
O_X_X | Normal | Heteroscedastic | Unbalanced |
X_O_O | Non-normal | Homoscedastic | Balanced |
X_X_O | Non-normal | Heteroscedastic | Balanced |
X_X_X | Non-normal | Heteroscedastic | Unbalanced |
Examples
data(O_O_O)
boxplot(val ~ grp, data = O_O_O)
data(X_X_X)
boxplot(val ~ grp, data = X_X_X)
aggregate(val ~ grp, data = O_O_O, FUN = mean)
aggregate(val ~ grp, data = X_X_X, FUN = mean)