library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
hr <- read_csv('https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv')
## Rows: 14999 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Department, salary
## dbl (8): satisfaction_level, last_evaluation, number_project, average_montly...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
2. Interpret the results in technical terms (.5 point) For each
chi-square test, explain what the test’s p-value means
(significance).
Employees were almost 20% more likely to stay at the company if they
didnt experience a work accident.
3. Interpret the results in non-technical terms (1 point) For each
chi-square test, what do the results mean in non-techical terms.
Employees are more likely to stay if there was a work accident.
4. Create a plot that helps visualize the chi-square test (.5 point)
For each chi-square test, create a graph to help visualize the
difference between means, if any. The title must be the non-technical
interpretation.
prop_data <- hr %>%
mutate(Work_accident = as.factor(Work_accident)) %>%
group_by(Work_accident) %>%
summarise(
stayed = sum(left == 0) / n(),
left = sum(left == 1) / n()
)
plot_ly(prop_data) %>%
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 Accidents"),
yaxis = list(title = "Perecentage of Employees Retained or Left", tickformat = ",.0%"),
title = "Employees are more likely to stay if there was a work accident"
)
2. Interpret the results in technical terms (.5 point) For each
chi-square test, explain what the test’s p-value means
(significance).
Employees were almost 20% more likely to stay at the company if they
have received a promotion in the last 5 years.
3. Interpret the results in non-technical terms (1 point) For each
chi-square test, what do the results mean in non-techical terms.
Employees are more likely to stay if they receive a promotion in the
last 5 years.
4. Create a plot that helps visualize the chi-square test (.5 point)
For each chi-square test, create a graph to help visualize the
difference between means, if any. The title must be the non-technical
interpretation.
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()
)
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 = "Promotions in the Last 5 Years"),
yaxis = list(title = "Perecentage of Employees that Stayed at the Company", tickformat = ",.0%"),
title = "Employees are more likely to stay if they receive a promotion in the last 5 years"
)
2. Interpret the results in technical terms (.5 point) For each
chi-square test, explain what the test’s p-value means
(significance).
On average 75% of employees stay with the company (Most employees
leave from the hr and marketing department).
3. Interpret the results in non-technical terms (1 point) For each
chi-square test, what do the results mean in non-techical terms.
Employees are more likely to stay if they work in the management or
RandD department.
4. Create a plot that helps visualize the chi-square test (.5 point)
For each chi-square test, create a graph to help visualize the
difference between means, if any. The title must be the non-technical
interpretation.
prop_data <- hr %>%
mutate(Department = as.factor(Department)) %>%
group_by(Department) %>%
summarise(
stayed = sum(left == 0) / n(),
left = sum(left == 1) / n()
)
plot_ly(prop_data) %>%
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 = "Perecentage of Employees Who Stayed at the Company", tickformat = ",.0%"),
title = "Employees are more likely to stay if they work in the management or RandD department"
)
2. Interpret the results in technical terms (.5 point) For each
chi-square test, explain what the test’s p-value means
(significance).
Employees who are payed with a high salary are 20% more likely to
stay with the company than those with a low salary.
3. Interpret the results in non-technical terms (1 point) For each
chi-square test, what do the results mean in non-techical terms.
The higher the salary the more likely an employee is to stay at the
company.
4. Create a plot that helps visualize the chi-square test (.5 point)
For each chi-square test, create a graph to help visualize the
difference between means, if any. The title must be the non-technical
interpretation.
prop_data <- hr %>%
mutate(salary = factor(salary, levels = c("low", "medium", "high"))) %>%
group_by(salary) %>%
summarise(
stayed = sum(left == 0) / n(),
left = sum(left == 1) / n()
)
plot_ly(prop_data) %>%
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 = "Perecentage of Employees who Stayed or Left", tickformat = ",.0%"),
title = "The higher the salary the more likely an employee is to stay at the company"
)