Andrew DeLaricheliere
DATA3210
Assignment 9
Load libraries:
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.
Chi-Squared Test:
chisq.test(table(hr$left, hr$salary))
##
## Pearson's Chi-squared test
##
## data: table(hr$left, hr$salary)
## X-squared = 381.23, df = 2, p-value < 2.2e-16
Graph:
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(salary) %>%
summarise(
stayed = sum(left == 0) / n(),
left = sum(left == 1) / n()
) %>%
mutate(salary = factor(salary, levels = c("low", "medium", "high")))
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 Level"),
yaxis = list(title = "Proportion"),
title = "Employees with lower salaries are more likely to leave"
)
Interpretations:
# P-Value Interpretation: The p-value is extremely small, making it very unlikely that the results are due to chance.
# Technical interpretation: There is a dependency between left and salary.
# Non-Technical Interpretation: Employees with lower salaries are more likely to leave.