telco_train <- read.csv("~/Financial Software/WA_Fn-UseC_-HR-Employee-Attrition.csv", header = TRUE)
data <- telco_train[, c("EmployeeNumber", "Department", "JobRole", "PerformanceRating", "Attrition")]
# Number of attrition by department
attrition_dept <- table(data$Department, data$Attrition)
attrition_dept
##                         
##                           No Yes
##   Human Resources         51  12
##   Research & Development 828 133
##   Sales                  354  92
# Percentage of attrition by department
prop.table(attrition_dept, margin = 1) * 100
##                         
##                                No      Yes
##   Human Resources        80.95238 19.04762
##   Research & Development 86.16025 13.83975
##   Sales                  79.37220 20.62780
# Number of attrition by job role and department
attrition_jobrole <- table(data$Department, data$JobRole, data$Attrition)
attrition_jobrole
## , ,  = No
## 
##                         
##                          Healthcare Representative Human Resources
##   Human Resources                                0              40
##   Research & Development                       122               0
##   Sales                                          0               0
##                         
##                          Laboratory Technician Manager Manufacturing Director
##   Human Resources                            0      11                      0
##   Research & Development                   197      51                    135
##   Sales                                      0      35                      0
##                         
##                          Research Director Research Scientist Sales Executive
##   Human Resources                        0                  0               0
##   Research & Development                78                245               0
##   Sales                                  0                  0             269
##                         
##                          Sales Representative
##   Human Resources                           0
##   Research & Development                    0
##   Sales                                    50
## 
## , ,  = Yes
## 
##                         
##                          Healthcare Representative Human Resources
##   Human Resources                                0              12
##   Research & Development                         9               0
##   Sales                                          0               0
##                         
##                          Laboratory Technician Manager Manufacturing Director
##   Human Resources                            0       0                      0
##   Research & Development                    62       3                     10
##   Sales                                      0       2                      0
##                         
##                          Research Director Research Scientist Sales Executive
##   Human Resources                        0                  0               0
##   Research & Development                 2                 47               0
##   Sales                                  0                  0              57
##                         
##                          Sales Representative
##   Human Resources                           0
##   Research & Development                    0
##   Sales                                    33
# Percentage of attrition by job role and department
prop.table(attrition_jobrole, margin = c(1,2)) * 100
## , ,  = No
## 
##                         
##                          Healthcare Representative Human Resources
##   Human Resources                                        76.923077
##   Research & Development                 93.129771                
##   Sales                                                           
##                         
##                          Laboratory Technician    Manager
##   Human Resources                              100.000000
##   Research & Development             76.061776  94.444444
##   Sales                                         94.594595
##                         
##                          Manufacturing Director Research Director
##   Human Resources                                                
##   Research & Development              93.103448         97.500000
##   Sales                                                          
##                         
##                          Research Scientist Sales Executive
##   Human Resources                                          
##   Research & Development          83.904110                
##   Sales                                           82.515337
##                         
##                          Sales Representative
##   Human Resources                            
##   Research & Development                     
##   Sales                             60.240964
## 
## , ,  = Yes
## 
##                         
##                          Healthcare Representative Human Resources
##   Human Resources                                        23.076923
##   Research & Development                  6.870229                
##   Sales                                                           
##                         
##                          Laboratory Technician    Manager
##   Human Resources                                0.000000
##   Research & Development             23.938224   5.555556
##   Sales                                          5.405405
##                         
##                          Manufacturing Director Research Director
##   Human Resources                                                
##   Research & Development               6.896552          2.500000
##   Sales                                                          
##                         
##                          Research Scientist Sales Executive
##   Human Resources                                          
##   Research & Development          16.095890                
##   Sales                                           17.484663
##                         
##                          Sales Representative
##   Human Resources                            
##   Research & Development                     
##   Sales                             39.759036
calculate_attrition_cost <- function(
    
  # Employee
  n                    = 1,
  salary               = 80000,
  
  # Direct Costs
  separation_cost      = 500,
  vacancy_cost         = 10000,
  acquisition_cost     = 4900,
  placement_cost       = 3500,
  
  # Productivity Costs
  net_revenue_per_employee = 250000,
  workdays_per_year        = 240,
  workdays_position_open   = 40,
  workdays_onboarding      = 60,
  onboarding_efficiency    = 0.50
  
) {
  
  # Direct Costs
  direct_cost <- sum(separation_cost, vacancy_cost, acquisition_cost, placement_cost)
  
  # Lost Productivity Costs
  productivity_cost <- net_revenue_per_employee / workdays_per_year * 
    (workdays_position_open + workdays_onboarding * onboarding_efficiency) 
  
  # Savings of Salary & Benefits (Cost Reduction)
  salary_benefit_reduction <- salary / workdays_per_year * workdays_position_open
  
  # Estimated Turnover Per Employee
  cost_per_employee <- direct_cost + productivity_cost - salary_benefit_reduction
  
  # Total Cost of Employee Turnover
  total_cost <- n * cost_per_employee
  
  return(total_cost)

}
calculate_attrition_cost(n = 1, salary = 80000) 
## [1] 78483.33