| Title: | Tidy Dataframes and Expressions with Statistical Details |
|---|---|
| Description: | Utilities for producing dataframes with rich details for the most common types of statistical approaches and tests: parametric, nonparametric, robust, and Bayesian t-test, one-way ANOVA, correlation analyses, contingency table analyses, and meta-analyses. The functions are pipe-friendly and provide a consistent syntax to work with tidy data. These dataframes additionally contain expressions with statistical details, and can be used in graphing packages. This package also forms the statistical processing backend for 'ggstatsplot'. References: Patil (2021) <doi:10.21105/joss.03236>. |
| Authors: | Indrajeet Patil [cre, aut, cph] (ORCID: <https://orcid.org/0000-0003-1995-6531>) |
| Maintainer: | Indrajeet Patil <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.2.0.9000 |
| Built: | 2026-10-18 21:00:59 UTC |
| Source: | https://github.com/indrajeetpatil/statsexpressions |
Creates an expression from a data frame containing statistical details.
Ideally, this data frame would come from having run tidy_model_parameters()
on your model object.
This function is currently not stable and should not be used outside of this package context.
add_expression_col( data, paired = FALSE, statistic.text = NULL, effsize.text = NULL, prior.type = NULL, n = NULL, n.text = list(if (paired) quote(italic("n")["pairs"]) else quote(italic("n")["obs"])), digits = 2L, digits.df = 0L, digits.df.error = digits.df, ... )add_expression_col( data, paired = FALSE, statistic.text = NULL, effsize.text = NULL, prior.type = NULL, n = NULL, n.text = list(if (paired) quote(italic("n")["pairs"]) else quote(italic("n")["obs"])), digits = 2L, digits.df = 0L, digits.df.error = digits.df, ... )
data |
A data frame containing details from the statistical analysis and should contain some or all of the following columns:
|
paired |
Logical that decides whether the experimental design is
repeated measures/within-subjects or between-subjects. The default is
|
statistic.text |
A list containing a |
effsize.text |
A list containing a |
prior.type |
Currently ignored. The prior label is inferred from the
|
n |
An integer specifying the sample size used for the test. Ignored if
|
n.text |
A list containing a |
digits, digits.df, digits.df.error
|
Number of decimal places to display
for the parameters ( |
... |
Currently ignored. |
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
set.seed(123) # creating a data frame with stats results stats_df <- cbind.data.frame( statistic = 5.494, df = 29.234, p.value = 0.00001, estimate = -1.980, conf.level = 0.95, conf.low = -2.873, conf.high = -1.088, method = "Student's t-test" ) # expression for *t*-statistic with Cohen's *d* as effect size # note that the plotmath expressions need to be quoted add_expression_col( data = stats_df, statistic.text = list(quote(italic("t"))), effsize.text = list(quote(italic("d"))), n = 32L, n.text = list(quote(italic("n")["no.obs"])), digits = 3L, digits.df = 3L )set.seed(123) # creating a data frame with stats results stats_df <- cbind.data.frame( statistic = 5.494, df = 29.234, p.value = 0.00001, estimate = -1.980, conf.level = 0.95, conf.low = -2.873, conf.high = -1.088, method = "Student's t-test" ) # expression for *t*-statistic with Cohen's *d* as effect size # note that the plotmath expressions need to be quoted add_expression_col( data = stats_df, statistic.text = list(quote(italic("t"))), effsize.text = list(quote(italic("d"))), n = 32L, n.text = list(quote(italic("n")["no.obs"])), digits = 3L, digits.df = 3L )
Tidy version of the "Bugs" dataset.
bugs_longbugs_long
A data frame with 372 rows and 6 variables
subject. Dummy identity number for each participant.
gender. Participant's gender (Female, Male).
region. Region of the world the participant was from.
education. Level of education.
condition. Condition of the experiment the participant gave rating for (LDLF: low disgustingness and low frighteningness; LDHF: low disgustingness and high frighteningness; HDLF: high disgustingness and low frighteningness; HDHF: high disgustingness and high frighteningness).
desire. The desire to kill an arthropod was indicated on a scale from 0 to 10.
This data set, "Bugs", provides the extent to which men and women want to kill arthropods that vary in frighteningness (low, high) and disgustingness (low, high). Each participant rates their attitudes towards all arthropods. Subset of the data reported by Ryan et al. (2013).
Ryan, R. S., Wilde, M., & Crist, S. (2013). Compared to a small, supervised lab experiment, a large, unsupervised web-based experiment on a previously unknown effect has benefits that outweigh its potential costs. Computers in Human Behavior, 29(4), 1295-1301.
dplyr::glimpse(bugs_long)dplyr::glimpse(bugs_long)
Parametric, non-parametric, robust, and Bayesian measures of centrality.
centrality_description( data, x, y, type = "parametric", conf.level = 0.95, tr = 0.2, digits = 2L, ... )centrality_description( data, x, y, type = "parametric", conf.level = 0.95, tr = 0.2, digits = 2L, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable in |
y |
The response (or outcome or dependent) variable from |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
conf.level |
Scalar between |
tr |
Trim level for the mean when carrying out |
digits |
Number of digits for rounding or significant figures. May also
be |
... |
Currently ignored. |
This function describes a distribution for y variable for each level of the
grouping variable in x by a set of indices (e.g., measures of centrality,
dispersion, range, skewness, kurtosis, etc.). It additionally returns an
expression containing a specified centrality measure. The function internally
relies on datawizard::describe_distribution() function.
The returned object is a tibble data frame with the additional class
"statsExpressions". Unlike the hypothesis-testing functions, this one returns
one row per level of the grouping variable x, describing the distribution
of y within that level. The columns are:
the grouping variable (named after x, e.g. Species)
the requested centrality estimate (named after y, e.g. Sepal.Length):
the mean (type = "parametric"), median ("nonparametric"), trimmed mean
("robust"), or MAP estimate ("bayes")
std.dev: standard deviation (for "parametric" and "robust")
mad: median absolute deviation (for "nonparametric"); neither std.dev
nor mad is returned for "bayes"
iqr: interquartile range
conf.low, conf.high: bounds of the confidence/credible interval for the
centrality estimate
min, max: minimum and maximum values
skewness, kurtosis: shape statistics of the distribution
n.obs: number of non-missing observations
missing.obs: number of missing observations after filtering (always
0, since rows with missing x or y are removed before summarizing)
expression: a list-column of pre-formatted
plotmath expressions (each
element is a language object, not a character string) containing the
centrality estimate, ready to be used in {ggplot2}
n.expression: a label combining the group name and its sample size (e.g.
"setosa\n(n = 50)"), useful as an axis or facet label
For more examples, see the Data frame outputs and the Return value schema articles.
| Type | Measure | Function used |
| Parametric | mean | datawizard::describe_distribution() |
| Non-parametric | median | datawizard::describe_distribution() |
| Robust | trimmed mean | datawizard::describe_distribution() |
| Bayesian | MAP | datawizard::describe_distribution()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# for reproducibility set.seed(123) # ----------------------- parametric ----------------------- centrality_description(iris, Species, Sepal.Length, type = "parametric") # ----------------------- non-parametric ------------------- centrality_description(mtcars, am, wt, type = "nonparametric") # ----------------------- robust --------------------------- centrality_description(ToothGrowth, supp, len, type = "robust") # ----------------------- Bayesian ------------------------- centrality_description(sleep, group, extra, type = "bayes")# for reproducibility set.seed(123) # ----------------------- parametric ----------------------- centrality_description(iris, Species, Sepal.Length, type = "parametric") # ----------------------- non-parametric ------------------- centrality_description(mtcars, am, wt, type = "nonparametric") # ----------------------- robust --------------------------- centrality_description(ToothGrowth, supp, len, type = "robust") # ----------------------- Bayesian ------------------------- centrality_description(sleep, group, extra, type = "bayes")
Prepares long/tidy repeated measures data for analysis by keeping only the
subjects observed in every level of x. This is the listwise deletion step
that long_to_wide_converter() applies when paired = TRUE, and thus the
data that two_sample_test(), oneway_anova(), and
pairwise_comparisons() analyze for within-subjects designs.
The following steps are carried out:
Rows with a missing x or subject.id are dropped, since they cannot be
paired.
An error is thrown if any subject has more than one row in a level of x.
Subjects with a missing y value, or without a row, in any level of x
are removed entirely.
complete_subjects(data, x, y, subject.id = NULL)complete_subjects(data, x, y, subject.id = NULL)
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable from |
y |
The response (or outcome or dependent) variable from |
subject.id |
Relevant in case of a repeated measures or within-subjects
design (i.e., |
A tibble in long format with columns .rowid (the subject
identifier, or an internal row identifier when subject.id is NULL),
x (as a factor with unused levels dropped), and y, sorted by .rowid.
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# subjects with a missing rating in any condition are removed complete_subjects(bugs_long, condition, desire, subject.id = subject)# subjects with a missing rating in any condition are removed complete_subjects(bugs_long, condition, desire, subject.id = subject)
Parametric and Bayesian one-way and two-way contingency table analyses.
contingency_table( data, x, y = NULL, paired = FALSE, type = "parametric", counts = NULL, ratio = NULL, alternative = "two.sided", digits = 2L, conf.level = 0.95, sampling.plan = "indepMulti", fixed.margin = "rows", prior.concentration = 1, ... )contingency_table( data, x, y = NULL, paired = FALSE, type = "parametric", counts = NULL, ratio = NULL, alternative = "two.sided", digits = 2L, conf.level = 0.95, sampling.plan = "indepMulti", fixed.margin = "rows", prior.concentration = 1, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The variable to use as the rows in the contingency table. |
y |
The variable to use as the columns in the contingency table.
Default is |
paired |
Logical indicating whether data came from a within-subjects or
repeated measures design study (Default: |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
counts |
The variable in data containing counts, or |
ratio |
A vector of proportions: the expected proportions for the
proportion test (should sum to |
alternative |
A character string specifying the alternative hypothesis;
Controls the type of CI returned: |
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
sampling.plan |
Character describing the sampling plan. Possible options:
Only used for Bayesian two-way tables. For more, see
|
fixed.margin |
For the independent multinomial sampling plan, which
margin is fixed ( |
prior.concentration |
Specifies the prior concentration parameter, set
to |
... |
Additional arguments (currently ignored). |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
There are no dedicated non-parametric or robust contingency table analyses.
type = "nonparametric" and type = "robust" are accepted, but run the same
frequentist tests as type = "parametric" (the "Parametric/Non-parametric" rows
below).
Hypothesis testing
| Type | Design | Test | Function used |
| Parametric/Non-parametric | Unpaired | Pearson's chi-squared test | stats::chisq.test() |
| Bayesian | Unpaired | Bayesian Pearson's chi-squared test | BayesFactor::contingencyTableBF() |
| Parametric/Non-parametric | Paired | McNemar's chi-squared test | stats::mcnemar.test() |
| Bayesian | Paired | No | No |
Effect size estimation
| Type | Design | Effect size | CI available? | Function used |
| Parametric/Non-parametric | Unpaired | Cramer's V | Yes | effectsize::cramers_v() |
| Bayesian | Unpaired | Cramer's V | Yes | effectsize::cramers_v() |
| Parametric/Non-parametric | Paired | Cohen's g | Yes | effectsize::cohens_g() |
| Bayesian | Paired | No | No | No |
Paired Bayesian analysis is not supported: for a two-way table with
type = "bayes", the paired argument is ignored and the unpaired Bayesian
test is run instead.
Hypothesis testing
| Type | Test | Function used |
| Parametric/Non-parametric | Goodness of fit chi-squared test | stats::chisq.test() |
| Bayesian | Bayesian Goodness of fit chi-squared test | (custom) |
Effect size estimation
| Type | Effect size | CI available? | Function used |
| Parametric/Non-parametric | Pearson's C | Yes | effectsize::pearsons_c() |
| Bayesian | No | No | No |
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
#### -------------------- association test ------------------------ #### # ------------------------ frequentist --------------------------------- # unpaired set.seed(123) contingency_table( data = mtcars, x = am, y = vs, paired = FALSE ) # paired paired_data <- dplyr::tibble( response_before = factor(c("no", "yes", "no", "yes")), response_after = factor(c("no", "no", "yes", "yes")), Freq = c(65L, 25L, 5L, 5L) ) set.seed(123) contingency_table( data = paired_data, x = response_before, y = response_after, paired = TRUE, counts = Freq ) # ------------------------ Bayesian ------------------------------------- # unpaired set.seed(123) contingency_table( data = mtcars, x = am, y = vs, paired = FALSE, type = "bayes" ) # paired set.seed(123) contingency_table( data = paired_data, x = response_before, y = response_after, paired = TRUE, counts = Freq, type = "bayes" ) #### -------------------- goodness-of-fit test -------------------- #### # ------------------------ frequentist --------------------------------- set.seed(123) contingency_table( data = as.data.frame(HairEyeColor), x = Eye, counts = Freq ) # ------------------------ Bayesian ------------------------------------- set.seed(123) contingency_table( data = as.data.frame(HairEyeColor), x = Eye, counts = Freq, ratio = c(0.2, 0.2, 0.3, 0.3), type = "bayes" )#### -------------------- association test ------------------------ #### # ------------------------ frequentist --------------------------------- # unpaired set.seed(123) contingency_table( data = mtcars, x = am, y = vs, paired = FALSE ) # paired paired_data <- dplyr::tibble( response_before = factor(c("no", "yes", "no", "yes")), response_after = factor(c("no", "no", "yes", "yes")), Freq = c(65L, 25L, 5L, 5L) ) set.seed(123) contingency_table( data = paired_data, x = response_before, y = response_after, paired = TRUE, counts = Freq ) # ------------------------ Bayesian ------------------------------------- # unpaired set.seed(123) contingency_table( data = mtcars, x = am, y = vs, paired = FALSE, type = "bayes" ) # paired set.seed(123) contingency_table( data = paired_data, x = response_before, y = response_after, paired = TRUE, counts = Freq, type = "bayes" ) #### -------------------- goodness-of-fit test -------------------- #### # ------------------------ frequentist --------------------------------- set.seed(123) contingency_table( data = as.data.frame(HairEyeColor), x = Eye, counts = Freq ) # ------------------------ Bayesian ------------------------------------- set.seed(123) contingency_table( data = as.data.frame(HairEyeColor), x = Eye, counts = Freq, ratio = c(0.2, 0.2, 0.3, 0.3), type = "bayes" )
Parametric, non-parametric, robust, and Bayesian correlation test.
corr_test( data, x, y, type = "parametric", digits = 2L, conf.level = 0.95, tr = 0.2, bf.prior = 0.707, ... )corr_test( data, x, y, type = "parametric", digits = 2L, conf.level = 0.95, tr = 0.2, bf.prior = 0.707, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The column in |
y |
The column in |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
tr |
Trim level for the mean when carrying out |
bf.prior |
A number between |
... |
Additional arguments (currently ignored). |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing and effect size estimation
| Type | Test | CI available? | Function used |
| Parametric | Pearson's correlation coefficient | Yes | correlation::correlation() |
| Non-parametric | Spearman's rank correlation coefficient | Yes | correlation::correlation() |
| Robust | Winsorized Pearson's correlation coefficient | Yes | correlation::correlation() |
| Bayesian | Bayesian Pearson's correlation coefficient | Yes | correlation::correlation()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# for reproducibility set.seed(123) # ----------------------- parametric ----------------------- corr_test(mtcars, wt, mpg, type = "parametric") # ----------------------- non-parametric ------------------- corr_test(mtcars, wt, mpg, type = "nonparametric") # ----------------------- robust --------------------------- corr_test(mtcars, wt, mpg, type = "robust") # ----------------------- Bayesian ------------------------- corr_test(mtcars, wt, mpg, type = "bayes")# for reproducibility set.seed(123) # ----------------------- parametric ----------------------- corr_test(mtcars, wt, mpg, type = "parametric") # ----------------------- non-parametric ------------------- corr_test(mtcars, wt, mpg, type = "nonparametric") # ----------------------- robust --------------------------- corr_test(mtcars, wt, mpg, type = "robust") # ----------------------- Bayesian ------------------------- corr_test(mtcars, wt, mpg, type = "bayes")
Relevant mostly for {ggstatsplot} and {statsExpressions} packages, where
different statistical approaches are supported via this argument: parametric,
non-parametric, robust, and Bayesian. This switch function converts strings
entered by users to a common pattern for convenience.
stats_type_switch() is an alias of extract_stats_type().
extract_stats_type(type) stats_type_switch(type)extract_stats_type(type) stats_type_switch(type)
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
A character vector of the same length as type, with values
"parametric", "nonparametric", "robust", or "bayes".
extract_stats_type("p") extract_stats_type("bf") extract_stats_type(c("np", "robust", "Bayes"))extract_stats_type("p") extract_stats_type("bf") extract_stats_type(c("np", "robust", "Bayes"))
Edgar Anderson's Iris Data in long format.
iris_longiris_long
A data frame with 600 rows and 6 variables
id. Dummy identity number for each flower (150 flowers in total).
Species. The species are Iris setosa, versicolor, and virginica.
condition. Factor giving a detailed description of the attribute
(Four levels: "Petal.Length", "Petal.Width", "Sepal.Length",
"Sepal.Width").
attribute. What attribute is being measured ("Sepal" or "Petal").
measure. What aspect of the attribute is being measured ("Length"
or "Width").
value. Value of the measurement.
This famous (Fisher's or Anderson's) iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica.
This is a modified dataset from {datasets} package.
dplyr::glimpse(iris_long)dplyr::glimpse(iris_long)
This conversion is helpful mostly for repeated measures design, where
removing NAs by participant can be a bit tedious.
long_to_wide_converter( data, x, y, subject.id = NULL, paired = TRUE, spread = TRUE, ... )long_to_wide_converter( data, x, y, subject.id = NULL, paired = TRUE, spread = TRUE, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable from |
y |
The response (or outcome or dependent) variable from |
subject.id |
Relevant in case of a repeated measures or within-subjects
design (i.e., |
paired |
Logical that decides whether the experimental design is
repeated measures/within-subjects or between-subjects. The default is
|
spread |
Logical that decides whether the data frame needs to be
converted from long/tidy to wide (default: |
... |
Currently ignored. |
A tibble with NAs removed while respecting the
between-or-within-subjects nature of the dataset: for paired designs, only
subjects observed in every level of x are kept (a subject with a missing
value or a missing row in any condition is removed entirely), while for
unpaired designs only the rows with missing values are removed. Rows are
grouped by subject.id whenever it is supplied, so with paired = FALSE
and a subject.id, a missing value still removes every row of that
subject. The .rowid column contains the subject identifier (or an
internal row identifier).
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# repeated measures design long_to_wide_converter( bugs_long, condition, desire, subject.id = subject, paired = TRUE ) # independent measures design long_to_wide_converter(mtcars, cyl, wt, paired = FALSE)# repeated measures design long_to_wide_converter( bugs_long, condition, desire, subject.id = subject, paired = TRUE ) # independent measures design long_to_wide_converter(mtcars, cyl, wt, paired = FALSE)
Parametric, robust, and Bayesian random-effects meta-analysis.
A non-parametric meta-analysis is not available, so type = "nonparametric"
is not supported.
meta_analysis( data, type = "parametric", random = "mixture", digits = 2L, conf.level = 0.95, ... )meta_analysis( data, type = "parametric", random = "mixture", digits = 2L, conf.level = 0.95, ... )
data |
A data frame. It must contain columns named
|
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
random |
The type of random-effects distribution for the robust
meta-analysis: |
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
... |
Additional arguments passed to the respective meta-analysis function. |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing and effect size estimation
| Type | Test | Effect size | CI available? | Function used |
| Parametric | Meta-analysis via random-effects models | beta | Yes | metafor::rma() |
| Robust | Meta-analysis via robust random-effects models | beta | Yes | metaplus::metaplus() |
| Bayesian | Meta-analysis via Bayesian random-effects models | beta | Yes | metaBMA::meta_random()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
The package needed for the chosen type ({metafor}, {metaplus}, or
{metaBMA}) is only suggested, so you will be asked to install it if it is
not available.
# let's use `mag` dataset from `{metaplus}` data(mag, package = "metaplus") dat <- dplyr::rename(mag, estimate = yi, std.error = sei) # ----------------------- parametric --------------------------------------- set.seed(123) meta_analysis(dat) # ----------------------- robust -------------------------------------------- set.seed(123) meta_analysis(dat, type = "robust", random = "normal") # ----------------------- Bayesian ------------------------------------------ # suppress warnings about divergent transitions after warmup set.seed(123) suppressWarnings(meta_analysis(dat, type = "bayes"))# let's use `mag` dataset from `{metaplus}` data(mag, package = "metaplus") dat <- dplyr::rename(mag, estimate = yi, std.error = sei) # ----------------------- parametric --------------------------------------- set.seed(123) meta_analysis(dat) # ----------------------- robust -------------------------------------------- set.seed(123) meta_analysis(dat, type = "robust", random = "normal") # ----------------------- Bayesian ------------------------------------------ # suppress warnings about divergent transitions after warmup set.seed(123) suppressWarnings(meta_analysis(dat, type = "bayes"))
Movie information and user ratings from IMDB.
movies_longmovies_long
A data frame with 1,579 rows and 8 variables
title. Title of the movie.
year. Year of release.
budget. Total budget (if known) in US dollars.
length. Length in minutes.
rating. Average IMDB user rating.
votes. Number of IMDB users who rated this movie.
mpaa. MPAA rating.
genre. Genre of the movie ("Action", "Action Comedy",
"Action Drama", "Animated", "Comedy", "Comedy Drama", "Drama",
"Romance Drama", "RomCom").
Modified dataset from {ggplot2movies} package.
https://CRAN.R-project.org/package=ggplot2movies
dplyr::glimpse(movies_long)dplyr::glimpse(movies_long)
Parametric, non-parametric, robust, and Bayesian one-sample tests.
one_sample_test( data, x, type = "parametric", test.value = 0, alternative = "two.sided", digits = 2L, conf.level = 0.95, tr = 0.2, bf.prior = 0.707, effsize.type = "g", exact = FALSE, ... )one_sample_test( data, x, type = "parametric", test.value = 0, alternative = "two.sided", digits = 2L, conf.level = 0.95, tr = 0.2, bf.prior = 0.707, effsize.type = "g", exact = FALSE, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
A numeric variable from the data frame |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
test.value |
A number indicating the true value of the mean (Default:
|
alternative |
a character string specifying the alternative
hypothesis, must be one of |
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
tr |
Trim level for the mean when carrying out |
bf.prior |
A number between |
effsize.type |
Type of effect size needed for parametric tests. The
argument can be |
exact |
A logical indicating whether exact p-values should be
computed. Relevant only when |
... |
Currently ignored. |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing
| Type | Test | Function used |
| Parametric | One-sample Student's t-test | stats::t.test() |
| Non-parametric | One-sample Wilcoxon test | stats::wilcox.test() |
| Robust | Bootstrap-t method for one-sample test | WRS2::trimcibt() |
| Bayesian | One-sample Student's t-test | BayesFactor::ttestBF()
|
Effect size estimation
| Type | Effect size | CI available? | Function used |
| Parametric | Cohen's d, Hedges' g | Yes | effectsize::cohens_d(), effectsize::hedges_g() |
| Non-parametric | r (rank-biserial correlation) | Yes | effectsize::rank_biserial() |
| Robust | trimmed mean | Yes | WRS2::trimcibt() |
| Bayesian | difference | Yes | bayestestR::describe_posterior()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# for reproducibility set.seed(123) # ----------------------- parametric ----------------------- one_sample_test(mtcars, wt, test.value = 3) # biased (Cohen's d) effect size one_sample_test(mtcars, wt, test.value = 3, effsize.type = "d") # ----------------------- non-parametric ------------------- one_sample_test(mtcars, wt, test.value = 3, type = "nonparametric") # ----------------------- robust --------------------------- one_sample_test(mtcars, wt, test.value = 3, type = "robust") # ----------------------- Bayesian ------------------------- one_sample_test(mtcars, wt, test.value = 3, type = "bayes")# for reproducibility set.seed(123) # ----------------------- parametric ----------------------- one_sample_test(mtcars, wt, test.value = 3) # biased (Cohen's d) effect size one_sample_test(mtcars, wt, test.value = 3, effsize.type = "d") # ----------------------- non-parametric ------------------- one_sample_test(mtcars, wt, test.value = 3, type = "nonparametric") # ----------------------- robust --------------------------- one_sample_test(mtcars, wt, test.value = 3, type = "robust") # ----------------------- Bayesian ------------------------- one_sample_test(mtcars, wt, test.value = 3, type = "bayes")
Parametric, non-parametric, robust, and Bayesian one-way ANOVA.
oneway_anova( data, x, y, subject.id = NULL, type = "parametric", paired = FALSE, digits = 2L, conf.level = 0.95, effsize.type = "omega", var.equal = FALSE, bf.prior = 0.707, tr = 0.2, nboot = 100L, ... )oneway_anova( data, x, y, subject.id = NULL, type = "parametric", paired = FALSE, digits = 2L, conf.level = 0.95, effsize.type = "omega", var.equal = FALSE, bf.prior = 0.707, tr = 0.2, nboot = 100L, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable from |
y |
The response (or outcome or dependent) variable from |
subject.id |
Relevant in case of a repeated measures or within-subjects
design (i.e., |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
paired |
Logical that decides whether the experimental design is
repeated measures/within-subjects or between-subjects. The default is
|
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
effsize.type |
Type of effect size needed for parametric tests. The
argument can be |
var.equal |
a logical variable indicating whether to treat the
two variances as being equal. If |
bf.prior |
A number between |
tr |
Trim level for the mean when carrying out |
nboot |
Number of bootstrap samples for computing confidence interval
for the effect size (Default: |
... |
Additional arguments (currently ignored). |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing
| Type | No. of groups | Test | Function used |
| Parametric | > 2 | Fisher's or Welch's one-way ANOVA | stats::oneway.test() |
| Non-parametric | > 2 | Kruskal-Wallis one-way ANOVA | stats::kruskal.test() |
| Robust | > 2 | Heteroscedastic one-way ANOVA for trimmed means | WRS2::t1way() |
| Bayesian | > 2 | Fisher's ANOVA | BayesFactor::anovaBF()
|
Effect size estimation
| Type | No. of groups | Effect size | CI available? | Function used |
| Parametric | > 2 | partial eta-squared, partial omega-squared | Yes | effectsize::omega_squared(), effectsize::eta_squared() |
| Non-parametric | > 2 | rank epsilon squared | Yes | effectsize::rank_epsilon_squared() |
| Robust | > 2 | Explanatory measure of effect size | Yes | WRS2::t1way() |
| Bayesian | > 2 | Bayesian R-squared | Yes | performance::r2_bayes()
|
Paired data: See complete_subjects() for subject matching, duplicate
observations, and removal of incomplete subjects.
Hypothesis testing
| Type | No. of groups | Test | Function used |
| Parametric | > 2 | One-way repeated measures ANOVA | afex::aov_ez() |
| Non-parametric | > 2 | Friedman rank sum test | stats::friedman.test() |
| Robust | > 2 | Heteroscedastic one-way repeated measures ANOVA for trimmed means | WRS2::rmanova() |
| Bayesian | > 2 | One-way repeated measures ANOVA | BayesFactor::anovaBF()
|
Effect size estimation
| Type | No. of groups | Effect size | CI available? | Function used |
| Parametric | > 2 | partial eta-squared, partial omega-squared | Yes | effectsize::omega_squared(), effectsize::eta_squared() |
| Non-parametric | > 2 | Kendall's coefficient of concordance | Yes | effectsize::kendalls_w() |
| Robust | > 2 | Algina-Keselman-Penfield robust standardized difference average | Yes | WRS2::wmcpAKP() |
| Bayesian | > 2 | Bayesian R-squared | Yes | performance::r2_bayes()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# for reproducibility set.seed(123) # ----------------------- parametric ------------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt ) # biased (partial eta-squared) effect size oneway_anova( data = mtcars, x = cyl, y = wt, effsize.type = "eta" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE ) # ----------------------- non-parametric ---------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt, type = "np" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE, type = "np" ) # ----------------------- robust ------------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt, type = "r" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE, type = "r" ) # ----------------------- Bayesian ------------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt, type = "bayes" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE, type = "bayes" )# for reproducibility set.seed(123) # ----------------------- parametric ------------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt ) # biased (partial eta-squared) effect size oneway_anova( data = mtcars, x = cyl, y = wt, effsize.type = "eta" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE ) # ----------------------- non-parametric ---------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt, type = "np" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE, type = "np" ) # ----------------------- robust ------------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt, type = "r" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE, type = "r" ) # ----------------------- Bayesian ------------------------------------- # between-subjects oneway_anova( data = mtcars, x = cyl, y = wt, type = "bayes" ) # within-subjects design oneway_anova( data = bugs_long, x = condition, y = desire, subject.id = subject, paired = TRUE, type = "bayes" )
Calculate parametric, non-parametric, robust, and Bayes Factor pairwise comparisons between group levels with corrections for multiple testing.
pairwise_comparisons( data, x, y, subject.id = NULL, type = "parametric", paired = FALSE, var.equal = FALSE, tr = 0.2, bf.prior = 0.707, p.adjust.method = "holm", digits = 2L, exact = FALSE, ... )pairwise_comparisons( data, x, y, subject.id = NULL, type = "parametric", paired = FALSE, var.equal = FALSE, tr = 0.2, bf.prior = 0.707, p.adjust.method = "holm", digits = 2L, exact = FALSE, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable from |
y |
The response (or outcome or dependent) variable from |
subject.id |
Relevant in case of a repeated measures or within-subjects
design (i.e., |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
paired |
Logical that decides whether the experimental design is
repeated measures/within-subjects or between-subjects. The default is
|
var.equal |
a logical variable indicating whether to treat the
two variances as being equal. If |
tr |
Trim level for the mean when carrying out |
bf.prior |
A number between |
p.adjust.method |
Adjustment method for p-values for multiple
comparisons. Possible methods are: |
digits |
Number of digits for rounding or significant figures. May also
be |
exact |
A logical indicating whether exact p-values should be
computed. Relevant only when |
... |
Additional arguments passed to the underlying pairwise test
function for the parametric and non-parametric tests (see the table
below). Ignored for robust tests. For Bayesian tests, they are passed to
the frequentist test ( |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing
| Type | Equal variance? | Test | p-value adjustment? | Function used |
| Parametric | No | Games-Howell test | Yes | PMCMRplus::gamesHowellTest() |
| Parametric | Yes | Student's t-test | Yes | stats::pairwise.t.test() |
| Non-parametric | No | Dunn test | Yes | PMCMRplus::kwAllPairsDunnTest() |
| Robust | No | Yuen's trimmed means test | Yes | WRS2::lincon() |
| Bayesian | NA |
Student's t-test | NA |
BayesFactor::ttestBF()
|
Effect size estimation
Not supported.
Paired data: See complete_subjects() for subject matching, duplicate
observations, and removal of incomplete subjects.
Hypothesis testing
| Type | Test | p-value adjustment? | Function used |
| Parametric | Student's t-test | Yes | stats::pairwise.t.test() |
| Non-parametric | Durbin-Conover test | Yes | PMCMRplus::durbinAllPairsTest() |
| Robust | Yuen's trimmed means test | Yes | WRS2::rmmcp() |
| Bayesian | Student's t-test | NA |
BayesFactor::ttestBF()
|
Effect size estimation
Not supported.
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
For more, see: https://www.indrapatil.com/ggstatsplot/articles/web_only/pairwise.html
# for reproducibility set.seed(123) #------------------- between-subjects design ---------------------------- # parametric # if `var.equal = TRUE`, then Student's t-test will be run pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "parametric", var.equal = TRUE, paired = FALSE, p.adjust.method = "none" ) # if `var.equal = FALSE`, then Games-Howell test will be run pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "parametric", var.equal = FALSE, paired = FALSE, p.adjust.method = "bonferroni" ) # non-parametric (Dunn test) pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "nonparametric", paired = FALSE, p.adjust.method = "none" ) # robust (Yuen's trimmed means t-test) pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "robust", paired = FALSE, p.adjust.method = "fdr" ) # Bayes Factor (Student's t-test) pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "bayes", paired = FALSE ) #------------------- within-subjects design ---------------------------- # parametric (Student's t-test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "parametric", paired = TRUE, p.adjust.method = "BH" ) # non-parametric (Durbin-Conover test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "nonparametric", paired = TRUE, p.adjust.method = "BY" ) # robust (Yuen's trimmed means t-test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "robust", paired = TRUE, p.adjust.method = "hommel" ) # Bayes Factor (Student's t-test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "bayes", paired = TRUE )# for reproducibility set.seed(123) #------------------- between-subjects design ---------------------------- # parametric # if `var.equal = TRUE`, then Student's t-test will be run pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "parametric", var.equal = TRUE, paired = FALSE, p.adjust.method = "none" ) # if `var.equal = FALSE`, then Games-Howell test will be run pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "parametric", var.equal = FALSE, paired = FALSE, p.adjust.method = "bonferroni" ) # non-parametric (Dunn test) pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "nonparametric", paired = FALSE, p.adjust.method = "none" ) # robust (Yuen's trimmed means t-test) pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "robust", paired = FALSE, p.adjust.method = "fdr" ) # Bayes Factor (Student's t-test) pairwise_comparisons( data = mtcars, x = cyl, y = wt, type = "bayes", paired = FALSE ) #------------------- within-subjects design ---------------------------- # parametric (Student's t-test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "parametric", paired = TRUE, p.adjust.method = "BH" ) # non-parametric (Durbin-Conover test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "nonparametric", paired = TRUE, p.adjust.method = "BY" ) # robust (Yuen's trimmed means t-test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "robust", paired = TRUE, p.adjust.method = "hommel" ) # Bayes Factor (Student's t-test) pairwise_comparisons( data = bugs_long, x = condition, y = desire, subject.id = subject, type = "bayes", paired = TRUE )
Pairwise Fisher's exact tests as post hoc tests for contingency table analyses, with effect sizes (Cramer's V) and p-value adjustment for multiple comparisons.
pairwise_contingency_table( data, x, y, counts = NULL, p.adjust.method = "holm", digits = 2L, conf.level = 0.95, alternative = "two.sided", ... )pairwise_contingency_table( data, x, y, counts = NULL, p.adjust.method = "holm", digits = 2L, conf.level = 0.95, alternative = "two.sided", ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The variable to use as the rows in the contingency table. |
y |
The variable to use as the columns in the contingency table.
Default is |
counts |
The variable in data containing counts, or |
p.adjust.method |
Adjustment method for p-values for multiple
comparisons. Possible methods are: |
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
alternative |
A character string specifying the alternative hypothesis;
Controls the type of CI returned: |
... |
Additional arguments passed to |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing
| Test | p-value adjustment? | Function used |
| Fisher's exact test | Yes | stats::fisher.test()
|
Effect size estimation
| Effect size | CI available? | Function used |
| Cramer's V | Yes | effectsize::cramers_v()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# for reproducibility set.seed(123) # pairwise Fisher's exact tests with Holm adjustment pairwise_contingency_table( data = mtcars, x = cyl, y = am, p.adjust.method = "holm" ) # with counts data and Bonferroni adjustment pairwise_contingency_table( data = as.data.frame(Titanic), x = Class, y = Survived, counts = Freq, p.adjust.method = "bonferroni" )# for reproducibility set.seed(123) # pairwise Fisher's exact tests with Holm adjustment pairwise_contingency_table( data = mtcars, x = cyl, y = am, p.adjust.method = "holm" ) # with counts data and Bonferroni adjustment pairwise_contingency_table( data = as.data.frame(Titanic), x = Class, y = Survived, counts = Freq, p.adjust.method = "bonferroni" )
Expressions with statistics for tidy regression data frames
tidy_model_expressions( data, statistic = NULL, digits = 2L, effsize.type = "omega", ... )tidy_model_expressions( data, statistic = NULL, digits = 2L, effsize.type = "omega", ... )
data |
A tidy data frame from regression model object (see
|
statistic |
Which statistic is to be displayed (either |
digits |
Number of digits for rounding or significant figures. May also
be |
effsize.type |
Type of effect size needed for parametric tests. The
argument can be |
... |
Currently ignored. |
When any of the necessary numeric column values (estimate, statistic,
p.value) are missing, for these rows, a NULL is returned instead of an
expression with empty strings.
The input data frame (as a tibble) with an additional expression
list-column.
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
set.seed(123) # t-statistic from a tidy linear model data frame df <- tidy_model_parameters(lm(wt ~ am * cyl, mtcars)) tidy_model_expressions(df, statistic = "t") # f-statistic (requires a data frame with `df`, `df.error`, and effect-size columns) df_f <- tidy_model_parameters( aov(wt ~ cyl, mtcars), es_type = "omega", table_wide = TRUE ) tidy_model_expressions(df_f, statistic = "f") df_f_eta <- tidy_model_parameters( aov(wt ~ cyl, mtcars), es_type = "eta", table_wide = TRUE ) tidy_model_expressions(df_f_eta, statistic = "f", effsize.type = "eta")set.seed(123) # t-statistic from a tidy linear model data frame df <- tidy_model_parameters(lm(wt ~ am * cyl, mtcars)) tidy_model_expressions(df, statistic = "t") # f-statistic (requires a data frame with `df`, `df.error`, and effect-size columns) df_f <- tidy_model_parameters( aov(wt ~ cyl, mtcars), es_type = "omega", table_wide = TRUE ) tidy_model_expressions(df_f, statistic = "f") df_f_eta <- tidy_model_parameters( aov(wt ~ cyl, mtcars), es_type = "eta", table_wide = TRUE ) tidy_model_expressions(df_f_eta, statistic = "f", effsize.type = "eta")
{parameters} package output to {tidyverse} conventionsRuns parameters::model_parameters() on a model object and standardizes
the result to {broom}-style column names (e.g. estimate, std.error,
conf.low, conf.high, statistic, df.error, p.value). Bayes factors
are returned in a bf10 column, along with their natural logarithm in
log_e_bf10. For Bayesian ANOVA designs ({BayesFactor} linear models),
the estimate is replaced by the Bayesian R-squared.
tidy_model_parameters(model, ...)tidy_model_parameters(model, ...)
model |
Statistical Model. |
... |
Arguments passed to or from other methods. Non-documented arguments are
|
A tibble with one row per parameter.
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
model <- lm(mpg ~ wt + cyl, data = mtcars) tidy_model_parameters(model)model <- lm(mpg ~ wt + cyl, data = mtcars) tidy_model_parameters(model)
Parametric, non-parametric, robust, and Bayesian two-sample tests.
two_sample_test( data, x, y, subject.id = NULL, type = "parametric", paired = FALSE, alternative = "two.sided", digits = 2L, conf.level = 0.95, effsize.type = "g", var.equal = FALSE, bf.prior = 0.707, tr = 0.2, nboot = 100L, exact = FALSE, ... )two_sample_test( data, x, y, subject.id = NULL, type = "parametric", paired = FALSE, alternative = "two.sided", digits = 2L, conf.level = 0.95, effsize.type = "g", var.equal = FALSE, bf.prior = 0.707, tr = 0.2, nboot = 100L, exact = FALSE, ... )
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable from |
y |
The response (or outcome or dependent) variable from |
subject.id |
Relevant in case of a repeated measures or within-subjects
design (i.e., |
type |
A character specifying the type of statistical approach:
You can specify just the initial letter (e.g. |
paired |
Logical that decides whether the experimental design is
repeated measures/within-subjects or between-subjects. The default is
|
alternative |
a character string specifying the alternative
hypothesis, must be one of |
digits |
Number of digits for rounding or significant figures. May also
be |
conf.level |
Scalar between |
effsize.type |
Type of effect size needed for parametric tests. The
argument can be |
var.equal |
a logical variable indicating whether to treat the
two variances as being equal. If |
bf.prior |
A number between |
tr |
Trim level for the mean when carrying out |
nboot |
Number of bootstrap samples for computing confidence interval
for the effect size (Default: |
exact |
A logical indicating whether exact p-values should be
computed. Relevant only when |
... |
Currently ignored. |
The returned object is a tibble data frame with the additional class
"statsExpressions". The exact set of columns depends on the test and, for
functions that accept a type argument, on the chosen analysis (parametric,
non-parametric, robust, or Bayesian). Any given call therefore returns some
(not all) of the columns below.
Hypothesis testing
statistic: the numeric value of a statistic
df and/or df.error: degrees of freedom for the test. A t-test
uses df.error, a chi-squared test uses df, and a parametric ANOVA
uses both (numerator df and denominator df.error)
p.value: the p-value associated with the observed statistic (two-sided
unless a one-sided alternative is requested, where supported)
method: the name of the inferential statistical test
Effect size estimation
effectsize: the name of the effect size
estimate: estimated value of the effect size
conf.level: the coverage level of the confidence/credible interval
(e.g. 0.95); the interval itself spans conf.low to conf.high
conf.low: lower bound for the effect size estimate
conf.high: upper bound for the effect size estimate
conf.method: method used to compute the confidence/credible interval
conf.distribution: statistical distribution for the effect
Bayesian analysis (only when type = "bayes")
bf10: Bayes factor for the alternative hypothesis relative to the null
log_e_bf10: natural logarithm of the Bayes factor (present for most, but
not all, Bayesian analyses)
prior.distribution, prior.scale, prior.location: prior specification
used to compute the Bayes factor and posterior estimates
Pairwise comparisons (for pairwise_comparisons() and
pairwise_contingency_table())
group1, group2: the two levels being compared
p.adjust.method: the adjustment method used for multiple comparisons
p.value.adj: the adjusted p-value; returned by
pairwise_contingency_table(). Note that pairwise_comparisons() instead
folds the adjusted value into p.value (and does not return a separate
p.value.adj column)
Common columns
n.obs: sample size used for the analysis: observations for unpaired
tests, complete subjects/pairs for paired two-sample tests and ANOVAs,
or studies for meta-analysis
expression: a list-column of pre-formatted
plotmath expressions; each
element is a language object (not a character string) containing the
statistical details, ready to be used in {ggplot2} (e.g. in labs() or
annotate())
For a per-function, column-by-column breakdown of the output (and an explanation
of the internal add_expression_col() engine that builds the expression
column), see the Return value schema
article. For more examples, see the Data frame outputs article.
Below is a summary of:
the statistical test carried out for inferential statistics
the type of effect size estimate and a measure of uncertainty for this estimate
the functions used internally to compute these details
Hypothesis testing
| Type | No. of groups | Test | Function used |
| Parametric | 2 | Student's or Welch's t-test | stats::t.test() |
| Non-parametric | 2 | Mann-Whitney U test | stats::wilcox.test() |
| Robust | 2 | Yuen's test for trimmed means | WRS2::yuen() |
| Bayesian | 2 | Student's t-test | BayesFactor::ttestBF()
|
Effect size estimation
| Type | No. of groups | Effect size | CI available? | Function used |
| Parametric | 2 | Cohen's d, Hedges' g | Yes | effectsize::cohens_d(), effectsize::hedges_g() |
| Non-parametric | 2 | r (rank-biserial correlation) | Yes | effectsize::rank_biserial() |
| Robust | 2 | Algina-Keselman-Penfield robust standardized difference | Yes | WRS2::akp.effect() |
| Bayesian | 2 | difference | Yes | bayestestR::describe_posterior()
|
Paired data: See complete_subjects() for subject matching, duplicate
observations, and removal of incomplete subjects.
Hypothesis testing
| Type | No. of groups | Test | Function used |
| Parametric | 2 | Student's t-test | stats::t.test() |
| Non-parametric | 2 | Wilcoxon signed-rank test | stats::wilcox.test() |
| Robust | 2 | Yuen's test on trimmed means for dependent samples | WRS2::yuend() |
| Bayesian | 2 | Student's t-test | BayesFactor::ttestBF()
|
Effect size estimation
| Type | No. of groups | Effect size | CI available? | Function used |
| Parametric | 2 | Cohen's d, Hedges' g | Yes | effectsize::cohens_d(), effectsize::hedges_g() |
| Non-parametric | 2 | r (rank-biserial correlation) | Yes | effectsize::rank_biserial() |
| Robust | 2 | Algina-Keselman-Penfield robust standardized difference | Yes | WRS2::wmcpAKP() |
| Bayesian | 2 | difference | Yes | bayestestR::describe_posterior()
|
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# ----------------------- within-subjects ------------------------------------- # data df <- dplyr::filter(bugs_long, condition %in% c("LDLF", "LDHF")) # for reproducibility set.seed(123) # ----------------------- parametric --------------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "parametric" ) # ----------------------- non-parametric ----------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "nonparametric" ) # ----------------------- robust -------------------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "robust" ) # ----------------------- Bayesian --------------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "bayes" ) # ----------------------- between-subjects ------------------------------------- # for reproducibility set.seed(123) # ----------------------- parametric --------------------------------------- # unequal variance two_sample_test(ToothGrowth, supp, len, type = "parametric") # equal variance two_sample_test(ToothGrowth, supp, len, type = "parametric", var.equal = TRUE) # biased (Cohen's d) effect size two_sample_test(ToothGrowth, supp, len, type = "parametric", effsize.type = "d") # ----------------------- non-parametric ----------------------------------- two_sample_test(ToothGrowth, supp, len, type = "nonparametric") # ----------------------- robust -------------------------------------------- two_sample_test(ToothGrowth, supp, len, type = "robust") # ----------------------- Bayesian --------------------------------------- two_sample_test(ToothGrowth, supp, len, type = "bayes")# ----------------------- within-subjects ------------------------------------- # data df <- dplyr::filter(bugs_long, condition %in% c("LDLF", "LDHF")) # for reproducibility set.seed(123) # ----------------------- parametric --------------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "parametric" ) # ----------------------- non-parametric ----------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "nonparametric" ) # ----------------------- robust -------------------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "robust" ) # ----------------------- Bayesian --------------------------------------- two_sample_test( df, condition, desire, subject.id = subject, paired = TRUE, type = "bayes" ) # ----------------------- between-subjects ------------------------------------- # for reproducibility set.seed(123) # ----------------------- parametric --------------------------------------- # unequal variance two_sample_test(ToothGrowth, supp, len, type = "parametric") # equal variance two_sample_test(ToothGrowth, supp, len, type = "parametric", var.equal = TRUE) # biased (Cohen's d) effect size two_sample_test(ToothGrowth, supp, len, type = "parametric", effsize.type = "d") # ----------------------- non-parametric ----------------------------------- two_sample_test(ToothGrowth, supp, len, type = "nonparametric") # ----------------------- robust -------------------------------------------- two_sample_test(ToothGrowth, supp, len, type = "robust") # ----------------------- Bayesian --------------------------------------- two_sample_test(ToothGrowth, supp, len, type = "bayes")