rstatix 1.0.0
rstatix 1.0.0
New features
anova_test()gains aciargument to add a confidence interval for partial eta squared. Witheffect.size = "pes"and e.g.ci = 0.95, two columnsconf.low/conf.highare returned, computed in base R from the noncentral F distribution (Steiger, 2004) — no new dependency. The intervals matcheffectsize::eta_squared(partial = TRUE, ci = , alternative = "two.sided"). Works for one-way, factorial, repeated-measures and mixed designs (using the uncorrected degrees of freedom, consistent with the effect-size point estimate). No interval is provided for generalized eta squared ("ges", the default), which has no standard closed-form interval. The defaultci = NULLleaves the output unchanged (#18).t_test()andwilcox_test()gain anerror.as.naargument: whenTRUE, a comparison that cannot be computed (a group with fewer than two observations, or essentially constant data) returns anNAresult row with a warning naming the comparison, instead of stopping with an error — so the remaining comparisons (or groups, in a grouped analysis) are still computed. The defaulterror.as.na = FALSEkeeps the previous behavior (the comparison errors) (#208, #158).t_test()andwilcox_test()gain anidargument for paired tests: it names the subject/sample identifier so the two compared groups are matched by subject (instead of by row order), using only subjects present in both groups (complete pairs). For more than two groups the matching is done independently per pairwise comparison, so comparisons can be based on different numbers of pairs (per-comparison pairwise deletion, like SPSS). This makes paired tests work when observations are missing or the groups have unequal sizes, and avoids silent mis-pairing when rows are not in subject order. The default (id = NULL) is unchanged (groups paired in row order) (#136, #175, #192).cor_test()now returns the degrees of freedom (df) for the Pearson method (e.g. to reportr(df) = …, p); the column sits next tostatistic. Spearman/Kendall (which have no df) andcor_mat()/cor_pmat()are unchanged (#107).get_summary_stats()can now report skewness and kurtosis (bias-corrected, type-2 estimator, matchinge1071'stype = 2). They are opt-in viashow, e.g.get_summary_stats(data, x, show = c("mean", "sd", "skewness", "kurtosis")), and are not added to any defaulttype, so existing output is unchanged (#99).get_summary_stats()gains adigitsargument to control the number of decimal places (default 3); useful when summarizing very small values that would otherwise round to 0 (#145, #186, #218).pairwise_mcnemar_test()now returns the McNemar chi-squaredstatisticanddfcolumns fortype = "mcnemar"(the default), as the documentation already described; they were previously dropped. The exact-binomial path (type = "exact"),mcnemar_test(), and thep/p.adjvalues are unchanged (#122).dunn_test()gains aref.groupargument to compare each group only to a reference (control) level. When specified, the multiple-comparison adjustment is computed over only thek - 1comparisons against the reference (matching e.g. GraphPad Prism), which is not equivalent to filtering the full pairwise result afterwards. The defaultref.group = NULLperforms all pairwise comparisons exactly as before (#101).chisq_test()now accepts a pipe-friendly data-frame interface for the test of independence between two categorical variables:data %>% chisq_test(var1, var2)(positional) ordata %>% chisq_test(vars = c("var1", "var2")). The contingency table is built internally. The existing table/matrix/vector interfaces (including passing a data frame that already is a contingency table) are unchanged (#43).wilcox_effsize()gains adetailedargument: whendetailed = TRUE, the output additionally includes theZstatistic(used to computer = Z/sqrt(N)), the p-value and the test method, so the effect size and the underlying Z are reported in a single data frame. The default (detailed = FALSE) output is unchanged (#122).- New function
dunnett_test()for Dunnett's many-to-one comparisons: each treatment group is compared against a single control (ref.group), with the family-wise error rate controlled over only thek - 1comparisons using the exact multivariate-t distribution. Results matchDescTools::DunnettTest()/multcomp::glht(). Built onemmeans(Suggests) (#129). - New function
ks_test()— a pipe-friendly wrapper aroundstats::ks.test()for the two-sample Kolmogorov-Smirnov test, with automatic pairwise comparisons (andref.group) for grouping variables with more than two levels (#92, #168). - New function
conover_test()for Conover's (Conover-Iman) all-pairs rank comparison test, a post-hoc procedure following a significant Kruskal-Wallis test. It mirrorsdunn_test()(includingref.groupand grouped-data support) but uses the pooled within-group rank variance and a t-distribution, making it generally more powerful. Implemented in base R (no new dependency); results matchPMCMRplus::kwAllPairsConoverTest()(#222, #17). - New function
friedman_conover_test()for Conover's all-pairs comparisons (also known as the Durbin-Conover test), a post-hoc procedure following a significant Friedman rank sum test (the repeated-measures analogue of Conover's Kruskal-Wallis post-hoc). It supportsref.groupand grouped data. Implemented in base R (no new dependency); results matchPMCMRplus::frdAllPairsConoverTest()(#8). - New function
friedman_nemenyi_test()for the Nemenyi all-pairs post-hoc test following a significant Friedman rank sum test (the rank-based, repeated-measures analogue of Tukey's HSD). The statistic is referred to the studentized range distribution, which already accounts for the multiplicity of the comparisons (so the reportedp.adjneeds no further adjustment). Implemented in base R (no new dependency); results matchPMCMRplus::frdAllPairsNemenyiTest()(#141). - New function
add_cld()adds the compact letter display to an all-pairwise comparison result (e.g. fromtukey_hsd(),dunn_test(),games_howell_test(),conover_test()or a pairwiset_test()/wilcox_test()): groups that do not share a letter are significantly different — convenient for annotating plots. The letters are computed in base R via the insert-and-absorb algorithm (Piepho, 2004), matchingmultcompView::multcompLetters()but without adding a dependency. Works on grouped tests (one display per group) (#110). - New function
fligner_test()— a pipe-friendly wrapper aroundstats::fligner.test()for the Fligner-Killeen test, a non-parametric (rank-based) test of the homogeneity of group variances and a robust alternative tolevene_test(). Supports grouped data and reports the complete-casen(#179).
Main changes
- P-values are no longer rounded to 3 significant figures before being returned. Test functions (
t_test(),wilcox_test(),kruskal_test(),cor_test(),tukey_hsd(),games_howell_test(),welch_anova_test(), thepairwise_*/*_testproportion/chi-square/Fisher/binomial/McNemar families, etc.) now return full-precisionpandp.adj, consistent withdunn_test()which already did. Adjusted p-values are now computed from the full-precision p-values, so re-runningadjust_pvalue()(orp.adjust()) downstream is exact. This changes the stored/printedp/p.adj(more digits), and pairwisep.adjvalues can shift slightly because adjustment is no longer applied to pre-rounded inputs. To round for display, usep_format()/p_round()oroptions(pillar.sigfig=). Test statistics, effect sizes, the correlation coefficient, and the omnibus ANOVA tests (anova_test(),welch_anova_test(), whose summary p stays at 3 significant figures) are unaffected (#108, #135, #219). - The
methodcolumn of detailed test results (detailed = TRUE) now reports the specific test variant instead of a generic label:t_test()gives "Welch t-test" / "T-test" / "Paired t-test" / "One-sample t-test", andwilcox_test()gives "Wilcoxon rank sum test" / "Wilcoxon signed rank test" (#124). Non-detailed output and the p-values/statistics are unchanged.
Minor changes
freq_table()now supports grouped data:data %>% group_by(g) %>% freq_table(x)computes the frequency table ofxwithin each group (the grouping columns are kept and the proportions sum to 100% within each group), returning a single tidy data frame. Previously a grouped call errored. Ungrouped behavior is unchanged. Based on the contribution by @jakub-jedrusiak (#191).- Documented how to use
emmeans_test()'smodelargument for two common cases: (i) computing estimated marginal means averaged over another factor in a factorial design (fitlm(y ~ a * b)and compareaviaformula = y ~ a,model =), and (ii) repeated-measures / mixed designs (pass a within-subject model such asaov(... + Error())ornlme::lme()). Both already worked viamodel =— this clarifies the parameter and adds examples (#139, #131). - Documented the columns added by
add_y_position()/add_x_position()/add_xy_position(), and clarified that thegroupscolumn is a reserved internal column (used to position dodged grouped comparisons) that is overwritten — users should not rely on it or usegroupsas one of their own column names in the test object. A future major version may rename it to a dotted, less collision-prone name (#16). - Documented that
anova_test()'s default sums-of-squares type can differ between its two interfaces on unbalanced designs: theformulainterface defaults to type II for between-subjects designs, while thedv=/between=interface uses type III for unbalanced between-subjects designs with more than one factor (both use type III for repeated measures). For balanced designs the types coincide; for unbalanced designs, passtype=explicitly for reproducible, interface-independent results. ANoteand example were added to?anova_test. No change to computed results (#190). - New documentation topic
?\rstatix-programming`showing how to userstatixprogrammatically (variable names held in strings, wrapper functions). The selection interface (e.g.cor_test(),get_summary_stats()) supports tidy evaluation —!!/!!!, embracing with{{ }},vars=, andall_of()/any_of()— and the formula tests (e.g.t_test(),anova_test()) take a formula built withreformulate()/as.formula(paste())`. These patterns already work; they are now documented and cross-referenced from the relevant help pages (#142). cor_test()now errors with a clear message when aweightsargument is supplied, instead of silently returning the unweighted correlation (it wrapsstats::cor.test(), which has noweightsargument). The message points to base Rstats::cov.wt(..., cor = TRUE)for a weighted Pearson correlation. Unweighted calls are unaffected (#47).- The "reference group not present" error (see below) now carries the S3 condition class
rstatix_missing_ref_group, so downstream callers (e.g.ggpubr::geom_pwc(), which skips ref-less grouped subsets) can detect it reliably by class — viarlang::cnd_inherits()to also catch it through the grouped (doo()/purrr) wrapping — instead of matching the translatable message text (#153). t_test()/wilcox_test()(and the other tests that acceptref.group) now give a clear, actionable error when the specifiedref.groupis not present in the data, instead of a cryptic'<ref>' must be an existing levelfromrelevel(). This most often happens with grouped data where some group does not contain the reference level; the message lists the available levels and shows thegroup_by() %>% filter(any(... == ref.group))idiom to keep only the groups that have it. Validref.groupvalues (includingref.group = "all") are unaffected (#153).- Documented the sign convention of
t_test()/wilcox_test()when aref.groupis used: the reference is taken asgroup1, soestimate = mean(group1) - mean(group2) = mean(ref.group) - mean(other)(the base Rt.test()/wilcox.test()convention) and a positivestatistic/estimatemeans the value is higher in the reference group. The note also shows how to flip the sign if you prefer a positive sign to mean "higher in the non-reference group". Documentation only — computed values are unchanged (#153). add_xy_position()/add_x_position()withscales = "free"now compute the bracket x positions (xmin/xmax) per facet, so they align correctly when a faceted plot (facet_*(scales = "free")) shows a different set of x-axis levels in each panel. Previously the global x positions were used, placing brackets off-panel in facets that didn't start from the first level.scales = "fixed"(default) and"free_y"are unchanged (#203).add_y_position()/add_xy_position()now handle repeated-measures test results whose stashed formula has theoutcome ~ within | subjectform (e.g.friedman_conover_test()): the| subjectblock is dropped when locating the x/grouping variable, so the brackets position correctly. Ordinaryoutcome ~ groupresults are unaffected (#8).anova_test()now gives clear, actionable error messages for two common repeated-measures data problems instead of cryptic ones: when the data has more than one observation per subject per within-subject cell ("duplicated cells"), and when no subject has a complete set of within-cell observations (previously a0 (non-NA) caseserror). Valid designs are unaffected (#216, #146, #116, #134, #102).- Updated the CRAN checks badge in the README to the current
badges.cranchecks.infoendpoint (the oldcranchecks.infobadge no longer resolves) (#174). - Clarified the
?anova_testdocumentation about contrasts: the formula /dv+between/withininterface fits the model internally withcontr.sum(matching SPSS / type-III), whereas a pre-fittedlm()/aov()keeps its own contrasts (R's defaultcontr.treatmentunless set otherwise) (#225). - Clarified the
?wilcox_effsizedocumentation of the sample sizeNused inr = Z/sqrt(N). For the one-sample and paired tests,Nis the number of pairs (difference scores), because the paired test reduces to a one-sample signed-rank test on the differences; this matches the default ofrcompanion::wilcoxonPairedR(). The alternative conventionN = 2 x pairs(Field, 2012; Tomczak & Tomczak, 2014) is now documented, with how to obtain it. Documentation only — computed effect sizes are unchanged (#213). - Removed all internal tidyselect deprecation warnings (
Use of .data in tidyselect expressions...,Using an external vector in selections..., andmutate_at()/pull()external-vector usage) across the package by selecting columns withall_of()/any_of(). This is an internal change only — results are unchanged — but it future-proofsrstatixagainst upcomingtidyselectversions and cleans up the test output (#202).
Bug fixes
-
kruskal_test()(and thereforekruskal_effsize()) now reports the number of observations actually used by the test asn, rather thannrow(data). When the outcome or group contained missing values,kruskal.test()dropped them but the reportednwas the inflated raw row count; becausekruskal_effsize()(eta²[H]) usesnin its denominator, the effect size could be wrong too.nis now the complete-case count (matching the test's own NA handling); the test statistic and p-value are unchanged, and data without NAs report the samenas before (#224). -
Grouped repeated-measures
anova_test()followed byget_anova_table()no longer errors (Can't combine <data.frame> and <list>) when the per-group results have different shapes — for example when one group needs a sphericity correction (so its result carries the Mauchly/sphericity-correction tables) while another does not. The internaldoo()helper now decides whether to unnest based on all groups rather than only the first, keeping heterogeneous results in a list-column soget_anova_table()can extract each group. Homogeneous grouped results (the usual case) are unchanged (#83). -
wilcox_test()no longer hides the warning when the underlyingwilcox.test()silently lowers the confidence interval's confidence level (e.g. to 60% instead of the requested 95%) because it cannot be achieved with tied or zero data. Previously this was suppressed, so the returned interval looked like a 95% CI and could contradict the p-value (e.g.p > 0.05while the CI excludes 0). A clear warning is now emitted in that case (only whendetailed = TRUE, i.e. when a CI is requested). The returned values are unchanged;t_test()and clean-data calls are unaffected (#127). -
games_howell_test()no longer crashes (`df` must be size 15 or 1, not 12) when groups have zero variance (constant values) or undefined variance (a single observation). The Welch correction is undefined for the affected pairs (degrees of freedom0/0, orNAvariance), so those comparisons are now returned asNAwith a warning while all other comparisons are computed as usual. Previously such data either errored or silently returned recycled/incorrect values. Results for data without zero/undefined-variance groups are unchanged (#183). -
add_xy_position()/add_y_position()now keep significance brackets evenly spaced after the test results have been filtered (e.g. to keep only significant comparisons). Previously the y positions were computed for the full comparison set and then joined onto the filtered rows, producing uneven spacing; they are now computed for exactly the comparisons present. Unfiltered results,ref.group = "all", one-sample and grouped tests are unchanged (#197). -
cor_test()(andcor_mat()) no longer emit the tidyselect "Using an external vector in selections was deprecated" warning whenvars/vars2are passed as character vectors (e.g.cor_test(data, vars = my_vars)); the columns are now selected viaall_of(). Bare names and tidyselect helpers are unaffected (#202). -
p_format()no longer strips a trailing0from the exponent of scientific-notation p-values (e.g.p_format(5.1e-10)returned"5.1e-1"; it now correctly returns"5.1e-10"). Ordinary decimal formatting, includingtrailing.zeropadding, is unchanged (#112). -
p_mark_significant()no longer produces"e-NA"(with a coercion warning) when given a scientific-notation p-value string such as the output ofp_format()on1e-4; it now correctly returns e.g."1e-04****"(#148). -
get_y_position()/add_y_position()now space significance brackets by exactlystep.increase. Previously the gap between consecutive brackets wasstep.increase * n/(n-1)(wider than requested) forn >= 2comparisons. This changes the computedy.positionvalues for plots with 3 or more groups (brackets are slightly closer together); single-comparison (two-group) plots andref.group = "all"are unchanged (#201). -
get_test_label()now includes the sample sizenfor ANOVA results (e.g.Anova, F(1,58) = 105.06, p = <0.0001, eta2[g] = 0.644, n = 60), consistent with the other tests; it was previously dropped because the slicing step stripped the attributesget_n()needs (#150). -
The comparison tests (
t_test(),wilcox_test(),dunn_test(),emmeans_test(), etc.) now drop unused levels of the grouping factor, so a filtered factor that still carries empty levels no longer triggers "not enough observations" errors — matchingstats::t.test()(#133). -
wilcox_test()andpairwise_wilcox_test()no longer error on degenerate (all-tied / constant) data. The location confidence interval (which can fail to compute on such data) is now requested only whendetailed = TRUE, so the default call returns gracefully;statistic/pare unchanged (#79, #167). -
anova_test()results (grouped and ungrouped) andget_anova_table()output are now compatible withdplyrverbs again (e.g.filter(),mutate(),add_xy_position()): the class order is corrected sorstatix_testprecedesdata.frame, which recentvctrs/dplyrrequire (#106, #111). -
cohens_d()now honours themuargument for two-sample tests (independent and paired):muis the hypothesized mean difference and is subtracted before standardizing, consistent with the one-sample case. Previouslymuwas silently ignored for two-sample tests. Calls using the defaultmu = 0are unchanged (#200). -
emmeans_test()no longer fails with "Nonconforming number of contrast coefficients" when thecovariateis a numeric variable with only two distinct values (e.g. a 0/1 indicator). The covariate is now correctly averaged over (ANCOVA) instead of being kept as a grid factor (#206, #86). -
kruskal_effsize()now clamps the eta-squared effect size to its valid[0, 1]range, so a near-null effect no longer returns a negative value (the formula could yield a small negative for a tinyH); consequently it is correctly labelled "small" rather than "large" (the magnitude had used the absolute value) (#217). -
anova_test()/anova_summary()now return both effect sizes wheneffect.size = c("pes", "ges")is requested; previously only partial eta squared was kept (#180). -
tukey_hsd()now respectsconf.level(and otherTukeyHSD()arguments) for the ungrouped data-frame interface; previously...was dropped so the confidence interval was always 95% (#188). -
pairwise_binom_test_against_p()no longer errors on an unnamedx; groups are auto-labelledgrp1,grp2, … (named/table input is unchanged) (#44). -
Fixed a missing space in the
anova_test()error message for single-level factors (now reads "Variable x has only one level") (#137). -
anova_test()results now carryrstatix_testas the first class, with the specific test class (anova_test/grouped_anova_test) in second position — matching every other rstatix test. The #106 dplyr/vctrs invariant (rstatix_testbeforedata.frame) is preserved, but the earlierc("anova_test", "rstatix_test", "data.frame")order had shifted the specific class out of position 2, breaking reverse dependencies that dispatch onclass(x)[2](e.g. GimmeMyStats, GimmeMyPlot).inherits(),print()/plot()dispatch, dplyr verbs and ggpubr are unaffected.