View source: R/centrality-description.R
| centrality_description | R Documentation |
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,
...
)
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")
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
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
The exact dispersion column depends on the type of analysis (std.dev vs
mad; neither is returned for "bayes"), and datawizard::describe_distribution() is used internally to compute
these indices.
For more examples, see the data frame output vignette and the Return value schema article.
The table below provides summary about:
statistical test carried out for inferential statistics
type of effect size estimate and a measure of uncertainty for this estimate
functions used internally to compute these details
| 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.