Introduction

With attrition becoming a more and more serious issue in today’s business world, we selected a dataset from IBM which contains 1470 employee data with various relevant information to dive deep into two questions:
1. What are the factors influencing employee attrition?
2. What strategies can be adopted to improve employee retention?
Having a clear goal in mind, we used logistic regression to find out the relationships between those variables and attrition.
The first thing we did was to load necessary packages and clean our dataset.
library(ggplot2)
library(mosaic)
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
library(skimr)
## 
## Attaching package: 'skimr'
## The following object is masked from 'package:mosaic':
## 
##     n_missing
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0          ✔ stringr   1.5.0     
## ✔ lubridate 1.9.2          ✔ tibble    3.2.1     
## ✔ purrr     1.0.2          ✔ tidyr     1.3.0.9000
## ✔ readr     2.1.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ mosaic::count() masks dplyr::count()
## ✖ purrr::cross()  masks mosaic::cross()
## ✖ mosaic::do()    masks dplyr::do()
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ✖ tidyr::pack()   masks Matrix::pack()
## ✖ mosaic::stat()  masks ggplot2::stat()
## ✖ mosaic::tally() masks dplyr::tally()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(here)
## here() starts at /Users/melanie/Desktop/Business Analytics Final Project
library(dplyr)
library(readr)
library(tibble)
library(janitor)
## 
## Attaching package: 'janitor'
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(performance)
library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
library(InformationValue)
library(formatR)
library(knitr)

Inspecting and Cleaning the Data

Reading data into a tibble: The HR data CSV file is loaded from the specified path into a tibble, which is a modern version of a data frame in R.
Filename <- "/Users/melanie/Desktop/Business Analytics Final Project/groupnumber8_finalproject.csv"
Changing the datatypes of the variables: This line uses the read_csv function with specified column types to ensure each column in the dataset is read with the correct data type.
employee_attrition <- readr::read_csv(Filename, col_types = "ffffffcdfffffddddfddfffdfffddddffdfdfdddd")
Cleaning the column names: clean_names function from the janitor package is applied to standardize column names into snake_case.
employee_attrition <- clean_names(employee_attrition, case = "snake")
Removing unnecessary columns (cf_attrition_label,emp_no,employee_number, over18,x2,x0,cf_current_employee,employee_count, standard_hours): This removes specific columns from the dataset that are not needed for the analysis by their index numbers.
employee_attrition <- employee_attrition[-c(4,7,8, 13,15,16,18,22,34)]
Renaming age and distance columns: The rename function is used to change names of the cf_age_band and distance_from_home columns for better readability.
employee_attrition <- employee_attrition %>%
  rename(age_band = cf_age_band, dist_from_home_km = distance_from_home)
Creating a column to indicate positive attrition: A new logical column is created to indicate whether attrition is positive based on the attrition column values.
employee_attrition$positive_attrition <- employee_attrition$attrition == "Yes"
Since a lot of categorical variables only had a few significant categories, we clubbed the non-significant categories, as follows:
Creating a new age variable New_age_band: This uses mutate and case_when to re-categorize the age_band into a new New_age_band variable with simplified age groups.
employee_attrition <- employee_attrition %>%
  mutate(New_age_band = case_when(
    age_band == "Under 25" ~ "Under35",
    age_band == "25 - 34" ~ "Under35",
    age_band == "35 - 44" ~ "Over35",
    age_band == "45 - 54" ~ "Over35",
    age_band == "Over 55" ~ "Over35",
  ))
Creating a new age variable R&D_department: A logical column indicating whether an employee belongs to the R&D department is created.
employee_attrition$research_department <- employee_attrition$department == "R&D"
Reordering categorical variables
employee_attrition$work_life_balance <- factor(employee_attrition$work_life_balance, levels=c("1","2","3","4"))
employee_attrition$job_level <- factor(employee_attrition$job_level, levels=c("1","2","3","4","5"))
employee_attrition$relationship_satisfaction <- factor(employee_attrition$relationship_satisfaction, levels=c("1","2","3","4"))
employee_attrition$job_satisfaction <- factor(employee_attrition$job_satisfaction, levels=c("1","2","3","4"))
Creating a new variable education_field_tech_degree
employee_attrition$technical_education <- employee_attrition$education_field == "Technical Degree"
Creating a new variable low_environment_satisfaction
employee_attrition$low_environment_satisfaction <- employee_attrition$environment_satisfaction == "1"
Creating a new variable job_involvement
employee_attrition$low_job_involvement <- employee_attrition$job_involvement == "1"
Creating a new variable low stock option
employee_attrition$high_stock_option <- employee_attrition$stock_option_level == "1"
Creating a new variable job_role_research_director
employee_attrition$job_role_research_director <- employee_attrition$job_role == "Research Director"
Dropping unnecessary variables: Post-creation of new variables, this drops additional columns that are no longer needed for further analysis.
employee_attrition <- employee_attrition[-c(1, 3, 4, 5, 7, 15, 17, 26)]
glimpse and view functions provide a quick overview of the data structure and the first few rows of the dataset.
tibble::glimpse(employee_attrition)
## Rows: 1,470
## Columns: 32
## $ business_travel              <fct> Travel_Rarely, Travel_Frequently, Travel_…
## $ gender                       <fct> Female, Male, Male, Female, Male, Male, F…
## $ marital_status               <fct> Single, Married, Single, Married, Married…
## $ over_time                    <fct> Yes, No, Yes, Yes, No, No, Yes, No, No, N…
## $ training_times_last_year     <dbl> 0, 3, 3, 3, 3, 2, 3, 2, 2, 3, 5, 3, 1, 2,…
## $ age                          <dbl> 41, 49, 37, 33, 27, 32, 59, 30, 38, 36, 3…
## $ daily_rate                   <dbl> 1102, 279, 1373, 1392, 591, 1005, 1324, 1…
## $ dist_from_home_km            <dbl> 1, 8, 2, 3, 2, 2, 3, 24, 23, 27, 16, 15, …
## $ education                    <fct> Associates Degree, High School, Associate…
## $ hourly_rate                  <dbl> 94, 61, 92, 56, 40, 79, 81, 67, 44, 94, 8…
## $ job_level                    <fct> 2, 2, 1, 1, 1, 1, 1, 1, 3, 2, 1, 2, 1, 1,…
## $ job_satisfaction             <fct> 4, 2, 3, 3, 2, 4, 1, 3, 3, 3, 2, 3, 3, 4,…
## $ monthly_income               <dbl> 5993, 5130, 2090, 2909, 3468, 3068, 2670,…
## $ monthly_rate                 <dbl> 19479, 24907, 2396, 23159, 16632, 11864, …
## $ num_companies_worked         <dbl> 8, 1, 6, 1, 9, 0, 4, 1, 0, 6, 0, 0, 1, 0,…
## $ percent_salary_hike          <dbl> 11, 23, 15, 11, 12, 13, 20, 22, 21, 13, 1…
## $ performance_rating           <fct> 3, 4, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3,…
## $ relationship_satisfaction    <fct> 1, 4, 2, 3, 4, 3, 1, 2, 2, 2, 3, 4, 4, 3,…
## $ total_working_years          <dbl> 8, 10, 7, 8, 6, 8, 12, 1, 10, 17, 6, 10, …
## $ work_life_balance            <fct> 1, 3, 3, 3, 3, 2, 2, 3, 3, 2, 3, 3, 2, 3,…
## $ years_at_company             <dbl> 6, 10, 0, 8, 2, 7, 1, 1, 9, 7, 5, 9, 5, 2…
## $ years_in_current_role        <dbl> 4, 7, 0, 7, 2, 7, 0, 0, 7, 7, 4, 5, 2, 2,…
## $ years_since_last_promotion   <dbl> 0, 1, 0, 3, 2, 3, 0, 0, 1, 7, 0, 0, 4, 1,…
## $ years_with_curr_manager      <dbl> 5, 7, 0, 0, 2, 6, 0, 0, 8, 7, 3, 8, 3, 2,…
## $ positive_attrition           <lgl> TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ New_age_band                 <chr> "Over35", "Over35", "Over35", "Under35", …
## $ research_department          <lgl> FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE…
## $ technical_education          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ low_environment_satisfaction <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, …
## $ low_job_involvement          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ high_stock_option            <lgl> FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, F…
## $ job_role_research_director   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
view(employee_attrition)
Summarising data: The skim function provides a summary of the data, showing data types and missing values for each column.
skimr::skim(employee_attrition)
Data summary
Name employee_attrition
Number of rows 1470
Number of columns 32
_______________________
Column type frequency:
character 1
factor 10
logical 7
numeric 14
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
New_age_band 0 1 6 7 0 2 0

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
business_travel 0 1 FALSE 3 Tra: 1043, Tra: 277, Non: 150
gender 0 1 FALSE 2 Mal: 882, Fem: 588
marital_status 0 1 FALSE 3 Mar: 673, Sin: 470, Div: 327
over_time 0 1 FALSE 2 No: 1054, Yes: 416
education 0 1 FALSE 5 Bac: 572, Mas: 398, Ass: 282, Hig: 170
job_level 0 1 FALSE 5 1: 543, 2: 534, 3: 218, 4: 106
job_satisfaction 0 1 FALSE 4 4: 459, 3: 442, 1: 289, 2: 280
performance_rating 0 1 FALSE 2 3: 1244, 4: 226
relationship_satisfaction 0 1 FALSE 4 3: 459, 4: 432, 2: 303, 1: 276
work_life_balance 0 1 FALSE 4 3: 893, 2: 344, 4: 153, 1: 80

