Learn/R Programming/Statistical Analysis

Chi-Square Test

Topic: Chi-Square

Advertisement

Introduction

The chi-square test determines if there is an association between categorical variables.

Test of Independence

# Create contingency table
table_data <- table(df$var1, df$var2)

# Chi-square test
chisq.test(table_data)

# With correction
chisq.test(table_data, correct = TRUE)

Goodness of Fit

# Observed counts
observed <- c(10, 20, 30)

# Expected proportions
expected <- c(0.25, 0.25, 0.5)

chisq.test(observed, p = expected)

Expected Frequencies

# Get expected values
result <- chisq.test(table_data)
result$expected

Effect Size

# Cramer's V
library(vcd)
assocstats(table_data)

Summary

Chi-square tests categorical associations. Check expected frequencies assumption.

Advertisement

Advertisement

Need More Practice?

Get personalized R programming help from ChatWhole's AI-powered platform.

Get Expert Help →