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.
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
options(scipen=999)
t.test(hr$last_evaluation ~ hr$left)
##
## Welch Two Sample t-test
##
## data: hr$last_evaluation by hr$left
## t = -0.72534, df = 5154.9, p-value = 0.4683
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
## -0.009772224 0.004493874
## sample estimates:
## mean in group 0 mean in group 1
## 0.7154734 0.7181126
The p-value is 0.4683, which is a lot higher than the significance threshold I keep of 0.05; this suggests that there is a no statistically significant difference between the means of either group.
The difference between the means is .718-.715, which is
not very significant.
Evaluation ratings aren’t significantly different between active and non-active employees.
plot_ly(hr,
x = ~factor(left, levels = c(0, 1), labels = c('Stayed', 'Left')),
y = ~last_evaluation,
type = 'box') %>%
layout(
title = 'Evaluation ratings are not significantly different between active and non-active employees.',
xaxis = list(title = 'Left Status'),
yaxis = list(title = 'Last Evaluation')
)
t.test(hr$average_montly_hours ~ hr$left)
##
## Welch Two Sample t-test
##
## data: hr$average_montly_hours by hr$left
## t = -7.5323, df = 4875.1, p-value = 0.00000000000005907
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
## -10.534631 -6.183384
## sample estimates:
## mean in group 0 mean in group 1
## 199.0602 207.4192
The p-value is extremely small, which means the differenct betweens means of average monthly hours and left status is significant.
The difference between the means is 199.0602-207.4192,
which is a difference of around 8 hours a month. That’s a whole extra
work day.
Employees who stayed worked less than whose who left.
plot_ly(hr,
x = ~factor(left, levels = c(0, 1), labels = c('Stayed', 'Left')),
y = ~average_montly_hours,
type = 'box') %>%
layout(
title = 'Employees who stayed worked less than whose who left.',
xaxis = list(title = 'Left Status'),
yaxis = list(title = 'Average Monthly Hours')
)
t.test(hr$number_project ~ hr$left)
##
## Welch Two Sample t-test
##
## data: hr$number_project by hr$left
## t = -2.1663, df = 4236.5, p-value = 0.03034
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
## -0.131136535 -0.006540119
## sample estimates:
## mean in group 0 mean in group 1
## 3.786664 3.855503
The p-value is less than the significance level of .05, which means there is a tiny bit of a difference between the mean number of projects of either groups.
The difference between the means is 3.786664-3.855503,
which is a difference of around a tenth of a project.
Employees who stayed did a little less project work than those who left.
plot_ly(hr,
x = ~factor(left, levels = c(0, 1), labels = c('Stayed', 'Left')),
y = ~number_project,
type = 'box') %>%
layout(
title = 'Employees who stayed did a little less project work than those who left.',
xaxis = list(title = 'Left Status'),
yaxis = list(title = 'Number of Projects')
)
t.test(hr$time_spend_company ~ hr$left)
##
## Welch Two Sample t-test
##
## data: hr$time_spend_company by hr$left
## t = -22.631, df = 9625.6, p-value < 0.00000000000000022
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
## -0.5394767 -0.4534706
## sample estimates:
## mean in group 0 mean in group 1
## 3.380032 3.876505
The p-value is teeny tiny, which means there is a significant different between the years spent at the company between either group.
The difference between the means is 3.876505-3.380032,
which is a difference of around six months.
Employees who stayed worked at the company longer than those who left.
plot_ly(hr,
x = ~factor(left, levels = c(0, 1), labels = c('Stayed', 'Left')),
y = ~time_spend_company,
type = 'box') %>%
layout(
title = 'Employees who stayed worked at the company longer than those who left.',
xaxis = list(title = 'Left Status'),
yaxis = list(title = 'Years with Company')
)