rtmb_table: RTMB-based Contingency Table Analysis (Chi-squared Test)

View source: R/wrapper_table.R

rtmb_tableR Documentation

RTMB-based Contingency Table Analysis (Chi-squared Test)

Description

'rtmb_table' performs a chi-squared test of independence between two categorical variables. It provides both classic (frequentist) Pearson chi-squared tests and Bayesian multinomial-style models.

Usage

rtmb_table(
  x,
  y = NULL,
  data = NULL,
  correct = TRUE,
  prior = prior_flat(),
  fixed = NULL,
  WAIC = FALSE,
  ...
)

Arguments

x

Variable name, formula, table, or matrix.

y

Variable name (optional if x is a formula).

data

A data frame.

correct

Logical; if TRUE, apply Yates' continuity correction for 2x2 classic analyses.

prior

Prior specification (Bayesian mode). Use 'prior_flat()' for a uniform Dirichlet prior or 'prior_normal(dirichlet_alpha = ...)' to set the Dirichlet concentration. Default is 'prior_flat()'.

fixed

Optional named list of fixed values for specific parameters.

WAIC

Logical; if TRUE, add pointwise 'log_lik' to the generate block for WAIC.

...

Reserved; unused arguments are rejected.

Value

An 'RTMB_Model' object.

Examples


# Classic chi-squared test
data(debate, package = "BayesRTMB")
rtmb_table(skill, cond, data = debate)$classic()
rtmb_table(table(debate$skill, debate$cond))$classic()


BayesRTMB documentation built on Nov. 24, 2026, 9:06 a.m.