| Title: | One-Way Statistical Analyses |
|---|---|
| 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>. |
| Authors: | Joon-Keat Lai [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-9840-5836>) |
| Maintainer: | Joon-Keat Lai <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.4 |
| Built: | 2026-10-15 12:23:06 UTC |
| Source: | https://github.com/p10911004-npust/oneway |
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.
anorexiaanorexia
A data frame with 72 observations and 2 variables:
A factor indicating the treatment group with three levels:
"control", "cognitive", and "family".
A numeric vector giving the observed weight gain after treatment.
Group sample sizes are:
Control: 26
Cognitive-behavior therapy: 29
Family therapy: 17
Howell, D. C. (2013). Statistical methods for psychology (8th ed.). Cengage. Chapter 11, Table 11.5, pg. 342.
Calculate Cohen's d and Hedges' g introduced in Lakens (2013).
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 )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 )
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. |
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.
A numeric scalar or a numeric vector of length 3, depends on return_CI.
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
Represent significance statements resulting from all-pairwise comparisons.
compact_letter_display( x1, x2, pvalues, grp_names, centers, alpha = 0.05, descending = TRUE, display_letters = base::letters, display_null_letter = "", misc = FALSE )compact_letter_display( x1, x2, pvalues, grp_names, centers, alpha = 0.05, descending = TRUE, display_letters = base::letters, display_null_letter = "", misc = FALSE )
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. |
A character vector.
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
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)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)
Compute and summarize descriptive statistics for one or more groups.
describe(data, formula, rounding = 2)describe(data, formula, rounding = 2)
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. |
A data frame with 13 columns:
Group name.
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.
Sample size.
Arithmetic mean.
Sample standard deviation.
Median.
Minimum observed value.
Maximum observed value.
Two-sided 95% confidence interval for the population mean.
Normal distribution has a skewness of 0. See normality::skewness.
Normal distribution has a kurtosis of 3. See normality::kurtosis.
Is the data normally distributed? See normality::is_normal.
Number of possible outliers. See outlying::Grubbs_test.
y1 <- c(stats::rnorm(20), 7) y2 <- c(stats::rnorm(22), -7, 9) describe(list("apple" = y1, "banana" = y2))y1 <- c(stats::rnorm(20), 7) y2 <- c(stats::rnorm(22), -7, 9) describe(list("apple" = y1, "banana" = y2))
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().
df_wide_to_long(df, columns, names_to = "grp", values_to = "val", keep = FALSE)df_wide_to_long(df, columns, names_to = "grp", values_to = "val", keep = FALSE)
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 |
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.
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"))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"))
Performs Dunn's multiple comparison procedure for all pairwise comparisons of groups following a significant Kruskal-Wallis test.
Dunn_test( data, formula = NULL, alpha = 0.05, p_adjust_method = "holm", rounding = 4, verbose = TRUE )Dunn_test( data, formula = NULL, alpha = 0.05, p_adjust_method = "holm", rounding = 4, verbose = TRUE )
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. |
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.
A list containing the following components:
The name of the statistical procedure.
The input data used in the analysis.
The Kruskal-Wallis test results.
Results of all pairwise Dunn comparisons, including differences in mean ranks, confidence intervals, Z statistics, unadjusted and adjusted p-values, and effect sizes.
Descriptive statistics for each group, including compact letter displays (CLD).
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.
out <- Dunn_test(X_X_O, val ~ grp)out <- Dunn_test(X_X_O, val ~ grp)
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.
Games_Howell_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )Games_Howell_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )
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. |
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.
A list containing the following components:
The name of the statistical procedure.
The input data used in the analysis.
The one-way analysis of variance results.
Results of all pairwise Games-Howell comparisons, including mean differences, confidence intervals, test statistics, adjusted p-values, and effect sizes.
Descriptive statistics for each group, including compact letter displays (CLD).
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.
out <- Games_Howell_test(O_X_X, val ~ grp)out <- Games_Howell_test(O_X_X, val ~ grp)
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.
is_balance(data, formula, buffer_ratio = 0)is_balance(data, formula, buffer_ratio = 0)
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, |
The function compares each group's sample size with the mean sample size across groups. The sample sizes are considered balanced if:
where is the mean sample size across groups and r is buffer_ratio.
A logical value:
Sample sizes among groups are considered balanced.
At least one group has a sample size outside the specified tolerance range.
is_balance(list(rnorm(10), rnorm(13)), buffer_ratio = 0.2) is_balance(list(rnorm(10), rnorm(13)), buffer_ratio = 0.1)is_balance(list(rnorm(10), rnorm(13)), buffer_ratio = 0.2) is_balance(list(rnorm(10), rnorm(13)), buffer_ratio = 0.1)
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.
Kruskal_Wallis_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )Kruskal_Wallis_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )
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. |
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.
A data frame summarizing the Kruskal–Wallis test result in an ANOVA-like table:
Degrees of freedom.
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.
Rank-based mean square (SS / DF). Only the between-group value is defined.
Observed Kruskal–Wallis H statistic.
Critical chi-squared value at the specified significance level.
P-value associated with the H statistic.
Significance code corresponding to the p-value.
Effect size (currently returned as NA).
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.
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.
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)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)
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.
morphinemorphine
A data frame with 40 rows and 2 columns:
A numeric variable containing the morphine tolerance measurement.
A factor identifying the experimental treatment group with five
levels: "MS", "MM", "SS", "SM", and "McM".
The treatment groups are coded as:
Morphine followed by saline.
Morphine followed by morphine.
Saline followed by saline.
Saline followed by morphine.
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.
Howell, D. C. (2013). Statistical methods for psychology (8th ed.). Cengage. Chapter 11, Table 12.1, pg. 375.
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.
oneway_anova( data, formula = NULL, alpha = 0.05, var_equal = NA, rounding = 4, verbose = TRUE )oneway_anova( data, formula = NULL, alpha = 0.05, var_equal = NA, rounding = 4, verbose = TRUE )
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. |
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.
A data frame representing the ANOVA table with the following columns:
Degrees of freedom.
Sum of squares.
Mean square.
Observed F statistic.
Critical F value at the specified significance level.
P-value associated with the F statistic.
Significance code corresponding to the p-value.
Effect size. Partial omega squared.
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").
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.
# 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)# 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)
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.
oneway_art( data, formula = NULL, alpha = 0.05, var_equal = NA, rounding = 4, verbose = TRUE )oneway_art( data, formula = NULL, alpha = 0.05, var_equal = NA, rounding = 4, verbose = TRUE )
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. |
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.
A data frame representing the ANOVA table with the following columns:
Degrees of freedom.
Sum of squares.
Mean square.
Observed F statistic.
Critical F value at the specified significance level.
P-value associated with the F statistic.
Significance code corresponding to the p-value.
A character specifying this is an ART-ANOVA procedure.
The rows correspond to the treatment groups ("Group"), residual error ("Residuals"), and total variation ("Total").
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
normality::is_normal(anorexia, weight_gain ~ therapy) oneway_art(anorexia, weight_gain ~ therapy)normality::is_normal(anorexia, weight_gain ~ therapy) oneway_art(anorexia, weight_gain ~ therapy)
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.
pairwise_comparison( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE, p_adjust_method = "holm" )pairwise_comparison( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE, p_adjust_method = "holm" )
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 |
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.
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.
oneway_anova(), oneway_art(), REGWQ_test(),
Tukey_Kramer_test(), Games_Howell_test(),
Kruskal_Wallis_test(), Dunn_test()
# 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)# 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)
Generate a contrast matrix containing all pairwise comparisons among groups. Each row represents
one pairwise contrast, with a coefficient of 1 assigned to the first group and -1 assigned
to the second group. All other coefficients are 0. The sum of all coefficients is zero.
pairwise_contrasts(group_names)pairwise_contrasts(group_names)
group_names |
A character vector of group names or group labels. |
The contrasts are generated in the order returned by utils::combn(), with the first group in
each pair assigned a coefficient of 1 and the second group assigned a coefficient of -1.
The resulting matrix can be used to specify all-pairwise comparisons in multiple-comparison procedures, such as Scheffe's test.
A numeric matrix with one row for each pairwise comparison and one column for each
unique group. Column names correspond to the group names. Each row contains one
coefficient of 1, one coefficient of -1, and zeros elsewhere.
groups <- c("g1", "g2", "g3", "g4", "g5") pairwise_contrasts(groups) # Use the unique group names from a grouping vector group_names <- c("Control", "Low", "High", "Control", "Low") pairwise_contrasts(group_names)groups <- c("g1", "g2", "g3", "g4", "g5") pairwise_contrasts(groups) # Use the unique group names from a grouping vector group_names <- c("Control", "Low", "High", "Control", "Low") pairwise_contrasts(group_names)
Etch Rate Data (in Å/min) from the Plasma Etching Experiment.
plasma_etchingplasma_etching
A data frame with 20 rows and 2 columns:
A factor identifying the power (W) (160(20)220).
A numeric response variable.
Montgomery, D. C. (2017). Design and analysis of experiments (Ninth edition). John Wiley & Sons, Inc.
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.
pval2asterisk( x, break_points = c(0.055, 0.05, 0.01, 0.001, 0), symbols = c("ns", ".", "*", "**", "***") )pval2asterisk( x, break_points = c(0.055, 0.05, 0.01, 0.001, 0), symbols = c("ns", ".", "*", "**", "***") )
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 |
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.
A character vector of the same length as x, where each element is the corresponding
significance label.
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") )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") )
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.
REGWQ_test(data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE)REGWQ_test(data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE)
data |
A data frame, a list, 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 (default: 0.05) specifying the significance level. |
rounding |
An integer (default: 4). The number of decimal places to display in the output. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
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().
A list containing the following components:
The name of the statistical procedure.
The input data used in the analysis.
The one-way analysis of variance results.
Results of all pairwise REGWQ comparisons, including mean differences, confidence intervals, studentized range statistics, p-values, modified significance levels, and effect sizes.
Descriptive statistics for each group, including compact letter displays (CLD).
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.
out <- REGWQ_test(morphine, tolerance ~ grp)out <- REGWQ_test(morphine, tolerance ~ grp)
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.
row_arrange(data, cols, by_order)row_arrange(data, cols, by_order)
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
|
A data frame with the same columns as data, but with rows reordered
according to the specified column orderings.
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"))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"))
Performs Scheffé's multiple-comparison procedure for testing planned contrasts among group means
following an analysis of variance (ANOVA). By default, all pairwise comparisons are performed
(NOT recommended, please use other tests to conduct pairwise comparison). Users can also specify
custom contrasts through the planned_contrasts argument.
Scheffe_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE, planned_contrasts = NULL )Scheffe_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE, planned_contrasts = NULL )
data |
A data frame, a list, 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 (default: 0.05) specifying the significance level. |
rounding |
An integer (default: 4). The number of decimal places to display in the output. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
planned_contrasts |
An optional contrast matrix. For example, see |
An object containing the results of the Scheffé planned-contrast analysis, including the underlying ANOVA results, group summaries, post-hoc comparison results, and contrast matrix. The object is returned invisibly.
Heckert, N.A., Filliben, J.J., Croarkin, C.M., Hembree, B., Guthrie, W.F., Tobias, P., & Prinz, J. (2002). Handbook 151: Nist/sematech e-handbook of statistical methods. Section 7.4.6.2: Scheffe's method https://doi.org/10.18434/M32189
Howell, D.C. (2010). Statistical Methods for Psychology (7th ed.). Cengage Learning. Chapter 12: Multiple comparisons among treatment means, Section 12.3: A Priori Comparisons, pg. 374.
Montgomery, D.C. (2017). Design and analysis of experiments (9th ed.). John Wiley & Sons. pg. 89-95.
Scheffé, H. (1953). A method for judging all contrasts in the analysis of variance. Biometrika, 40, 87–104. https://doi.org/10.1093/biomet/40.1-2.87
oneway_anova(), pairwise_contrasts()
# Compare all pairwise group means using Scheffé's method out <- Scheffe_test(morphine, tolerance ~ grp) # Specify custom contrasts grp_names <- c("MS", "MM", "SS", "SM", "McM") ca <- c(-1, -1, -1, 1.5, 1.5) cb <- c(0, -1, 0, 0, 1) cc <- c(-1, 0, 1, 0, 0) cd <- c(0, 1, -1, 0, 0) contr <- matrix(c(ca, cb, cc, cd), ncol = length(grp_names), byrow = TRUE) colnames(contr) <- grp_names out <- Scheffe_test(morphine, tolerance ~ grp, planned_contrasts = contr)# Compare all pairwise group means using Scheffé's method out <- Scheffe_test(morphine, tolerance ~ grp) # Specify custom contrasts grp_names <- c("MS", "MM", "SS", "SM", "McM") ca <- c(-1, -1, -1, 1.5, 1.5) cb <- c(0, -1, 0, 0, 1) cc <- c(-1, 0, 1, 0, 0) cd <- c(0, 1, -1, 0, 0) contr <- matrix(c(ca, cb, cc, cd), ncol = length(grp_names), byrow = TRUE) colnames(contr) <- grp_names out <- Scheffe_test(morphine, tolerance ~ grp, planned_contrasts = contr)
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.
O_O_O O_O_X O_X_X X_O_O X_X_O X_X_XO_O_O O_O_X O_X_X X_O_O X_X_O X_X_X
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 120 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.
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:
D)Distribution. O indicates normally
distributed data, whereas X indicates distribution-free or
non-normally distributed data.
V)Variance. O indicates homoscedasticity,
whereas X indicates heteroscedasticity.
B)Design balance. O indicates a balanced
design, whereas X indicates 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 | 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 |
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)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)
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.
Tukey_HSD_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )Tukey_HSD_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )
data |
A data frame, a list, 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 (default: 0.05) specifying the significance level. |
rounding |
An integer (default: 4). The number of decimal places to display in the output. |
verbose |
Logical (default: TRUE). Show warnings and messages. |
Tukey's HSD test is based on the studentized range distribution and assumes
equal variances across groups. It provides simultaneous confidence intervals
and adjusted -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().
A list containing the following components:
The name of the statistical procedure.
The input data used in the analysis.
The one-way analysis of variance results.
Results of all pairwise Tukey-HSD comparisons, including mean differences, confidence intervals, studentized range statistics, adjusted p-values, and effect sizes.
Descriptive statistics for each group, including compact letter displays (CLD).
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.
out <- Tukey_HSD_test(O_O_O, val ~ grp)out <- Tukey_HSD_test(O_O_O, val ~ grp)
Represent significance statements resulting from all-pairwise comparisons.
Tukey_Kramer_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )Tukey_Kramer_test( data, formula = NULL, alpha = 0.05, rounding = 4, verbose = TRUE )
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. |
A list with 4 elements:
Statistical procedures that were conducted.
The input data and possibly other transformed data.
a priori test result.
Post-hoc test result.
Descriptive statistics.
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.
out <- Tukey_Kramer_test(O_O_X, val ~ grp)out <- Tukey_Kramer_test(O_O_X, val ~ grp)