1.
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, therefore the
probability of these results being random is very small.
chi-square test interpretation: There is a dependency between the
promotion in the last 5 years and leaving.
non-technical interpretation: Employees that did not get a promotion
within the last 5 years are more likely to leave.
Calculate proportions
prop_data <- hr %>%
mutate(promotion_last_5years = as.factor(promotion_last_5years))%>%
group_by(promotion_last_5years) %>%
summarise(
Stayed = sum(left == 0) / n(),
Left = sum(left == 1) / n()
)
Create stacked bar chart
plot_ly(prop_data) %>%
add_bars(x = ~promotion_last_5years, y = ~Stayed, name = "Stayed",
marker = list(color = "#1f77b4")) %>%
add_bars(x = ~promotion_last_5years, y = ~Left, name = "Left",
marker = list(color = "#ff7f0e")) %>%
layout(
barmode = "stack",
xaxis = list(title = "Promotion in the Last 5 Years"),
yaxis = list(title = "Proportion", tickformat = ",.0%"),
title = "Employees that did not get a promotion \n are more likely to leave"
)
2.
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, therefore the
probability of these results being random is very small.
chi-square test interpretation: There is a dependency between having
a work accident and leaving.
non-technical interpretation: Employees that had a work accident are
more likely to stay.
Calculate proportions
prop_data2 <- hr %>%
mutate(Work_accident = as.factor(Work_accident))%>%
group_by(Work_accident) %>%
summarise(
Stayed = sum(left == 0) / n(),
Left = sum(left == 1) / n()
)
Create stacked bar chart
plot_ly(prop_data2) %>%
add_bars(x = ~Work_accident, y = ~Stayed, name = "Stayed",
marker = list(color = "#1f77b4")) %>%
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 had a work \n accident are more likely to stay"
)
3.
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, therefore the
probability of these results being random is very small.
chi-square test interpretation: There is a dependency between salary
level and leaving.
non-technical interpretation: Employees with the highest salary
level are the most likely to stay, while low salary are the most likely
to leave.
Calculate proportions
prop_data3 <- hr %>%
group_by(salary) %>%
summarise(
Stayed = sum(left == 0) / n(),
Left = sum(left == 1) / n()
)
Create stacked bar chart
plot_ly(prop_data3) %>%
add_bars(x = ~salary, y = ~Stayed, name = "Stayed",
marker = list(color = "#1f77b4")) %>%
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 the highest salary level\nare the most likely to stay, while low \n salary are the most likely to leave"
)
4.
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.042e-15). The
probability that these results could be random is very small.
chi-square test interpretation: There is a dependency between
department and leaving.
non-technical interpretation: Employees that work within management
and R&D are the most likely to stay.
Calculate proportions
prop_data4 <- hr %>%
mutate(Department = as.factor(Department))%>%
group_by(Department) %>%
summarise(
Stayed = sum(left == 0) / n(),
Left = sum(left == 1) / n()
)
Create stacked bar chart
plot_ly(prop_data4) %>%
add_bars(x = ~Department, y = ~Stayed, name = "Stayed",
marker = list(color = "#1f77b4")) %>%
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 = "Employees that work within management and \n R&D are the most likely to stay"
)