1. Left vs Work Accident

Perform the chi-square test (.5 point)

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
Interpret the results in technical terms (.5 point)
  • p-value interpretation: The p-value is very small, meaning there is a very small chance these results are random
  • Therefore we will be rejecting the Null Hypothesis that states there is no dependency
Interpret the results in non-technical terms (1 point)
  • chi-square test interpretation: There is a dependence between left and work accident
  • non-technical interpretation: Employees that did not have a work accident are more than 3 times likely to leave
Create a plot that helps visualize the chi-square test (.5 point)
prop_data1 <- hr %>%
  mutate(Work_accident = ifelse(Work_accident == 1, 'Yes', 'No'))%>%
  group_by(Work_accident) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left = sum(left == 1) / n()
  )

plot_ly(prop_data1) %>%
  add_bars(x = ~Work_accident, y = ~stayed, name = "Stayed", 
           marker = list(color = "#007396")) %>%
  add_bars(x = ~Work_accident, y = ~left, name = "Left", 
           marker = list(color = "#ff7f0e")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Work Accident"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees that did not have a work accident 
    are more than 3 times likely to leave")

2. Left vs Department

Perform the chi-square test (.5 point)

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
Interpret the results in technical terms (.5 point)
  • p-value interpretation: The p-value is very small, meaning there is a very small chance these results are random
  • Therefore we will be rejecting the Null Hypothesis that states there is no dependency
Interpret the results in non-technical terms (1 point)
  • chi-square test interpretation: There is a dependence between left and Department
  • non-technical interpretation: The number of Employees who leave varies across different departments
Create a plot that helps visualize the chi-square test (.5 point)
prop_data2 <- hr %>%
  group_by(Department) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left = sum(left == 1) / n()
  )

plot_ly(prop_data2) %>%
  add_bars(x = ~Department, y = ~stayed, name = "Stayed", 
           marker = list(color = "#007396")) %>%
  add_bars(x = ~Department, y = ~left, name = "Left", 
           marker = list(color = "#ff7f0e")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "The number of Employees who leave varies between
    several departments (high of 29% | low of 14%)")

3. Left vs Salary

Perform the chi-square test (.5 point)

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
Interpret the results in technical terms (.5 point)
  • p-value interpretation: The p-value is very small, meaning there is a very small chance these results are random
  • Therefore we will be rejecting the Null Hypothesis that states there is no dependency
Interpret the results in non-technical terms (1 point)
  • chi-square test interpretation: There is a dependence between left and salary
  • non-technical interpretation: Employees with high salary are the least likely to leave
Create a plot that helps visualize the chi-square test (.5 point)
prop_data3 <- hr %>%
  group_by(salary) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left = sum(left == 1) / n()
  )

plot_ly(prop_data3) %>%
  add_bars(x = ~salary, y = ~stayed, name = "Stayed", 
           marker = list(color = "#007396")) %>%
  add_bars(x = ~salary, y = ~left, name = "Left", 
           marker = list(color = "#ff7f0e")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Salary"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees with high salary are the least likely to leave")

4. Left vs Promotion Last 5 Years

Perform the chi-square test (.5 point)

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
Interpret the results in technical terms (.5 point)
  • p-value interpretation: The p-value is very small, meaning there is a very small chance these results are random
  • Therefore we will be rejecting the Null Hypothesis that states there is no dependency
Interpret the results in non-technical terms (1 point)
  • chi-square test interpretation: There is a dependence between left and promotion last 5 years
  • non-technical interpretation: Employees that haven’t recieved a promotion are 4 times more likely to leave
Create a plot that helps visualize the chi-square test (.5 point)
prop_data4 <- hr %>%
  mutate(promotion_last_5years = ifelse(promotion_last_5years == 1, 'Yes', 'No'))%>%
  group_by(promotion_last_5years) %>%
  summarise(
    stayed = sum(left == 0) / n(),
    left = sum(left == 1) / n()
  )

plot_ly(prop_data4) %>%
  add_bars(x = ~promotion_last_5years, y = ~stayed, name = "Stayed", 
           marker = list(color = "#007396")) %>%
  add_bars(x = ~promotion_last_5years, y = ~left, name = "Left", 
           marker = list(color = "#ED7D31")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Promotion Last 5 Years"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees that haven't recieved a promotion 
    are 4 times more likely to leave")