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.
options(repos = c(CRAN = "https://cran.rstudio.com/"))
install.packages("plotly")
## 
## The downloaded binary packages are in
##  /var/folders/q1/gl10h4f94b3dsmnpk2jdysgr0000gn/T//Rtmp3vbT8m/downloaded_packages
install.packages("dplyr")
## 
## The downloaded binary packages are in
##  /var/folders/q1/gl10h4f94b3dsmnpk2jdysgr0000gn/T//Rtmp3vbT8m/downloaded_packages
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

Number 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.

department_test <- table(hr$Department, hr$left)
print(department_test)
##              
##                  0    1
##   accounting   563  204
##   hr           524  215
##   IT           954  273
##   management   539   91
##   marketing    655  203
##   product_mng  704  198
##   RandD        666  121
##   sales       3126 1014
##   support     1674  555
##   technical   2023  697
chi_department <- chisq.test(department_test)
print(chi_department)
## 
##  Pearson's Chi-squared test
## 
## data:  department_test
## X-squared = 86.825, df = 9, p-value = 7.042e-15

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 extremely small, meaning that the probability of these results being random is very small. There is a dependence between department and left the company.

Interpret the results in non-technical terms (1 point) For each chi-square test, what do the results mean in non-techical terms.

  • Some departments have a higher turnover rate compared to others most likely due to things like satisfaction level, salary, or workload.

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.

ggplot(hr, aes(x = Department, fill = factor(left))) +
  geom_bar(position = "dodge") +
  labs(
    title = "Employee Turnover by Department",
    x = "Department",
    y = "Count of Employees",
    fill = "Left the Job"
  ) +
  theme_minimal() 

Number 2

Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.

 salary_test <- table(hr$salary, hr$left)
  print(salary_test)
##         
##             0    1
##   high   1155   82
##   low    5144 2172
##   medium 5129 1317
  chi_salary <- chisq.test(salary_test)
  print(chi_salary)
## 
##  Pearson's Chi-squared test
## 
## data:  salary_test
## X-squared = 381.23, df = 2, p-value < 2.2e-16

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 extremely small, meaning that the probability of these results being random is very small. There is a dependence between salary and left the company.

Interpret the results in non-technical terms (1 point) For each chi-square test, what do the results mean in non-techical terms.

  • Those employees who had a high salary are mostly likely to have a lower employee turnover while those with a low salary most likely will have a higher turnover.

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.

ggplot(hr, aes(x = salary, fill = factor(left))) +
  geom_bar(position = "dodge") +
  labs(
    title = "Employee Turnover by Salary",
    x = "Salary",
    y = "Count of Employees",
    fill = "Left the Job"
  ) +
  theme_minimal() 

Number 3

Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.

accident_test <- table(hr$Work_accident, hr$left)
  print(accident_test)
##    
##        0    1
##   0 9428 3402
##   1 2000  169
  chi_accident <- chisq.test(accident_test)
  print(chi_accident)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  accident_test
## X-squared = 357.56, df = 1, p-value < 2.2e-16

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 extremely small, meaning that the probability of these results being random is very small. There is a dependence between having a work accident and leaving the company.

Interpret the results in non-technical terms (1 point) For each chi-square test, what do the results mean in non-techical terms.

  • Those employees who had work accidents were more likely to not leave the company probably due to things like receiving worker compensation or fear of not finding another job at a different company following the accident.

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.

ggplot(hr, aes(x = Work_accident, fill = factor(left))) +
    geom_bar(position = "dodge") +
  labs(
    title = "Employee Turnover by Work Accident",
    x = "Work Accident",
    y = "Count of Employees",
    fill = "Left the Job"
  ) +
    theme_minimal() 

Number 4

Perform the chi-square test (.5 point) Choose any two appropriate variables from the data and perform the chi-square test, displaying the results.

 promotion_test <- table(hr$promotion_last_5years, hr$left)
  print(promotion_test)
##    
##         0     1
##   0 11128  3552
##   1   300    19
  chi_promotion <- chisq.test(promotion_test)
  print(chi_promotion)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  promotion_test
## X-squared = 56.262, df = 1, p-value = 6.344e-14

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 extremely small, meaning that the probability of these results being random is very small. There is a dependence between getting a promotion and staying at the company.

Interpret the results in non-technical terms (1 point) For each chi-square test, what do the results mean in non-techical terms.

  • Those employees who got a promotion are more likely to stay at the company.

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.

ggplot(hr, aes(x = promotion_last_5years, fill = factor(left))) +
    geom_bar(position = "dodge") +
  labs(
    title = "Employee Turnover by Promotion in the Last 5 Years",
    x = "Promotion",
    y = "Count of Employees",
    fill = "Left the Job"
  ) +
    theme_minimal()