contingency_table {statsExpressions} | R Documentation |
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, k = 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. |
counts |
The variable in data containing counts, or |
ratio |
A vector of proportions: the expected proportions for the
proportion test (should sum to 1). Default is |
k |
Number of digits after decimal point (should be an integer)
(Default: |
conf.level |
Scalar between |
sampling.plan |
Character describing the sampling plan. Possible options
are |
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 tibble data frame can contain some or all of the following columns (the exact columns will depend on the statistical test):
statistic
: the numeric value of a statistic
df
: the numeric value of a parameter being modeled (often degrees
of freedom for the test)
df.error
and df
: relevant only if the statistic in question has
two degrees of freedom (e.g. anova)
p.value
: the two-sided p-value associated with the observed statistic
method
: the name of the inferential statistical test
estimate
: estimated value of the effect size
conf.low
: lower bound for the effect size estimate
conf.high
: upper bound for the effect size estimate
conf.level
: width of the confidence interval
conf.method
: method used to compute confidence interval
conf.distribution
: statistical distribution for the effect
effectsize
: the name of the effect size
n.obs
: number of observations
expression
: pre-formatted expression containing statistical details
For examples, see data frame output vignette.
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
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 |
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 |
# for reproducibility set.seed(123) library(statsExpressions) # ------------------------ Frequentist ----------------------------- # association test contingency_table( data = mtcars, x = am, y = vs, paired = FALSE ) # goodness-of-fit test contingency_table( data = as.data.frame(HairEyeColor), x = Eye, counts = Freq, ratio = c(0.2, 0.2, 0.3, 0.3) ) # ------------------------ Bayesian ----------------------------- # association test contingency_table( data = mtcars, x = am, y = vs, paired = FALSE, type = "bayes" ) # goodness-of-fit test contingency_table( data = as.data.frame(HairEyeColor), x = Eye, counts = Freq, ratio = c(0.2, 0.2, 0.3, 0.3), type = "bayes" )