Variable type: logical

skim_variable n_missing complete_rate mean count
positive_attrition 0 1 0.16 FAL: 1233, TRU: 237
research_department 0 1 0.65 TRU: 961, FAL: 509
technical_education 0 1 0.09 FAL: 1338, TRU: 132
low_environment_satisfaction 0 1 0.19 FAL: 1186, TRU: 284
low_job_involvement 0 1 0.06 FAL: 1387, TRU: 83
high_stock_option 0 1 0.41 FAL: 874, TRU: 596
job_role_research_director 0 1 0.05 FAL: 1390, TRU: 80

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
training_times_last_year 0 1 2.80 1.29 0 2 3.0 3.00 6 ▂▇▇▂▃
age 0 1 36.92 9.14 18 30 36.0 43.00 60 ▂▇▇▃▂
daily_rate 0 1 802.49 403.51 102 465 802.0 1157.00 1499 ▇▇▇▇▇
dist_from_home_km 0 1 9.19 8.11 1 2 7.0 14.00 29 ▇▅▂▂▂
hourly_rate 0 1 65.89 20.33 30 48 66.0 83.75 100 ▇▇▇▇▇
monthly_income 0 1 6502.93 4707.96 1009 2911 4919.0 8379.00 19999 ▇▅▂▁▂
monthly_rate 0 1 14313.10 7117.79 2094 8047 14235.5 20461.50 26999 ▇▇▇▇▇
num_companies_worked 0 1 2.69 2.50 0 1 2.0 4.00 9 ▇▃▂▂▁
percent_salary_hike 0 1 15.21 3.66 11 12 14.0 18.00 25 ▇▅▃▂▁
total_working_years 0 1 11.28 7.78 0 6 10.0 15.00 40 ▇▇▂▁▁
years_at_company 0 1 7.01 6.13 0 3 5.0 9.00 40 ▇▂▁▁▁
years_in_current_role 0 1 4.23 3.62 0 2 3.0 7.00 18 ▇▃▂▁▁
years_since_last_promotion 0 1 2.19 3.22 0 0 1.0 3.00 15 ▇▁▁▁▁
years_with_curr_manager 0 1 4.12 3.57 0 2 3.0 7.00 17 ▇▂▅▁▁

Exploratory Data Analysis

Visualization

We created several plots using ggplot2 to visualize relationships between attrition and other variables, such as marital status and age. Please find below the plots we found to be the most useful.

Marital Status vs. Attrition
counts1 <- table(employee_attrition$marital_status, employee_attrition$positive_attrition)

mosaicplot(counts1, xlab = 'Marital Status', ylab = 'Employee Attrition', main = 'Marital Status vs. Employee Attrition', col = 'Orange')

Married people are less likely to leave company because they need to support family and desire stability. But divorced individuals face the same situation, maybe because some of them become the only bread owner with even more pressure.
Work-Life Balance vs. Attrition
ggplot(data = employee_attrition, aes(x = work_life_balance, fill = positive_attrition)) + geom_bar(position = "dodge") + labs(x = "Work-Life Balance Rating", y = "Employee Attrition", title = "Work-Life Balance vs. Employee Attrition", fill = "Employee Attrition")

People have bad work-life balance are more likely to leave the company. This makes sense especially for tech firms, we have witnessed a lot of firms like Google launch flexible working hour and remote working policies. However, we see there’s a fluctuation from level 3 to 4, which will be discusses in the last part.
Job Involvement vs. Attrition
ggplot(data = employee_attrition, aes(x = low_job_involvement, fill = positive_attrition)) + geom_bar(position = "fill") + labs(x = "Low Job Involvement", y = "Employee Attrition", title = "Job Involvement vs. Employee Attrition", fill = "Employee Attrition")

