1. Work Accident vs. Employee Status

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 status and work accidents.

non-technical interpretation: Employees that had a work accident are most likely to stay at the company.

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

plot_ly(prop_data) %>%
  add_bars(x = ~Work_accident, y = ~Left, name = "Left", 
           marker = list(color = "#9fcddd")) %>%
  add_bars(x = ~Work_accident, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#e9b4e3")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Work Accident"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees that had a work accident are most likely to stay at the company"
  )

2. Promotion in the Last 5 Years vs. Employee Status

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 status and promotions in the last 5 years.

non-technical interpretation: Employees that received a promotion in the last 5 years are most likely to stay at the company.

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

plot_ly(prop_data2) %>%
  add_bars(x = ~promotion_last_5years, y = ~Left, name = "Left", 
           marker = list(color = "#e99e64")) %>%
  add_bars(x = ~promotion_last_5years, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#84df8d")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Promotion in the Last 5 Years"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees that received a promotion in the last 
     5 years are most likely to stay at the company"
  )

3. Department vs. Employee Status

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 status and the department that they are in.

non-technical interpretation: Employees are most likely to stay in the company if they are in the management and RandD departments.

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

plot_ly(prop_data3) %>%
  add_bars(x = ~Department, y = ~Left, name = "Left", 
           marker = list(color = "#b0eada")) %>%
  add_bars(x = ~Department, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#c1b0ea")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees are most likely to stay in the company 
    if they are in the management and RandD departments"
  )

4. Salary vs. Employee Status

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 status and salary.

non-technical interpretation: Employees paid high salaries are most likely to stay at the company.

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

plot_ly(prop_data4) %>%
  add_bars(x = ~salary, y = ~Left, name = "Left", 
           marker = list(color = "#d28cca")) %>%
  add_bars(x = ~salary, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#c67569")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Salary"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees paid high salaries are most likely to stay at the company"
  )