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
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.
#Perform four (4) t-tests using any appropriate variables (continuous) by #the variable left. Note that the variable left describes whether the employee #left the company (left = 1), or not (left = 0).
#For each of the four t-tests:
#1. Perform the t-test (.5 point) Choose any two appropriate variables from #the data and perform the t-test, displaying the results.
hr1 <- hr %>%
mutate(Employee_status = ifelse(left == 0, 'Stayed', 'Left'))
t.test(hr1$average_montly_hours ~ hr1$Employee_status)
##
## Welch Two Sample t-test
##
## data: hr1$average_montly_hours by hr1$Employee_status
## t = 7.5323, df = 4875.1, p-value = 5.907e-14
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
## 6.183384 10.534631
## sample estimates:
## mean in group Left mean in group Stayed
## 207.4192 199.0602
#2. Interpret the results in technical terms (.5 point) For each t-test, explain what the test’s p-value means (significance).
#There is a significant difference between means, where employees that left worked at least 6 hours more.
#3. Interpret the results in non-technical terms (1 point) For each t-test,what do the results mean in non-technical terms.
#Discriptive: Employees that left, on average, work more hours, at least 3% more. #Perscritptive: To reduce employee attrition, average monthly hours can be reduced by 3%, for those that work long hours.
#4. Create a plot that helps visualize the t-test (.5 point) For each t-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
plot_ly(hr1,
x = ~Employee_status ,
y = ~average_montly_hours ,
type = 'box' ,
color = ~Employee_status,
colors = c('#1a1aff' , '#ff3333'))%>%
layout(title = 'Employees that left, on average, work more hours, at least 3% more')
#1. Perform the t-test (.5 point) Choose any two appropriate variables from the data and perform the t-test, displaying the results.
t.test(hr1$last_evaluation ~ hr1$Employee_status)
##
## Welch Two Sample t-test
##
## data: hr1$last_evaluation by hr1$Employee_status
## t = 0.72534, df = 5154.9, p-value = 0.4683
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
## -0.004493874 0.009772224
## sample estimates:
## mean in group Left mean in group Stayed
## 0.7181126 0.7154734
#2. Interpret the results in technical terms (.5 point) For each t-test, explain what the test’s p-value means (significance).
#There is no significance between the last evaluation of an employee and their employee status.
#3. Interpret the results in non-technical terms (1 point) For each t-test, what do the results mean in non-techical terms.
#The last evaluation of employees had no effect on whether or not they would leave.
#4. Create a plot that helps visualize the t-test (.5 point) For each t-test, create a graph to help visualize the difference between means, if any. The title must be the non-technical interpretation.
plot_ly(hr1,
x = ~Employee_status ,
y = ~last_evaluation ,
type = 'box' ,
color = ~Employee_status,
colors = c('#1a1aff' , '#ff3333'))%>%
layout(title = 'Employees that left were not affected by their last evaluation')
#1. Perform the t-test (.5 point) Choose any two appropriate variables from the data and perform the t-test, displaying the results.
t.test(hr1$satisfaction_level ~ hr1$Employee_status)
##
## Welch Two Sample t-test
##
## data: hr1$satisfaction_level by hr1$Employee_status
## t = -46.636, df = 5167, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
## -0.2362417 -0.2171815
## sample estimates:
## mean in group Left mean in group Stayed
## 0.4400980 0.6668096
#2. Interpret the results in technical terms (.5 point) For each t-test, explain what the test’s p-value means (significance).
#The p-value indicates that there is significant difference between the mean of employees staying or leaving and their satisfaction levels.
#3. Interpret the results in non-technical terms (1 point) For each t-test, what do the results mean in non-technical terms.
#Employees that left had a lower satisfaction level.
#4. Create a plot that helps visualize the t-test (.5 point) For each t-test, create a graph to help visualize the difference between means, if any. The title must be the non-technical interpretation.
plot_ly(hr1,
x = ~Employee_status ,
y = ~satisfaction_level ,
type = 'box' ,
color = ~Employee_status,
colors = c('#1a1aff' , '#ff3333'))%>%
layout(title = 'Employees that left had lower satisfaction levels')
#1. Perform the t-test (.5 point) Choose any two appropriate variables from the data and perform the t-test, displaying the results.
t.test(hr1$promotion_last_5years ~ hr1$Employee_status)
##
## Welch Two Sample t-test
##
## data: hr1$promotion_last_5years by hr1$Employee_status
## t = -10.853, df = 13132, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
## -0.02471098 -0.01715037
## sample estimates:
## mean in group Left mean in group Stayed
## 0.005320638 0.026251313
#2. Interpret the results in technical terms (.5 point) For each t-test, explain what the test’s p-value means (significance).
#There is a significant difference between the mean of employees staying or leaving and whether or not they got a promotion in the last 5 years.
#3. Interpret the results in non-technical terms (1 point) For each t-test, what do the results mean in non-technical terms.
#On average, employees that received a promotion within the last five years stayed, whereas employees that didn’t receive a promotion left.
#4. Create a plot that helps visualize the t-test (.5 point) For each t-test, create a graph to help visualize the difference between means, if any. The title must be the non-technical interpretation.
plot_ly(hr1,
x = ~Employee_status ,
y = ~promotion_last_5years ,
type = 'box' ,
color = ~Employee_status,
colors = c('#1a1aff' , '#ff3333'))%>%
layout(title = 'Employees that left, on average, did not recieve a promotion within the last 5 years')