View source: R/wrapper_loglinear.R
| rtmb_loglinear | R Documentation |
Performs Bayesian or Frequentist log-linear analysis (Poisson regression) on a contingency table or raw data.
rtmb_loglinear(
formula,
data,
prior = prior_flat(),
y_range = NULL,
fixed = NULL,
WAIC = FALSE,
...
)
formula |
A formula (e.g., '~ A + B + A:B') or a contingency table. |
data |
A data frame (required if 'formula' is used). |
prior |
An object of class "rtmb_prior" specifying the prior distribution. |
y_range |
Optional theoretical minimum and maximum values of the count response. If supplied with the default flat prior, 'prior_weak()' is used. |
fixed |
Optional named list of fixed values for specific parameters. |
WAIC |
Logical; if TRUE, add pointwise 'log_lik' to the generate block for WAIC. |
... |
Additional arguments passed to 'rtmb_glm()'. |
An 'RTMB_Model' object.
# Create a contingency table
tab <- matrix(c(10, 20, 30, 40), nrow = 2)
dimnames(tab) <- list(A = c("A1", "A2"), B = c("B1", "B2"))
# Fit a log-linear model (independence model: ~ A + B)
fit_log <- rtmb_loglinear(~ A + B, data = tab)
# MAP estimation
map_log <- fit_log$optimize()
map_log$summary()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.