People with higher job involvement are more likely to stay with a company.
The potential reasons are: 1. Employees feel a strong connection to their work and understand how their role contributes to the company’s goals; 2. Highly involved employees experience greater job satisfaction, reducing their motivation to seek opportunities elsewhere; 3. High job involvement provide opportunities for personal and professional development, enhancing satisfaction and retention
Age Category vs. Attrition
ggplot(data = employee_attrition, aes(x = New_age_band, fill = positive_attrition)) + geom_bar(position = "dodge") + labs(x = "Age Category", y = "Employee Attrition", title = "Age Category vs. Employee Attrition", fill = "Employee Attrition")

Odder people have higher possibility of staying in the firm because they care more about stability. Changing job at this stage may bring big influence over their personal life. 35 is the devide based on our correlation analysis. This makes sense because many people are settled down at the age of 35.
Employees Working Over Time vs. Attrition
ggplot(data = employee_attrition, aes(x = over_time, fill = positive_attrition)) + geom_bar(position = "fill") + labs(x = "Employee Working Over Time", y = "Employee Attrition", title = "Employees Working Over Time vs. Employee Attrition", fill = "Employee Attrition")

People often work overtime are more likely to leave the company because this may not be good for their health.
Employees with Technical Education vs. Attrition
ggplot(data = employee_attrition, aes(x = technical_education, fill = positive_attrition)) + geom_bar(position = "fill") + labs(x = "Employees with Technical Education", y = "Employee Attrition", title = "Employees with Technical Education vs. Employee Attrition", fill = "Employee Attrition")

Stack bar chart here shows that people with technical education background are less likely to leave the company. This might because technical roles demand specialized skills and provide clear career paths, making employees valuable assets with opportunities for growth. They also offer competitive pay, benefits, and intellectually stimulating work.

Checking correlations

The ggpairs function is used to create a pairs plot to visually check for correlations between selected variables. (we tried to make the plot more readable using “progress = FALSE”).
employee_attrition %>%
  select(New_age_band, total_working_years, 
    years_at_company, years_in_current_role, years_since_last_promotion, years_with_curr_manager, dist_from_home_km, num_companies_worked) %>%
  ggpairs(aes(colour = New_age_band, alpha = 0.4), progress = FALSE) + theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Testing various models

We tried 10 models during this process with the original model throwing all the variables in.
Model 0
model0 <- glm(positive_attrition ~ .,family = "binomial", data = employee_attrition)

