Measure the relationship between two categorical variables
Data:HR_comma_sep
Employee_left <- HR_comma_sep %>% 
  mutate (Left = ifelse ( left > 0, "left", "stay"),
          Work_accident = as.factor(Work_accident),
          promotion_last_5years = as.factor(promotion_last_5years)) %>% 
  select(-left)
Employee_left <- rename(Employee_left, Department = sales)

2 left vs Work_accident

CrossTable(Employee_left$Left , Employee_left$Work_accident , chisq = T)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  14999 
## 
##  
##                    | Employee_left$Work_accident 
## Employee_left$Left |         0 |         1 | Row Total | 
## -------------------|-----------|-----------|-----------|
##               left |      3402 |       169 |      3571 | 
##                    |    39.510 |   233.709 |           | 
##                    |     0.953 |     0.047 |     0.238 | 
##                    |     0.265 |     0.078 |           | 
##                    |     0.227 |     0.011 |           | 
## -------------------|-----------|-----------|-----------|
##               stay |      9428 |      2000 |     11428 | 
##                    |    12.346 |    73.029 |           | 
##                    |     0.825 |     0.175 |     0.762 | 
##                    |     0.735 |     0.922 |           | 
##                    |     0.629 |     0.133 |           | 
## -------------------|-----------|-----------|-----------|
##       Column Total |     12830 |      2169 |     14999 | 
##                    |     0.855 |     0.145 |           | 
## -------------------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  358.5938     d.f. =  1     p =  5.698673e-80 
## 
## Pearson's Chi-squared test with Yates' continuity correction 
## ------------------------------------------------------------
## Chi^2 =  357.5624     d.f. =  1     p =  9.55824e-80 
## 
## 

Explanation:

#1 There is a dependency between employee left and Work_accident at the alpha = 0.05 level
#2 Relative Risk: Employee who left the company had 1.16 (0.953/0.825) times possiblity to had work_accident compared to employee who stay in the company.
#3 work_accident increase the probability of employee to left company.

3Left vs promotion_last_5years

CrossTable(Employee_left$Left , Employee_left$promotion_last_5years , chisq = T)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  14999 
## 
##  
##                    | Employee_left$promotion_last_5years 
## Employee_left$Left |         0 |         1 | Row Total | 
## -------------------|-----------|-----------|-----------|
##               left |      3552 |        19 |      3571 | 
##                    |     0.928 |    42.702 |           | 
##                    |     0.995 |     0.005 |     0.238 | 
##                    |     0.242 |     0.060 |           | 
##                    |     0.237 |     0.001 |           | 
## -------------------|-----------|-----------|-----------|
##               stay |     11128 |       300 |     11428 | 
##                    |     0.290 |    13.343 |           | 
##                    |     0.974 |     0.026 |     0.762 | 
##                    |     0.758 |     0.940 |           | 
##                    |     0.742 |     0.020 |           | 
## -------------------|-----------|-----------|-----------|
##       Column Total |     14680 |       319 |     14999 | 
##                    |     0.979 |     0.021 |           | 
## -------------------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  57.26273     d.f. =  1     p =  3.813123e-14 
## 
## Pearson's Chi-squared test with Yates' continuity correction 
## ------------------------------------------------------------
## Chi^2 =  56.26163     d.f. =  1     p =  6.344155e-14 
## 
## 

Explanation:

#1 There is a dependency between emloyee left and promotion_last_5years, at the alpha = 0.05 level
#2  Relative Risk: Employee who left the company and had 0.19 (0.005/0.026) times employee to had promotiona_last_5years compared to employee who stay in the company.
#3  Promotion_last_5_years decrease the probability of employee to left company.

4left VS Department

CrossTable(Employee_left$Department , Employee_left$Left, chisq = T)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  14999 
## 
##  
##                          | Employee_left$Left 
## Employee_left$Department |      left |      stay | Row Total | 
## -------------------------|-----------|-----------|-----------|
##               accounting |       204 |       563 |       767 | 
##                          |     2.506 |     0.783 |           | 
##                          |     0.266 |     0.734 |     0.051 | 
##                          |     0.057 |     0.049 |           | 
##                          |     0.014 |     0.038 |           | 
## -------------------------|-----------|-----------|-----------|
##                       hr |       215 |       524 |       739 | 
##                          |     8.670 |     2.709 |           | 
##                          |     0.291 |     0.709 |     0.049 | 
##                          |     0.060 |     0.046 |           | 
##                          |     0.014 |     0.035 |           | 
## -------------------------|-----------|-----------|-----------|
##                       IT |       273 |       954 |      1227 | 
##                          |     1.252 |     0.391 |           | 
##                          |     0.222 |     0.778 |     0.082 | 
##                          |     0.076 |     0.083 |           | 
##                          |     0.018 |     0.064 |           | 
## -------------------------|-----------|-----------|-----------|
##               management |        91 |       539 |       630 | 
##                          |    23.202 |     7.250 |           | 
##                          |     0.144 |     0.856 |     0.042 | 
##                          |     0.025 |     0.047 |           | 
##                          |     0.006 |     0.036 |           | 
## -------------------------|-----------|-----------|-----------|
##                marketing |       203 |       655 |       858 | 
##                          |     0.008 |     0.002 |           | 
##                          |     0.237 |     0.763 |     0.057 | 
##                          |     0.057 |     0.057 |           | 
##                          |     0.014 |     0.044 |           | 
## -------------------------|-----------|-----------|-----------|
##              product_mng |       198 |       704 |       902 | 
##                          |     1.307 |     0.408 |           | 
##                          |     0.220 |     0.780 |     0.060 | 
##                          |     0.055 |     0.062 |           | 
##                          |     0.013 |     0.047 |           | 
## -------------------------|-----------|-----------|-----------|
##                    RandD |       121 |       666 |       787 | 
##                          |    23.510 |     7.346 |           | 
##                          |     0.154 |     0.846 |     0.052 | 
##                          |     0.034 |     0.058 |           | 
##                          |     0.008 |     0.044 |           | 
## -------------------------|-----------|-----------|-----------|
##                    sales |      1014 |      3126 |      4140 | 
##                          |     0.815 |     0.255 |           | 
##                          |     0.245 |     0.755 |     0.276 | 
##                          |     0.284 |     0.274 |           | 
##                          |     0.068 |     0.208 |           | 
## -------------------------|-----------|-----------|-----------|
##                  support |       555 |      1674 |      2229 | 
##                          |     1.114 |     0.348 |           | 
##                          |     0.249 |     0.751 |     0.149 | 
##                          |     0.155 |     0.146 |           | 
##                          |     0.037 |     0.112 |           | 
## -------------------------|-----------|-----------|-----------|
##                technical |       697 |      2023 |      2720 | 
##                          |     3.771 |     1.178 |           | 
##                          |     0.256 |     0.744 |     0.181 | 
##                          |     0.195 |     0.177 |           | 
##                          |     0.046 |     0.135 |           | 
## -------------------------|-----------|-----------|-----------|
##             Column Total |      3571 |     11428 |     14999 | 
##                          |     0.238 |     0.762 |           | 
## -------------------------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  86.82547     d.f. =  9     p =  7.04213e-15 
## 
## 
## 

Explanation:

#1  There is no dependency between employee left and different department, at the alpha = 0.05 level.
#2  As we can see from the table, employee stay in the company have probably 3 times high than employee left the company no matter in which department.