t-test - Employee Attrition Analysis

1

t1 <- t.test(hr$satisfaction_level ~ hr$left)
t1
## 
##  Welch Two Sample t-test
## 
## data:  hr$satisfaction_level by hr$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

p-value interpretation: The p-value is extremely small, so the difference in mean satisfaction level is significant.

t-test interpretation: Employees who left had a significantly lower average satisfaction level.

non-technical interpretation: Employees who left the company were less satisfied.

plot_ly(hr,
        x = ~left,
        y = ~satisfaction_level,
        type = "box") %>%
  layout(title = "Employees who left had lower satisfaction levels")

2

t2 <- t.test(hr$last_evaluation ~ hr$left)
t2
## 
##  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
p-value interpretation: The p-value is large, so there is no significant difference in mean evaluation score.

t-test interpretation: Employees who left and employees who stayed had similar evaluation scores.

non-technical interpretation: Employees who left were evaluated about the same as those who stayed.

plot_ly(hr,
        x = ~left,
        y = ~last_evaluation,
        type = "box") %>%
  layout(title = "Employees who left the company had higher performance evaluations")

3

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

p-value interpretation: The p-value is extremely small, so the difference in mean monthly hours is significant.

t-test interpretation: Employees who left worked significantly more monthly hours on average.

non-technical interpretation: Employees who left the company worked more hours each month.

plot_ly(hr,
        x = ~left,
        y = ~average_montly_hours,
        type = "box") %>%
  layout(title = "Employees who left the company worked more hours each month")

4

t4 <- t.test(hr$time_spend_company ~ hr$left)
t4
## 
##  Welch Two Sample t-test
## 
## data:  hr$time_spend_company by hr$left
## t = -22.631, df = 9625.6, 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.5394767 -0.4534706
## sample estimates:
## mean in group 0 mean in group 1 
##        3.380032        3.876505

p-value interpretation: The p-value is extremely small, so the difference in years at the company is significant.

t-test interpretation: Employees who left had spent significantly more years at the company on average.

non-technical interpretation: Employees who left the company had been there longer.

plot_ly(hr,
        x = ~left,
        y = ~time_spend_company,
        type = "box") %>%
  layout(title = "Employees who left the company had been there longer")