summary(model0)
## 
## Call:
## glm(formula = positive_attrition ~ ., family = "binomial", data = employee_attrition)
## 
## Coefficients:
##                                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       4.016e+00  1.169e+00   3.437 0.000589 ***
## business_travelTravel_Frequently  9.611e-01  2.200e-01   4.368 1.25e-05 ***
## business_travelNon-Travel        -1.112e+00  4.084e-01  -2.724 0.006451 ** 
## genderMale                        4.220e-01  1.898e-01   2.223 0.026185 *  
## marital_statusMarried            -7.291e-01  2.372e-01  -3.074 0.002110 ** 
## marital_statusDivorced           -1.154e+00  2.989e-01  -3.862 0.000112 ***
## over_timeNo                      -2.094e+00  2.029e-01 -10.319  < 2e-16 ***
## training_times_last_year         -1.775e-01  7.451e-02  -2.382 0.017215 *  
## age                               2.640e-03  1.873e-02   0.141 0.887923    
## daily_rate                       -4.055e-04  2.258e-04  -1.796 0.072525 .  
## dist_from_home_km                 5.185e-02  1.111e-02   4.666 3.08e-06 ***
## educationHigh School             -2.604e-01  3.358e-01  -0.775 0.438102    
## educationMaster's Degree         -6.028e-02  2.787e-01  -0.216 0.828756    
## educationBachelor's Degree       -7.598e-02  2.594e-01  -0.293 0.769625    
## educationDoctoral Degree         -1.305e-01  5.989e-01  -0.218 0.827496    
## hourly_rate                       1.738e-03  4.563e-03   0.381 0.703229    
## job_level2                       -1.101e+00  3.339e-01  -3.299 0.000971 ***
## job_level3                        6.926e-01  6.379e-01   1.086 0.277619    
## job_level4                       -2.845e-01  1.222e+00  -0.233 0.815891    
## job_level5                        1.802e+00  1.545e+00   1.167 0.243353    
## job_satisfaction2                -7.229e-01  2.814e-01  -2.569 0.010194 *  
## job_satisfaction3                -7.694e-01  2.471e-01  -3.113 0.001849 ** 
## job_satisfaction4                -1.405e+00  2.668e-01  -5.266 1.40e-07 ***
## monthly_income                   -1.605e-04  8.434e-05  -1.903 0.057018 .  
## monthly_rate                      7.031e-06  1.273e-05   0.552 0.580870    
## num_companies_worked              2.049e-01  3.999e-02   5.124 2.99e-07 ***
## percent_salary_hike              -2.735e-02  3.980e-02  -0.687 0.492020    
## performance_rating4               1.561e-01  4.090e-01   0.382 0.702776    
## relationship_satisfaction2       -8.576e-01  2.949e-01  -2.908 0.003633 ** 
## relationship_satisfaction3       -8.992e-01  2.584e-01  -3.480 0.000502 ***
## relationship_satisfaction4       -9.880e-01  2.596e-01  -3.806 0.000141 ***
## total_working_years              -5.300e-02  2.928e-02  -1.810 0.070323 .  
## work_life_balance2               -9.993e-01  3.647e-01  -2.740 0.006146 ** 
## work_life_balance3               -1.427e+00  3.436e-01  -4.153 3.29e-05 ***
## work_life_balance4               -1.016e+00  4.212e-01  -2.412 0.015871 *  
## years_at_company                  8.456e-02  3.959e-02   2.136 0.032694 *  
## years_in_current_role            -1.247e-01  4.993e-02  -2.497 0.012535 *  
## years_since_last_promotion        1.757e-01  4.482e-02   3.919 8.90e-05 ***
## years_with_curr_manager          -1.630e-01  5.011e-02  -3.253 0.001141 ** 
## New_age_bandUnder35               8.030e-01  3.110e-01   2.582 0.009833 ** 
## research_departmentTRUE          -1.075e+00  2.078e-01  -5.175 2.28e-07 ***
## technical_educationTRUE           9.075e-01  2.964e-01   3.062 0.002199 ** 
## low_environment_satisfactionTRUE  1.202e+00  2.217e-01   5.421 5.91e-08 ***
## low_job_involvementTRUE           1.571e+00  3.339e-01   4.704 2.55e-06 ***
## high_stock_optionTRUE            -6.464e-01  2.459e-01  -2.629 0.008571 ** 
## job_role_research_directorTRUE   -1.326e+00  9.083e-01  -1.459 0.144441    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  811.52  on 1424  degrees of freedom
## AIC: 903.52
## 
## Number of Fisher Scoring iterations: 7
performance::r2_mcfadden(model0)
## # R2 for Generalized Linear Regression
##        R2: 0.375
##   adj. R2: 0.374
Nine logistic regression models are built to predict positive attrition, using different combinations of predictors.
Model 1
model1 <- glm(positive_attrition ~ business_travel + gender + marital_status + over_time + training_times_last_year + dist_from_home_km + job_level + job_satisfaction + num_companies_worked + relationship_satisfaction + work_life_balance + years_at_company + years_in_current_role + years_since_last_promotion + years_with_curr_manager + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model1)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + gender + 
##     marital_status + over_time + training_times_last_year + dist_from_home_km + 
##     job_level + job_satisfaction + num_companies_worked + relationship_satisfaction + 
##     work_life_balance + years_at_company + years_in_current_role + 
##     years_since_last_promotion + years_with_curr_manager + New_age_band + 
##     research_department + technical_education + low_environment_satisfaction + 
##     low_job_involvement + high_stock_option, family = "binomial", 
##     data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       2.90343    0.58302   4.980 6.36e-07 ***
## business_travelTravel_Frequently  0.93062    0.21558   4.317 1.58e-05 ***
## business_travelNon-Travel        -1.04209    0.39398  -2.645 0.008167 ** 
## genderMale                        0.42344    0.18644   2.271 0.023133 *  
## marital_statusMarried            -0.78848    0.23226  -3.395 0.000687 ***
## marital_statusDivorced           -1.16612    0.29612  -3.938 8.21e-05 ***
## over_timeNo                      -2.02977    0.19802 -10.251  < 2e-16 ***
## training_times_last_year         -0.18415    0.07354  -2.504 0.012278 *  
## dist_from_home_km                 0.05133    0.01093   4.694 2.68e-06 ***
## job_level2                       -1.63322    0.24630  -6.631 3.33e-11 ***
## job_level3                       -0.77969    0.30508  -2.556 0.010596 *  
## job_level4                       -2.89403    0.68848  -4.203 2.63e-05 ***
## job_level5                       -1.85352    0.68970  -2.687 0.007201 ** 
## job_satisfaction2                -0.66970    0.27763  -2.412 0.015858 *  
## job_satisfaction3                -0.74394    0.24240  -3.069 0.002148 ** 
## job_satisfaction4                -1.40490    0.26307  -5.340 9.28e-08 ***
## num_companies_worked              0.17133    0.03670   4.668 3.04e-06 ***
## relationship_satisfaction2       -0.87589    0.28768  -3.045 0.002329 ** 
## relationship_satisfaction3       -0.87388    0.25204  -3.467 0.000526 ***
## relationship_satisfaction4       -0.97236    0.25496  -3.814 0.000137 ***
## work_life_balance2               -0.99564    0.35683  -2.790 0.005267 ** 
## work_life_balance3               -1.40693    0.33583  -4.189 2.80e-05 ***
## work_life_balance4               -1.00902    0.41326  -2.442 0.014622 *  
## years_at_company                  0.06706    0.03640   1.842 0.065443 .  
## years_in_current_role            -0.14291    0.04848  -2.948 0.003203 ** 
## years_since_last_promotion        0.18221    0.04386   4.154 3.26e-05 ***
## years_with_curr_manager          -0.15880    0.04949  -3.209 0.001333 ** 
## New_age_bandUnder35               0.94692    0.20504   4.618 3.87e-06 ***
## research_departmentTRUE          -1.17617    0.20114  -5.848 4.99e-09 ***
## technical_educationTRUE           0.84274    0.29192   2.887 0.003891 ** 
## low_environment_satisfactionTRUE  1.11396    0.21566   5.165 2.40e-07 ***
## low_job_involvementTRUE           1.50710    0.32283   4.668 3.04e-06 ***
## high_stock_optionTRUE            -0.60648    0.24203  -2.506 0.012216 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  828.66  on 1437  degrees of freedom
## AIC: 894.66
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model1)
## # R2 for Generalized Linear Regression
##        R2: 0.362
##   adj. R2: 0.360
Model 2
model2 <- glm(positive_attrition ~ business_travel + gender + marital_status + over_time + training_times_last_year + dist_from_home_km + job_satisfaction + num_companies_worked + relationship_satisfaction + work_life_balance + years_in_current_role + years_since_last_promotion + years_with_curr_manager + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model2)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + gender + 
##     marital_status + over_time + training_times_last_year + dist_from_home_km + 
##     job_satisfaction + num_companies_worked + relationship_satisfaction + 
##     work_life_balance + years_in_current_role + years_since_last_promotion + 
##     years_with_curr_manager + New_age_band + research_department + 
##     technical_education + low_environment_satisfaction + low_job_involvement + 
##     high_stock_option, family = "binomial", data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       2.12275    0.54418   3.901 9.59e-05 ***
## business_travelTravel_Frequently  0.84999    0.20600   4.126 3.69e-05 ***
## business_travelNon-Travel        -1.03173    0.37915  -2.721 0.006506 ** 
## genderMale                        0.43315    0.17997   2.407 0.016094 *  
## marital_statusMarried            -0.88994    0.22552  -3.946 7.94e-05 ***
## marital_statusDivorced           -1.10754    0.28333  -3.909 9.27e-05 ***
## over_timeNo                      -1.93288    0.18901 -10.226  < 2e-16 ***
## training_times_last_year         -0.18275    0.07099  -2.574 0.010048 *  
## dist_from_home_km                 0.04303    0.01040   4.138 3.51e-05 ***
## job_satisfaction2                -0.58309    0.26343  -2.213 0.026866 *  
## job_satisfaction3                -0.70528    0.23300  -3.027 0.002471 ** 
## job_satisfaction4                -1.37657    0.25351  -5.430 5.63e-08 ***
## num_companies_worked              0.11511    0.03524   3.267 0.001089 ** 
## relationship_satisfaction2       -0.87018    0.27524  -3.162 0.001569 ** 
## relationship_satisfaction3       -0.71147    0.24164  -2.944 0.003237 ** 
## relationship_satisfaction4       -0.90955    0.24640  -3.691 0.000223 ***
## work_life_balance2               -1.03306    0.34292  -3.013 0.002591 ** 
## work_life_balance3               -1.43525    0.32312  -4.442 8.92e-06 ***
## work_life_balance4               -0.97571    0.39419  -2.475 0.013314 *  
## years_in_current_role            -0.12497    0.04193  -2.980 0.002879 ** 
## years_since_last_promotion        0.18879    0.03846   4.909 9.16e-07 ***
## years_with_curr_manager          -0.15846    0.04191  -3.781 0.000156 ***
## New_age_bandUnder35               1.19229    0.19070   6.252 4.05e-10 ***
## research_departmentTRUE          -0.67826    0.17765  -3.818 0.000135 ***
## technical_educationTRUE           0.93044    0.27726   3.356 0.000791 ***
## low_environment_satisfactionTRUE  1.06975    0.20566   5.202 1.98e-07 ***
## low_job_involvementTRUE           1.35836    0.31368   4.330 1.49e-05 ***
## high_stock_optionTRUE            -0.47751    0.23215  -2.057 0.039696 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  888.71  on 1442  degrees of freedom
## AIC: 944.71
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model2)
## # R2 for Generalized Linear Regression
##        R2: 0.316
##   adj. R2: 0.314
Model 3
model3 <- glm(positive_attrition ~ business_travel + marital_status + over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + work_life_balance + years_in_current_role + years_since_last_promotion + years_with_curr_manager + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model3)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + marital_status + 
##     over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + 
##     work_life_balance + years_in_current_role + years_since_last_promotion + 
##     years_with_curr_manager + New_age_band + research_department + 
##     technical_education + low_environment_satisfaction + low_job_involvement + 
##     high_stock_option, family = "binomial", data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       2.26065    0.47243   4.785 1.71e-06 ***
## business_travelTravel_Frequently  0.79718    0.20211   3.944 8.00e-05 ***
## business_travelNon-Travel        -0.97889    0.37070  -2.641 0.008275 ** 
## marital_statusMarried            -0.81936    0.22089  -3.709 0.000208 ***
## marital_statusDivorced           -1.02597    0.27688  -3.705 0.000211 ***
## over_timeNo                      -1.86740    0.18406 -10.145  < 2e-16 ***
## dist_from_home_km                 0.03964    0.01021   3.883 0.000103 ***
## job_satisfaction2                -0.61596    0.26053  -2.364 0.018065 *  
## job_satisfaction3                -0.69200    0.22874  -3.025 0.002485 ** 
## job_satisfaction4                -1.35470    0.24824  -5.457 4.84e-08 ***
## relationship_satisfaction2       -0.78606    0.27027  -2.908 0.003632 ** 
## relationship_satisfaction3       -0.62642    0.23725  -2.640 0.008283 ** 
## relationship_satisfaction4       -0.82550    0.24241  -3.405 0.000661 ***
## work_life_balance2               -1.07469    0.33702  -3.189 0.001429 ** 
## work_life_balance3               -1.46770    0.31726  -4.626 3.72e-06 ***
## work_life_balance4               -0.97607    0.38822  -2.514 0.011930 *  
## years_in_current_role            -0.12848    0.04150  -3.096 0.001962 ** 
## years_since_last_promotion        0.17894    0.03743   4.781 1.75e-06 ***
## years_with_curr_manager          -0.15542    0.04103  -3.788 0.000152 ***
## New_age_bandUnder35               0.99490    0.17929   5.549 2.87e-08 ***
## research_departmentTRUE          -0.65049    0.17458  -3.726 0.000194 ***
## technical_educationTRUE           0.88765    0.27303   3.251 0.001149 ** 
## low_environment_satisfactionTRUE  1.06515    0.20165   5.282 1.28e-07 ***
## low_job_involvementTRUE           1.32973    0.30720   4.328 1.50e-05 ***
## high_stock_optionTRUE            -0.48853    0.22857  -2.137 0.032568 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  912.89  on 1445  degrees of freedom
## AIC: 962.89
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model3)
## # R2 for Generalized Linear Regression
##        R2: 0.297
##   adj. R2: 0.295
Model 4
model4 <- glm(positive_attrition ~ business_travel + marital_status + over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + work_life_balance + years_in_current_role + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model4)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + marital_status + 
##     over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + 
##     work_life_balance + years_in_current_role + New_age_band + 
##     research_department + technical_education + low_environment_satisfaction + 
##     low_job_involvement + high_stock_option, family = "binomial", 
##     data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       1.95532    0.45257   4.320 1.56e-05 ***
## business_travelTravel_Frequently  0.80016    0.19774   4.046 5.20e-05 ***
## business_travelNon-Travel        -0.90446    0.36301  -2.492 0.012718 *  
## marital_statusMarried            -0.72787    0.21709  -3.353 0.000800 ***
## marital_statusDivorced           -0.97329    0.27119  -3.589 0.000332 ***
## over_timeNo                      -1.82109    0.17989 -10.123  < 2e-16 ***
## dist_from_home_km                 0.03816    0.01005   3.798 0.000146 ***
## job_satisfaction2                -0.52299    0.25588  -2.044 0.040965 *  
## job_satisfaction3                -0.62024    0.22401  -2.769 0.005627 ** 
## job_satisfaction4                -1.27277    0.24256  -5.247 1.54e-07 ***
## relationship_satisfaction2       -0.73802    0.26567  -2.778 0.005469 ** 
## relationship_satisfaction3       -0.60134    0.23332  -2.577 0.009957 ** 
## relationship_satisfaction4       -0.76396    0.23852  -3.203 0.001361 ** 
## work_life_balance2               -0.99899    0.32979  -3.029 0.002452 ** 
## work_life_balance3               -1.38154    0.30900  -4.471 7.78e-06 ***
## work_life_balance4               -0.88245    0.37890  -2.329 0.019861 *  
## years_in_current_role            -0.14409    0.02904  -4.962 6.98e-07 ***
## New_age_bandUnder35               0.92128    0.17302   5.325 1.01e-07 ***
## research_departmentTRUE          -0.63781    0.17138  -3.722 0.000198 ***
## technical_educationTRUE           0.88956    0.26834   3.315 0.000916 ***
## low_environment_satisfactionTRUE  0.95905    0.19674   4.875 1.09e-06 ***
## low_job_involvementTRUE           1.34004    0.29974   4.471 7.80e-06 ***
## high_stock_optionTRUE            -0.46068    0.22460  -2.051 0.040253 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  941.92  on 1447  degrees of freedom
## AIC: 987.92
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model4)
## # R2 for Generalized Linear Regression
##        R2: 0.275
##   adj. R2: 0.273
Model 5
model5 <- glm(positive_attrition ~ business_travel + marital_status + over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + work_life_balance + years_with_curr_manager + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model5)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + marital_status + 
##     over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + 
##     work_life_balance + years_with_curr_manager + New_age_band + 
##     research_department + technical_education + low_environment_satisfaction + 
##     low_job_involvement + high_stock_option, family = "binomial", 
##     data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       2.08808    0.46193   4.520 6.17e-06 ***
## business_travelTravel_Frequently  0.82293    0.19845   4.147 3.37e-05 ***
## business_travelNon-Travel        -0.85281    0.36120  -2.361 0.018224 *  
## marital_statusMarried            -0.75643    0.21660  -3.492 0.000479 ***
## marital_statusDivorced           -0.96982    0.27060  -3.584 0.000338 ***
## over_timeNo                      -1.83536    0.18065 -10.160  < 2e-16 ***
## dist_from_home_km                 0.03782    0.01004   3.766 0.000166 ***
## job_satisfaction2                -0.52426    0.25591  -2.049 0.040503 *  
## job_satisfaction3                -0.63996    0.22454  -2.850 0.004371 ** 
## job_satisfaction4                -1.31924    0.24443  -5.397 6.77e-08 ***
## relationship_satisfaction2       -0.73729    0.26633  -2.768 0.005635 ** 
## relationship_satisfaction3       -0.59510    0.23392  -2.544 0.010960 *  
## relationship_satisfaction4       -0.73488    0.23871  -3.079 0.002080 ** 
## work_life_balance2               -1.08444    0.33239  -3.263 0.001104 ** 
## work_life_balance3               -1.47442    0.31224  -4.722 2.33e-06 ***
## work_life_balance4               -0.97229    0.38165  -2.548 0.010847 *  
## years_with_curr_manager          -0.14981    0.02842  -5.271 1.36e-07 ***
## New_age_bandUnder35               0.89146    0.17343   5.140 2.74e-07 ***
## research_departmentTRUE          -0.63884    0.17201  -3.714 0.000204 ***
## technical_educationTRUE           0.89505    0.26927   3.324 0.000887 ***
## low_environment_satisfactionTRUE  1.01155    0.19730   5.127 2.94e-07 ***
## low_job_involvementTRUE           1.34754    0.30110   4.475 7.63e-06 ***
## high_stock_optionTRUE            -0.50597    0.22497  -2.249 0.024508 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  938.58  on 1447  degrees of freedom
## AIC: 984.58
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model5)
## # R2 for Generalized Linear Regression
##        R2: 0.277
##   adj. R2: 0.276
Model 6
model6 <- glm(positive_attrition ~ business_travel + marital_status + over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + work_life_balance + years_since_last_promotion + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model6)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + marital_status + 
##     over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + 
##     work_life_balance + years_since_last_promotion + New_age_band + 
##     research_department + technical_education + low_environment_satisfaction + 
##     low_job_involvement + high_stock_option, family = "binomial", 
##     data = employee_attrition)
## 
## Coefficients:
##                                   Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       1.346185   0.438328   3.071 0.002132 ** 
## business_travelTravel_Frequently  0.726195   0.193621   3.751 0.000176 ***
## business_travelNon-Travel        -0.906331   0.354672  -2.555 0.010606 *  
## marital_statusMarried            -0.776978   0.214856  -3.616 0.000299 ***
## marital_statusDivorced           -1.011072   0.267403  -3.781 0.000156 ***
## over_timeNo                      -1.820499   0.177299 -10.268  < 2e-16 ***
## dist_from_home_km                 0.037515   0.009842   3.812 0.000138 ***
## job_satisfaction2                -0.462688   0.251903  -1.837 0.066244 .  
## job_satisfaction3                -0.544209   0.219651  -2.478 0.013226 *  
## job_satisfaction4                -1.247685   0.239442  -5.211 1.88e-07 ***
## relationship_satisfaction2       -0.670408   0.261416  -2.565 0.010332 *  
## relationship_satisfaction3       -0.531662   0.230105  -2.311 0.020859 *  
## relationship_satisfaction4       -0.732652   0.235378  -3.113 0.001854 ** 
## work_life_balance2               -1.053655   0.328722  -3.205 0.001349 ** 
## work_life_balance3               -1.431958   0.307426  -4.658 3.19e-06 ***
## work_life_balance4               -0.938796   0.376012  -2.497 0.012535 *  
## years_since_last_promotion        0.009183   0.027930   0.329 0.742311    
## New_age_bandUnder35               1.037792   0.173921   5.967 2.42e-09 ***
## research_departmentTRUE          -0.599915   0.168740  -3.555 0.000378 ***
## technical_educationTRUE           0.839054   0.264019   3.178 0.001483 ** 
## low_environment_satisfactionTRUE  1.011848   0.195205   5.184 2.18e-07 ***
## low_job_involvementTRUE           1.319914   0.299815   4.402 1.07e-05 ***
## high_stock_optionTRUE            -0.451686   0.221267  -2.041 0.041215 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.6  on 1469  degrees of freedom
## Residual deviance:  969.6  on 1447  degrees of freedom
## AIC: 1015.6
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model6)
## # R2 for Generalized Linear Regression
##        R2: 0.253
##   adj. R2: 0.252
Model 7
model7 <- glm(positive_attrition ~ business_travel + marital_status + over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + work_life_balance + total_working_years + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model7)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + marital_status + 
##     over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + 
##     work_life_balance + total_working_years + New_age_band + 
##     research_department + technical_education + low_environment_satisfaction + 
##     low_job_involvement + high_stock_option, family = "binomial", 
##     data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       2.34897    0.48801   4.813 1.48e-06 ***
## business_travelTravel_Frequently  0.80422    0.19660   4.091 4.30e-05 ***
## business_travelNon-Travel        -0.94367    0.35813  -2.635 0.008415 ** 
## marital_statusMarried            -0.72743    0.21637  -3.362 0.000774 ***
## marital_statusDivorced           -0.97872    0.26905  -3.638 0.000275 ***
## over_timeNo                      -1.83810    0.17934 -10.249  < 2e-16 ***
## dist_from_home_km                 0.03897    0.01005   3.878 0.000105 ***
## job_satisfaction2                -0.50722    0.25499  -1.989 0.046682 *  
## job_satisfaction3                -0.60576    0.22225  -2.726 0.006419 ** 
## job_satisfaction4                -1.31491    0.24276  -5.416 6.08e-08 ***
## relationship_satisfaction2       -0.66198    0.26333  -2.514 0.011941 *  
## relationship_satisfaction3       -0.55891    0.23253  -2.404 0.016236 *  
## relationship_satisfaction4       -0.73153    0.23718  -3.084 0.002041 ** 
## work_life_balance2               -1.01891    0.33053  -3.083 0.002051 ** 
## work_life_balance3               -1.43623    0.30936  -4.643 3.44e-06 ***
## work_life_balance4               -0.94039    0.37968  -2.477 0.013258 *  
## total_working_years              -0.07229    0.01608  -4.495 6.95e-06 ***
## New_age_bandUnder35               0.50243    0.19847   2.532 0.011356 *  
## research_departmentTRUE          -0.60977    0.17081  -3.570 0.000357 ***
## technical_educationTRUE           0.83206    0.26662   3.121 0.001804 ** 
## low_environment_satisfactionTRUE  1.05530    0.19650   5.370 7.86e-08 ***
## low_job_involvementTRUE           1.39864    0.30357   4.607 4.08e-06 ***
## high_stock_optionTRUE            -0.47300    0.22314  -2.120 0.034029 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  947.14  on 1447  degrees of freedom
## AIC: 993.14
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model7)
## # R2 for Generalized Linear Regression
##        R2: 0.271
##   adj. R2: 0.269
Model 8
model8 <- glm(positive_attrition ~ business_travel + marital_status + over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + work_life_balance + years_with_curr_manager + New_age_band + research_department + technical_education + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model8)
## 
## Call:
## glm(formula = positive_attrition ~ business_travel + marital_status + 
##     over_time + dist_from_home_km + job_satisfaction + relationship_satisfaction + 
##     work_life_balance + years_with_curr_manager + New_age_band + 
##     research_department + technical_education + low_environment_satisfaction + 
##     low_job_involvement + high_stock_option, family = "binomial", 
##     data = employee_attrition)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       2.08808    0.46193   4.520 6.17e-06 ***
## business_travelTravel_Frequently  0.82293    0.19845   4.147 3.37e-05 ***
## business_travelNon-Travel        -0.85281    0.36120  -2.361 0.018224 *  
## marital_statusMarried            -0.75643    0.21660  -3.492 0.000479 ***
## marital_statusDivorced           -0.96982    0.27060  -3.584 0.000338 ***
## over_timeNo                      -1.83536    0.18065 -10.160  < 2e-16 ***
## dist_from_home_km                 0.03782    0.01004   3.766 0.000166 ***
## job_satisfaction2                -0.52426    0.25591  -2.049 0.040503 *  
## job_satisfaction3                -0.63996    0.22454  -2.850 0.004371 ** 
## job_satisfaction4                -1.31924    0.24443  -5.397 6.77e-08 ***
## relationship_satisfaction2       -0.73729    0.26633  -2.768 0.005635 ** 
## relationship_satisfaction3       -0.59510    0.23392  -2.544 0.010960 *  
## relationship_satisfaction4       -0.73488    0.23871  -3.079 0.002080 ** 
## work_life_balance2               -1.08444    0.33239  -3.263 0.001104 ** 
## work_life_balance3               -1.47442    0.31224  -4.722 2.33e-06 ***
## work_life_balance4               -0.97229    0.38165  -2.548 0.010847 *  
## years_with_curr_manager          -0.14981    0.02842  -5.271 1.36e-07 ***
## New_age_bandUnder35               0.89146    0.17343   5.140 2.74e-07 ***
## research_departmentTRUE          -0.63884    0.17201  -3.714 0.000204 ***
## technical_educationTRUE           0.89505    0.26927   3.324 0.000887 ***
## low_environment_satisfactionTRUE  1.01155    0.19730   5.127 2.94e-07 ***
## low_job_involvementTRUE           1.34754    0.30110   4.475 7.63e-06 ***
## high_stock_optionTRUE            -0.50597    0.22497  -2.249 0.024508 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  938.58  on 1447  degrees of freedom
## AIC: 984.58
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model8)
## # R2 for Generalized Linear Regression
##        R2: 0.277
##   adj. R2: 0.276
Model 9
model9 <- glm(positive_attrition ~ marital_status + New_age_band
            + years_with_curr_manager + dist_from_home_km + research_department + business_travel + over_time + technical_education + work_life_balance + low_environment_satisfaction + low_job_involvement + high_stock_option,family = "binomial", data = employee_attrition)

