Analyzing employee attrition

with an introduction to Quarto

Author

Elizabeth Fitzgerald

Introduction

This data is from Kaggle. This data details employee job characteristics and whether they stayed in their role or not. Each row represents an employee, while each column represents a characteristic of their employment. Source: link.

option command i = create a code chunk

command shift enter = run a code chunk

stayorgo <- read_csv("https://myxavier-my.sharepoint.com/:x:/g/personal/fitzgeralde4_xavier_edu/EUAghCPAA-JBu5pvb7-9yocBaqLWYLeF0Nqbye3czSCyyg?download=1")

hist(stayorgo$MonthlyIncome)

Research Question

Are frequent business travelers more likely to leave their job than those that rarely travel for business, if they are paid less? I hypothesize that they are more likely to leave if they are paid less because the added stress of travel with an extra monetary incentive may help balance out the stress and make them less likely to quit.

I will answer this question by comparing the yearly salaries of employees that travel at different frequencies with boxplots, and use color to indicate if the employee quit (attrition) or stayed in the job. I chose to calculate yearly salary because other variables in the data set are reported yearly, so I wanted to make it consistent. Using a boxplot will allow me to examine the frequencies of employees in different levels of travel at higher or lower yearly salaries that stayed versus left the job.

library(skimr)
library(tidyverse)
stayorgo <- read_csv("https://myxavier-my.sharepoint.com/:x:/g/personal/fitzgeralde4_xavier_edu/EUAghCPAA-JBu5pvb7-9yocBaqLWYLeF0Nqbye3czSCyyg?download=1")
stayorgo$YearlyIncome <- c(stayorgo$MonthlyIncome * 12)
stayorgo %>%
  ggplot(aes(x=as.factor(BusinessTravel), y=YearlyIncome, color=Attrition))+
  geom_boxplot()+
  scale_y_continuous(labels = scales::dollar)+
  scale_x_discrete(labels = c("Travel_Frequently" = "Travel Frequently", "Travel_Rarely" = "Travel Rarely"))+
  labs(title="Attrition and Salaries by Business Travel Frequency",
       x="Travel Frequency")

This visualization supports the hypothesis that frequent travelers that are paid lower salaries quit more frequently. The distribution has a smaller maximum and smaller median salary for employees that quit, while those that travel frequently and did not quit have a much higher maximum, and a higher median. However, for employees that travel rarely, compared to those that do not travel, rare travelers with higher salaries actually quit more frequently than those who don’t travel.

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2
{r}
#| title: data import

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).