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
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")
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
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%)")
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
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")
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
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")