summary(model9)
## 
## Call:
## glm(formula = positive_attrition ~ marital_status + New_age_band + 
##     years_with_curr_manager + dist_from_home_km + research_department + 
##     business_travel + over_time + technical_education + work_life_balance + 
##     low_environment_satisfaction + low_job_involvement + high_stock_option, 
##     family = "binomial", data = employee_attrition)
## 
## Coefficients:
##                                   Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                       0.752460   0.387864   1.940 0.052378 .  
## marital_statusMarried            -0.683016   0.211466  -3.230 0.001238 ** 
## marital_statusDivorced           -0.919837   0.264393  -3.479 0.000503 ***
## New_age_bandUnder35               0.867206   0.168691   5.141 2.74e-07 ***
## years_with_curr_manager          -0.140321   0.027706  -5.065 4.09e-07 ***
## dist_from_home_km                 0.034313   0.009729   3.527 0.000420 ***
## research_departmentTRUE          -0.595196   0.167622  -3.551 0.000384 ***
## business_travelTravel_Frequently  0.730157   0.192335   3.796 0.000147 ***
## business_travelNon-Travel        -0.845511   0.351894  -2.403 0.016273 *  
## over_timeNo                      -1.674194   0.171847  -9.742  < 2e-16 ***
## technical_educationTRUE           0.868144   0.260936   3.327 0.000878 ***
## work_life_balance2               -1.088047   0.330734  -3.290 0.001003 ** 
## work_life_balance3               -1.399496   0.309422  -4.523 6.10e-06 ***
## work_life_balance4               -1.013274   0.380294  -2.664 0.007712 ** 
## low_environment_satisfactionTRUE  0.996818   0.190805   5.224 1.75e-07 ***
## low_job_involvementTRUE           1.252641   0.292538   4.282 1.85e-05 ***
## high_stock_optionTRUE            -0.512882   0.221343  -2.317 0.020496 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1298.58  on 1469  degrees of freedom
## Residual deviance:  980.74  on 1453  degrees of freedom
## AIC: 1014.7
## 
## Number of Fisher Scoring iterations: 6
performance::r2_mcfadden(model9)
## # R2 for Generalized Linear Regression
##        R2: 0.245
##   adj. R2: 0.243
Comparing select models
huxtable::huxreg( model7, model8, model9,
                  number_format = "%.3f",
                  bold_signif = 0.05,
                  statistics = c("adj.r.squared", "sigma"))
