library(readr)
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.
#1 #1 Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.
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
#2 Interpret the results in technical terms (.5 point) For each chi-square test, explain what the test’s p-value means (significance). #The p-value is very small, therefore the probability of the results being random is very small. It also means that there is a dependency between the work accident and leaving the company.
#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 that did not have a work accident are more then three times more likely to leave 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.
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
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
prop_data <- hr %>%
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 Accident"),
yaxis = list(title = "Proportion", tickformat = ",.0%"),
title = "Employees that did not have a work accident are more than 3 times more likely to leave"
)
#2 #1 Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.
chisq.test(hr$left , hr$satisfaction_level)
##
## Pearson's Chi-squared test
##
## data: hr$left and hr$satisfaction_level
## X-squared = 7937.7, df = 91, p-value < 2.2e-16
#2 Interpret the results in technical terms (.5 point) For each chi-square test, explain what the test’s p-value means (significance). #The p-value is very small, therefore the probability of the results being random is very small. It also means that there is a dependency between the satisfaction level and leaving the company.
#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 that have a high satisfaction level are less likely to leave 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.
library(plotly)
library(dplyr)
prop_data2 <- hr %>%
group_by(satisfaction_level) %>%
summarise(
Stayed = sum(left == 0) / n(),
Left = sum(left == 1) / n()
)
plot_ly(prop_data2) %>%
add_bars(x = ~satisfaction_level, y = ~Stayed, name = "Stayed",
marker = list(color = "#1f77b4")) %>%
add_bars(x = ~satisfaction_level, y = ~Left, name = "Left",
marker = list(color = "#ff7f0e")) %>%
layout(
barmode = "stack",
xaxis = list(title = "Satisfaction Level"),
yaxis = list(title = "Proportion", tickformat = ",.0%"),
title = "Employees with a higher satisfaction level were significantly more likely to stay"
)
#3 #1 Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.
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
#2 Interpret the results in technical terms (.5 point) For each chi-square test, explain what the test’s p-value means (significance). #The p-value is very small, therefore the probability of the results being random is very small. It also means that there is a dependency between salary and leaving the company.
#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 that have a lower salary are more likely to leave 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.
library(plotly)
library(dplyr)
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 = "#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 a higher salary were significantly more likely to stay"
)
#4 #1 Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.
chisq.test(hr$left , hr$last_evaluation)
##
## Pearson's Chi-squared test
##
## data: hr$left and hr$last_evaluation
## X-squared = 2534.8, df = 64, p-value < 2.2e-16
#2 Interpret the results in technical terms (.5 point) For each chi-square test, explain what the test’s p-value means (significance). #The p-value is very small, therefore the probability of the results being random is very small. It also means that there is a dependency between last evaluation and leaving the company.
#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 that had a lower evaluation are more likely to leave 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.
library(plotly)
library(dplyr)
prop_data4 <- hr %>%
group_by(last_evaluation) %>%
summarise(
Stayed = sum(left == 0) / n(),
Left = sum(left == 1) / n()
)
plot_ly(prop_data4) %>%
add_bars(x = ~last_evaluation, y = ~Stayed, name = "Stayed",
marker = list(color = "#1f77b4")) %>%
add_bars(x = ~last_evaluation, y = ~Left, name = "Left",
marker = list(color = "#ff7f0e")) %>%
layout(
barmode = "stack",
xaxis = list(title = "Last Evaluation"),
yaxis = list(title = "Proportion", tickformat = ",.0%"),
title = "Employees with a higher last evaluation were significantly more likely to stay"
)