1. Salary vs Employee Attrition

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

p-value interpretation:
The p-value is very small (1.65e-83), so the probability these results are random is very low.

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

non-technical interpretation:
Employees with lower salaries are more likely to leave.

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

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

2. Department vs Employee Attrition

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

p-value interpretation:
The p-value is very small (7.04e-15), so the probability these results are random is very low.

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

non-technical interpretation:
Employees in some departments leave more than others.

prop_department <- hr %>%
  group_by(Department) %>%
  summarise(
    Stayed = sum(left == 0) / n(),
    Left = sum(left == 1) / n()
  )

plot_ly(prop_department) %>%
  add_bars(x = ~Department, y = ~Stayed, name = "Stayed") %>%
  add_bars(x = ~Department, y = ~Left, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees in some departments leave more than others",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )

3. Promotion in Last 5 Years vs Employee Attrition

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

p-value interpretation:
The p-value is very small (6.34e-14), so the probability these results are random is very low.

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

non-technical interpretation:
Employees who were not promoted are more likely to leave.

prop_promotion <- hr %>%
  group_by(promotion_last_5years) %>%
  summarise(
    Stayed = sum(left == 0) / n(),
    Left = sum(left == 1) / n()
  )

plot_ly(prop_promotion) %>%
  add_bars(x = ~promotion_last_5years, y = ~Stayed, name = "Stayed") %>%
  add_bars(x = ~promotion_last_5years, y = ~Left, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees who were not promoted are more likely to leave",
    xaxis = list(title = "Promotion in Last 5 Years (0 = No, 1 = Yes)"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )

4. Work Accident vs Employee Attrition

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

p-value interpretation:
The p-value is very small (9.56e-80), so the probability these results are random is very low.

chi-square test interpretation:
There is a dependence between work accidents and employee attrition.

non-technical interpretation:
Employees with work accidents are less likely to leave.

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

plot_ly(prop_accident) %>%
  add_bars(x = ~Work_accident, y = ~Stayed, name = "Stayed") %>%
  add_bars(x = ~Work_accident, y = ~Left, name = "Left") %>%
  layout(
    barmode = "stack",
    title = "Employees with work accidents are less likely to leave",
    xaxis = list(title = "Work Accident (0 = No, 1 = Yes)"),
    yaxis = list(title = "Proportion", tickformat = ",.0%")
  )