ggstatsplot (version 0.0.12)

bf_contingency_tab: Bayesian contingency table analysis.

Description

Bayesian contingency table analysis.

Usage

bf_contingency_tab(data, main, condition = NULL, counts = NULL,
  ratio = NULL, sampling.plan = "indepMulti", fixed.margin = "rows",
  prior.concentration = 1, caption = NULL, output = "null", k = 2,
  ...)

Arguments

data

A dataframe (or a tibble) from which variables specified are to be taken. A matrix or tables will not be accepted.

main

The variable to use as the rows in the contingency table.

condition

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.

counts

A string naming a variable in data containing counts, or NULL if each row represents a single observation (Default).

ratio

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.

sampling.plan

Character describing the sampling plan. Possible options are "indepMulti" (independent multinomial; default), "poisson", "jointMulti" (joint multinomial), "hypergeom" (hypergeometric). For more, see ?BayesFactor::contingencyTableBF().

fixed.margin

For the independent multinomial sampling plan, which margin is fixed ("rows" or "cols"). Defaults to "rows".

prior.concentration

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.

caption

Text to display as caption (will be displayed on top of the bayes factor caption/message).

output

Can either be "null" (or "caption" or "H0", which will contain text for evidence in favor of the null hypothesis or H0) or "alternative" (or "title" or "H1") or "results", which will return a dataframe with results all the details).

k

Number of digits after decimal point (should be an integer) (Default: k = 2).

...

further arguments to be passed to or from methods.

See Also

bf_corr_test, bf_oneway_anova, bf_ttest

Examples

Run this code
# NOT RUN {
# ------------------ association tests --------------------------------

# for reproducibility
set.seed(123)
library(ggstatsplot)

# to get caption (in favor of null)
bf_contingency_tab(
  data = mtcars,
  main = am,
  condition = cyl,
  fixed.margin = "cols"
)

# to get caption (in favor of alternative)
bf_contingency_tab(
  data = mtcars,
  main = am,
  condition = cyl,
  fixed.margin = "rows",
  output = "alternative"
)

# to see results
bf_contingency_tab(
  data = mtcars,
  main = am,
  condition = cyl,
  sampling.plan = "jointMulti",
  fixed.margin = "rows",
  prior.concentration = 1
)

# ------------------ goodness of fit tests --------------------------------

bf_contingency_tab(
  data = mtcars,
  main = am,
  prior.concentration = 10
)
# }

Run the code above in your browser using DataLab