title: “Assignment 8: t-test - Employee Attrition Analysis” output: html_document ———————

Load Data

hr <- read_csv("https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv")

hr <- hr %>%
  mutate(left_label = factor(left, levels = c(0, 1), labels = c("Stayed", "Left")))

1. Satisfaction Level and Attrition

t1 <- t.test(satisfaction_level ~ left, data = hr)
t1
## 
##  Welch Two Sample t-test
## 
## data:  satisfaction_level by left
## t = 46.636, df = 5167, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  0.2171815 0.2362417
## sample estimates:
## mean in group 0 mean in group 1 
##       0.6668096       0.4400980

Technical interpretation: The p-value is very small, which means the difference in mean satisfaction level between employees who stayed and employees who left is statistically significant.

Non-technical interpretation: Employees who left were generally less satisfied with their jobs than employees who stayed.

ggplot(hr, aes(x = left_label, y = satisfaction_level)) +
  geom_boxplot() +
  labs(
    title = "Employees who left were generally less satisfied with their jobs than employees who stayed",
    x = "Employee Status",
    y = "Satisfaction Level"
  ) +
  theme_minimal()

2. Last Evaluation and Attrition

t2 <- t.test(last_evaluation ~ left, data = hr)
t2
## 
##  Welch Two Sample t-test
## 
## data:  last_evaluation by 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

Technical interpretation: The p-value is very small, so the difference in mean last evaluation scores between employees who stayed and employees who left is statistically significant.

Non-technical interpretation: Employees who left tended to have slightly higher evaluation scores than employees who stayed.

ggplot(hr, aes(x = left_label, y = last_evaluation)) +
  geom_boxplot() +
  labs(
    title = "Employees who left tended to have slightly higher evaluation scores than employees who stayed",
    x = "Employee Status",
    y = "Last Evaluation Score"
  ) +
  theme_minimal()

3. Number of Projects and Attrition

t3 <- t.test(number_project ~ left, data = hr)
t3
## 
##  Welch Two Sample t-test
## 
## data:  number_project by 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

Technical interpretation: The p-value is very small, which means the difference in mean number of projects between employees who stayed and employees who left is statistically significant.

Non-technical interpretation: Employees who left usually worked on more projects than employees who stayed.

ggplot(hr, aes(x = left_label, y = number_project)) +
  geom_boxplot() +
  labs(
    title = "Employees who left usually worked on more projects than employees who stayed",
    x = "Employee Status",
    y = "Number of Projects"
  ) +
  theme_minimal()

4. Average Monthly Hours and Attrition

t4 <- t.test(average_montly_hours ~ left, data = hr)
t4
## 
##  Welch Two Sample t-test
## 
## data:  average_montly_hours by left
## t = -7.5323, df = 4875.1, p-value = 5.907e-14
## 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

Technical interpretation: The p-value is very small, so the difference in mean average monthly hours between employees who stayed and employees who left is statistically significant.

Non-technical interpretation: Employees who left generally worked more hours per month than employees who stayed.

ggplot(hr, aes(x = left_label, y = average_montly_hours)) +
  geom_boxplot() +
  labs(
    title = "Employees who left generally worked more hours per month than employees who stayed",
    x = "Employee Status",
    y = "Average Monthly Hours"
  ) +
  theme_minimal()