## Warning in huxtable::huxreg(model7, model8, model9, number_format = "%.3f", : Unrecognized statistics: adj.r.squared, sigma
## Try setting `statistics` explicitly in the call to `huxreg()`
(1)(2)(3)
(Intercept)2.349 ***2.088 ***0.752    
(0.488)   (0.462)   (0.388)   
business_travelTravel_Frequently0.804 ***0.823 ***0.730 ***
(0.197)   (0.198)   (0.192)   
business_travelNon-Travel-0.944 ** -0.853 *  -0.846 *  
(0.358)   (0.361)   (0.352)   
marital_statusMarried-0.727 ***-0.756 ***-0.683 ** 
(0.216)   (0.217)   (0.211)   
marital_statusDivorced-0.979 ***-0.970 ***-0.920 ***
(0.269)   (0.271)   (0.264)   
over_timeNo-1.838 ***-1.835 ***-1.674 ***
(0.179)   (0.181)   (0.172)   
dist_from_home_km0.039 ***0.038 ***0.034 ***
(0.010)   (0.010)   (0.010)   
job_satisfaction2-0.507 *  -0.524 *          
(0.255)   (0.256)           
job_satisfaction3-0.606 ** -0.640 **         
(0.222)   (0.225)           
job_satisfaction4-1.315 ***-1.319 ***        
(0.243)   (0.244)           
relationship_satisfaction2-0.662 *  -0.737 **         
(0.263)   (0.266)           
relationship_satisfaction3-0.559 *  -0.595 *          
(0.233)   (0.234)           
relationship_satisfaction4-0.732 ** -0.735 **         
(0.237)   (0.239)           
work_life_balance2-1.019 ** -1.084 ** -1.088 ** 
(0.331)   (0.332)   (0.331)   
work_life_balance3-1.436 ***-1.474 ***-1.399 ***
(0.309)   (0.312)   (0.309)   
work_life_balance4-0.940 *  -0.972 *  -1.013 ** 
(0.380)   (0.382)   (0.380)   
total_working_years-0.072 ***                
(0.016)                   
New_age_bandUnder350.502 *  0.891 ***0.867 ***
(0.198)   (0.173)   (0.169)   
research_departmentTRUE-0.610 ***-0.639 ***-0.595 ***
(0.171)   (0.172)   (0.168)   
technical_educationTRUE0.832 ** 0.895 ***0.868 ***
(0.267)   (0.269)   (0.261)   
low_environment_satisfactionTRUE1.055 ***1.012 ***0.997 ***
(0.197)   (0.197)   (0.191)   
low_job_involvementTRUE1.399 ***1.348 ***1.253 ***
(0.304)   (0.301)   (0.293)   
high_stock_optionTRUE-0.473 *  -0.506 *  -0.513 *  
(0.223)   (0.225)   (0.221)   
years_with_curr_manager        -0.150 ***-0.140 ***
        (0.028)   (0.028)   
