Chi-Square Goodness-of-Fit Test: This test checks if the observed frequencies match the expected frequencies in a categorical variable. Use the chisq.test() function. For example, testing the distribution of eye colors in a population:
chisq_test_result <- chisq.test(observed_frequencies, p = expected_probabilities)
Chi-Square Test of Independence: This test examines the association between two categorical variables. It helps determine if there's a relationship between the two. Use the chisq.test() function. For example, testing the association between gender and preferred car color:
chi_square_test_result <- chisq.test(table(gender, car_color))