0% found this document useful (0 votes)
5 views

Log-linear Model for Contingency Tables in R

The document discusses the use of log-linear models to analyze multi-way contingency tables, focusing on categorical variables and their interactions. It provides an example using the HairEyeColor dataset in R to demonstrate how to fit a log-linear model and interpret its results. The model assesses the relationships between variables without a specified response variable, aiding in the study of associations.

Uploaded by

Navon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Log-linear Model for Contingency Tables in R

The document discusses the use of log-linear models to analyze multi-way contingency tables, focusing on categorical variables and their interactions. It provides an example using the HairEyeColor dataset in R to demonstrate how to fit a log-linear model and interpret its results. The model assesses the relationships between variables without a specified response variable, aiding in the study of associations.

Uploaded by

Navon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Log-linear Model for Contingency Tables in R

A log-linear model is used to analyze multi-way contingency tables by modeling the


logarithm of expected cell counts as a function of categorical variables and their interactions.
This approach helps in understanding the relationships between categorical variables
without specifying a response variable, making it useful for studying associations.

Example in R

Here, we analyze a three-way contingency table of Hair Color, Eye Color, and Sex using the
built-in HairEyeColor dataset.

# Load dataset
data("HairEyeColor")

# Convert the data to a table format


hair_eye_sex <- as.table(HairEyeColor)

# Fit a log-linear model


log_model <- loglm(~ Hair + Eye + Sex + Hair:Eye + Hair:Sex + Eye:Sex, data =
hair_eye_sex)

# Display model summary


summary(log_model)

Explanation

loglm(~ Hair + Eye + Sex + Hair:Eye + Hair:Sex + Eye:Sex, data = hair_eye_sex):

Models the three-way interaction between Hair, Eye, and Sex.

Includes main effects (Hair, Eye, Sex) and two-way interactions (Hair:Eye, Hair:Sex,
Eye:Sex).

summary(log_model):

Displays the significance of interactions and goodness-of-fit measures.

This model helps assess the independence or dependence of categorical variables.

You might also like