*** p < 0.001; ** p < 0.01; * p < 0.05.

Confidence Interval

This block calculates the confidence interval for the predictions made by model9, providing a range in which the true value of the model’s predictions likely falls.
predictions <- predict(model9, data.frame(marital_status = "Married", New_age_band = "Under35", years_since_last_promotion = 7, years_with_curr_manager = 7, dist_from_home_km = 8, research_department = TRUE, over_time = "No", work_life_balance = "3", technical_education = TRUE, low_environment_satisfaction = TRUE, low_job_involvement = TRUE, high_stock_option = TRUE, business_travel = "Travel_Frequently"), type = "response", se.fit = TRUE)
predictions
## $fit
##         1 
## 0.4737472 
## 
## $se.fit
##         1 
## 0.1177752 
## 
## $residual.scale
## [1] 1
#Estimated probability
predictions$fit
##         1 
## 0.4737472
#95% Confidence Interval
predictions$fit - 1.96*predictions$se.fit
##         1 
## 0.2429077
predictions$fit + 1.96*predictions$se.fit
##         1 
## 0.7045866

Checking Accuracy

We set attrition probability to 50% and checked this threshold’s accuracy
employee_attrition$estimatedProbability <- predict(model9, employee_attrition, type = "response")
employee_attrition$estimatedExEmployee <- employee_attrition$estimatedProbability > 0.5
head(employee_attrition)
## # A tibble: 6 × 34
##   business_travel   gender marital_status over_time training_times_last_…¹   age
##   <fct>             <fct>  <fct>          <fct>                      <dbl> <dbl>
## 1 Travel_Rarely     Female Single         Yes                            0    41
## 2 Travel_Frequently Male   Married        No                             3    49
## 3 Travel_Rarely     Male   Single         Yes                            3    37
## 4 Travel_Frequently Female Married        Yes                            3    33
## 5 Travel_Rarely     Male   Married        No                             3    27
## 6 Travel_Frequently Male   Single         No                             2    32
## # ℹ abbreviated name: ¹​training_times_last_year
## # ℹ 28 more variables: daily_rate <dbl>, dist_from_home_km <dbl>,
## #   education <fct>, hourly_rate <dbl>, job_level <fct>,
## #   job_satisfaction <fct>, monthly_income <dbl>, monthly_rate <dbl>,
## #   num_companies_worked <dbl>, percent_salary_hike <dbl>,
## #   performance_rating <fct>, relationship_satisfaction <fct>,
## #   total_working_years <dbl>, work_life_balance <fct>, …
sum(employee_attrition$estimatedExEmployee == employee_attrition$positive_attrition)
## [1] 1272
nrow(employee_attrition)
## [1] 1470
We found the best threshold using the function optimalcuttoff from the package InformationValue
(BestThreshold <- InformationValue::optimalCutoff(employee_attrition$positive_attrition, employee_attrition$estimatedProbability))
## [1] 0.5614536
employee_attrition$estimExEmplBestThres <- employee_attrition$estimatedProbability > BestThreshold

