Chi-Square 1: Left and Salary

chisq.test(hr$left, hr$salary)
## 
##  Pearson's Chi-squared test
## 
## data:  hr$left and hr$salary
## X-squared = 381.23, df = 2, p-value < 2.2e-16

p-value interpretation: The p-value is very small, therefore the probability of these results being random is very small

chi-square test interpretation: There is a dependence between employee attrition and salary

non-technical interpretation: Employees with low salaries are most likely to leave the company

prop_salary <- hr %>%
  group_by(salary) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left_company = sum(left == 1) / n()
  )

plot_ly(prop_salary) %>%
  add_bars(x = ~salary, y = ~stayed, name = "Stayed") %>%
  add_bars(x = ~salary, y = ~left_company, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees with low salaries are most likely to leave the company",
    xaxis = list(title = "Salary"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )

Chi-Square 2: Left and Work Accident

chisq.test(hr$left, hr$Work_accident)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  hr$left and hr$Work_accident
## X-squared = 357.56, df = 1, p-value < 2.2e-16

p-value interpretation: The p-value is very small, therefore the probability of these results being random is very small

chi-square test interpretation: There is a dependence between employee attrition and work accident status

non-technical interpretation: Employees without a work accident are most likely to leave the company

prop_accident <- hr %>%
  group_by(Work_accident) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left_company = sum(left == 1) / n()
  )

plot_ly(prop_accident) %>%
  add_bars(x = ~Work_accident, y = ~stayed, name = "Stayed") %>%
  add_bars(x = ~Work_accident, y = ~left_company, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees without a work accident are most likely to leave the company",
    xaxis = list(title = "Work Accident"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )

Chi-Square 3: Left and Promotion in the Last 5 Years

chisq.test(hr$left, hr$promotion_last_5years)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  hr$left and hr$promotion_last_5years
## X-squared = 56.262, df = 1, p-value = 6.344e-14

p-value interpretation: The p-value is very small, therefore the probability of these results being random is very small

chi-square test interpretation: There is a dependence between employee attrition and promotion history

non-technical interpretation: Employees who were not promoted in the last 5 years are most likely to leave the company

prop_promo <- hr %>%
  group_by(promotion_last_5years) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left_company = sum(left == 1) / n()
  )

plot_ly(prop_promo) %>%
  add_bars(x = ~promotion_last_5years, y = ~stayed, name = "Stayed") %>%
  add_bars(x = ~promotion_last_5years, y = ~left_company, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees who were not promoted in the last 5 years \n are most likely to leave the company",
    xaxis = list(title = "Promotion in Last 5 Years"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )

Chi-Square 4: Left and Department

chisq.test(hr$left, hr$Department)
## 
##  Pearson's Chi-squared test
## 
## data:  hr$left and hr$Department
## X-squared = 86.825, df = 9, p-value = 7.042e-15

p-value interpretation: The p-value is very small, therefore the probability of these results being random is very small

chi-square test interpretation: There is a dependence between employee attrition and department

non-technical interpretation: Employees in Research and Development and more likely to leave the company than others

prop_dept <- hr %>%
  group_by(Department) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left_company = sum(left == 1) / n()
  )

plot_ly(prop_dept) %>%
  add_bars(x = ~Department, y = ~stayed, name = "Stayed") %>%
  add_bars(x = ~Department, y = ~left_company, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees in some departments are more likely \n to leave the company than others",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )