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