sum(employee_attrition$estimExEmplBestThres == employee_attrition$positive_attrition)/nrow(employee_attrition)
## [1] 0.8693878
We created a confusion matrix using the package InformationValue. Further, we observed sensitivity (correctly predicting an employee leaving the company) and specificity (correctly predicting an employee staying in the company) of our model
InformationValue::confusionMatrix(actuals = employee_attrition$positive_attrition, predictedScores = employee_attrition$estimatedProbability, threshold = BestThreshold)
##   FALSE TRUE
## 0  1218  177
## 1    15   60
InformationValue::sensitivity(actuals = employee_attrition$positive_attrition, predictedScores = employee_attrition$estimatedProbability, threshold = BestThreshold)
## [1] 0.2531646
InformationValue::specificity(actuals = employee_attrition$positive_attrition, predictedScores = employee_attrition$estimatedProbability, threshold = BestThreshold)
## [1] 0.9878345
The ROC curve can be seen as below
InformationValue::plotROC(employee_attrition$positive_attrition, employee_attrition$estimatedProbability)

Conclusion

To avoid attrition, manager should improve work-life balance and enhance employee engagement.This could involve implementing flexible work schedules, providing opportunities for professional development, and creating a supportive work environment. Additionally, offering benefits such as wellness programs or mentorship initiatives can contribute to greater job satisfaction and reduce turnover. By prioritizing these strategies, managers can cultivate a workforce that feels valued, motivated, and committed to the organization’s goals, ultimately leading to lower attrition rates and improved overall performance.