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.
Test 1
tab1 <- table(hr$salary, hr$left)
chisq.test(tab1)
##
## Pearson's Chi-squared test
##
## data: tab1
## X-squared = 381.23, df = 2, p-value < 2.2e-16
prop1 <- hr %>%
group_by(salary) %>%
summarise(
stayed = sum(left == 0) / n(),
left = sum(left == 1) / n()
)
plot_ly(prop1) %>%
add_bars(x = ~salary, y = ~stayed, name = "Stayed") %>%
add_bars(x = ~salary, y = ~left, name = "Left") %>%
layout(
barmode = "stack",
xaxis = list(title = "Salary Level"),
yaxis = list(title = "Proportion"),
title = "Lower-paid employees are more likely to leave the company"
)