Antonio
Antonio

Reputation: 407

How do I perform Chi-Squared test on categorical variable?

This might be a question that could be answered relatively quickly if I knew more terminology.

Am I correctly performing a chi-squared test for independence on the JOB variable?

CD %>% select(JOB, DEFAULT) %>%
table() %>% chisq.test()
unique(CD$JOB)
[1] SkilledEmployee/Official                         
[2] Unemployed/Unskilled:Resident                    
[3] Mgr/SelfEmployed/HighlyQualified Employee/Officer
[4] Unemployed/Unskilled:NonResident   
              
4 Levels

Thank You.

Upvotes: 0

Views: 607

Answers (2)

Ruam Pimentel
Ruam Pimentel

Reputation: 1329

You can do exactly what you want in the way you thought by using chi_test() from rstatix package.

I strongly recommend checking out rstatix. This package makes baseR operation pipe-friendly. So if you like pipe, you will love it.

Solution

library(rstatix)

CD %>%
  select(JOB, DEFAULT) %>% 
  table() %>% 
  chisq_test()

Upvotes: 2

user12256545
user12256545

Reputation: 3002

You Almost got it right. Null hypothesis would be that the categics are independent. H1 would be they are not independent.

Run the test like this, there is no need for dplyr::select on the df CD.

chisq.test(table(CD$JOB,CD$DEFAULT))

Upvotes: 1

Related Questions