Log-linear Models for Two-Way Tables in R
Log-linear Models for Two-Way Tables in R
A log-linear model for a two-way contingency table helps analyze the relationship between
two categorical variables. It models the logarithm of expected cell counts as a function of the
main effects and their interaction.
Example in R
We'll use the built-in Titanic dataset (converted to a two-way table) to examine the
relationship between Survival and Class.
Explanation
Extracts a two-way contingency table of Class and Survival from the Titanic dataset.
Fits a log-linear model with main effects (Class and Survived) and their interaction
(Class:Survived).
summary(log_model):
Interpretation
A log-linear model for a three-way contingency table analyzes the relationships among three
categorical variables. It helps determine whether interactions exist between them by
modeling the logarithm of expected cell counts.
Example in R
We'll use the Titanic dataset to study the relationships between Class, Survival, and Sex.
Explanation
Includes main effects (Class, Sex, Survived) and two-way interactions (Class:Sex,
Class:Survived, Sex:Survived).
summary(log_model):
If higher-order interactions (like Class:Sex:Survived) are added and significant, it means that
survival patterns depend on the combination of both Class and Sex.