Last chance! 50% off unlimited learning
Sale ends in
Bayes Factor for contingency table analysis
bf_contingency_tab(
data,
x,
y = NULL,
counts = NULL,
ratio = NULL,
sampling.plan = "indepMulti",
fixed.margin = "rows",
prior.concentration = 1,
top.text = NULL,
output = "dataframe",
k = 2L,
...
)
A dataframe (or a tibble) from which variables specified are to be taken. A matrix or tables will not be accepted.
The variable to use as the rows in the contingency table.
The variable to use as the columns in the contingency
table. Default is NULL
. If NULL
, one-sample proportion test (a goodness
of fit test) will be run for the main
variable. Otherwise an appropriate
association test will be run.
A string naming a variable in data containing counts, or NULL
if each row represents a single observation.
A vector of proportions: the expected proportions for the
proportion test (should sum to 1). Default is NULL
, which means the null
is equal theoretical proportions across the levels of the nominal variable.
This means if there are two levels this will be ratio = c(0.5,0.5)
or if
there are four levels this will be ratio = c(0.25,0.25,0.25,0.25)
, etc.
Character describing the sampling plan. Possible options
are "indepMulti"
(independent multinomial; default), "poisson"
,
"jointMulti"
(joint multinomial), "hypergeom"
(hypergeometric). For
more, see ?BayesFactor::contingencyTableBF()
.
For the independent multinomial sampling plan, which
margin is fixed ("rows"
or "cols"
). Defaults to "rows"
.
Specifies the prior concentration parameter, set
to 1
by default. It indexes the expected deviation from the null
hypothesis under the alternative, and corresponds to Gunel and Dickey's
(1974) "a"
parameter.
Text to display as top.text (will be displayed on top of the Bayes Factor top.text/message).
If "expression"
, will return expression with statistical
details, while "dataframe"
will return a dataframe containing the
results.
Number of digits after decimal point (should be an integer)
(Default: k = 2L
).
Arguments passed on to bf_extractor
conf.level
Confidence/Credible Interval (CI) level. Default to 0.95
(95%
).
centrality
The point-estimates (centrality indices) to compute.
Character (vector) or list with one or more of these options: "median"
,
"mean"
, "MAP"
or "all"
.
conf.method
The type of index used for Credible Interval. Can be
"hdi"
(default, see bayestestR::hdi()
), "eti"
(see
bayestestR::eti()
) or "si"
(see bayestestR::si()
).
# NOT RUN {
# for reproducibility
set.seed(123)
library(tidyBF)
# ------------------ association tests --------------------------------
# to get dataframe
bf_contingency_tab(
data = mtcars,
x = am,
y = cyl,
output = "dataframe"
)
# ------------------ goodness of fit tests --------------------------------
# to get expression
bf_contingency_tab(
data = mtcars,
x = am,
prior.concentration = 10,
output = "expression"
)
# }
Run the code above in your browser using DataLab