<!DOCTYPE html>

Case Study 2

# Project Presentation

https://smu.zoom.us/rec/share/_PzRRtfdhT2ePWzXH0Lx2sIZMq8GwgeKTA2HAVasKvkCtHDZZRhChZdbOfmoVHVZ.ew57SCDdjbvTRiCs?startTime=1702429652000 Passcode: rdV076=w

CDCastr0.github.io/pro

Preparing the Environment and Loading the Data

This is loading the necessary libraries like readr, dplyr, tidyr, ggplot2, caret, e1071, and class.

# Load libraries
library(rmarkdown)
library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(caret)
## Warning: package 'caret' was built under R version 4.3.2
## Loading required package: ggplot2
## Loading required package: lattice
library(e1071)
## Warning: package 'e1071' was built under R version 4.3.2
library(class)
library(ggplot2)


# Load data
data <- read.csv(choose.files())
# Convert categorical variables to factors
data$Attrition <- factor(data$Attrition, levels = c("No", "Yes"), labels = c(0, 1))
data$BusinessTravel <- factor(data$BusinessTravel)
data$Department <- factor(data$Department)
data$EducationField <- factor(data$EducationField)
data$Gender <- factor(data$Gender)
data$JobRole <- factor(data$JobRole)
data$MaritalStatus <- factor(data$MaritalStatus)
data$Over18 <- factor(data$Over18)
data$OverTime <- factor(data$OverTime)
# Convert factors to numeric for correlation analysis
data_numeric <- data %>%
  mutate(across(where(is.factor), as.numeric))

# Remove constant variables
data_numeric <- data_numeric %>% select_if(~sd(.) != 0)

# Exploratory Data Analysis

To begin, we started by analyzing the correlation between all variables. This produced a correlation matrix used to reference different variables in the selection process.

# Perform correlation analysis
correlation <- cor(data_numeric, use = "complete.obs")

# Sort the correlation with Attrition and find the top factors
sorted_correlation <- sort(correlation['Attrition',], decreasing = TRUE)

# Display the top factors (excluding Attrition itself)
sorted_correlation[sorted_correlation != 1][1:3]
##      OverTime MaritalStatus       JobRole 
##     0.2720366     0.1970150     0.0905386

We next plotted different graphs in order to understand how the variables related to each other.

ggplot(data, aes(x = JobRole, fill = Attrition)) +
  geom_bar(position = "dodge") +
  labs(title = "Job Role vs Attrition", x = "Job Role", y = "Count") +
  theme_minimal()

ggplot(data, aes(x = OverTime, fill = Attrition)) +
  geom_bar(position = "dodge") +
  labs(title = "Overtime vs Attrition", x = "Overtime", y = "Count") +
  theme_minimal()

ggplot(data, aes(x = MaritalStatus, fill = Attrition)) +
  geom_bar(position = "dodge") +
  labs(title = "Marital Status vs Attrition", x = "Marital Status", y = "Count") +
  theme_minimal()

# Visualizing correlations
#correlation_plot <- cor(data %>% select_if(is.numeric))
#ggplot(data = as.data.frame(correlation_plot), aes(x = Var1, y = Var2, fill = value)) +
  geom_tile()
## geom_tile: linejoin = mitre, na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity
# Identifying top factors for attrition
#attrition_factors <- data %>% 
#  group_by(attrition) %>% 
#  summarise_all(funs(mean(., na.rm = TRUE)))
#Analyzing the distribution of attrition across different departments
#ggplot(data, aes(x = Department, fill = Attrition)) +
#  geom_bar(position = "fill") +
#  labs(title = "Attrition Distribution Across Departments", x = "Department", y = "Proportion")


# Exploring the relationship between job satisfaction and attrition
#ggplot(data, aes(x = JobSatisfaction, fill = Attrition)) +
#  geom_bar(position = "fill") +
#  labs(title = "Job Satisfaction vs Attrition", x = "Job Satisfaction Level", y = "Proportion")

# Relationship between total working years and attrition
#ggplot(data, aes(x = TotalWorkingYears, y = after_stat(count), fill = Attrition)) +
#  geom_histogram(binwidth = 1, position = "dodge") +
#  labs(title = "Total Working Years vs Attrition", x = "Total Working Years", y = "Count")

# Plotting histogram of a variable (example: Age)
#ggplot(data, aes(x = Age)) + geom_histogram(bins = 30) + theme_minimal()

# Exploring relationship between two variables (example: Age and Attrition)
#ggplot(data, aes(x = Age, fill = Attrition)) + geom_histogram(bins = 30) + theme_minimal()

# Analyzing the distribution of attrition across different departments
#ggplot(data, aes(x = Department, fill = Attrition)) +
#  geom_bar(position = "fill") +
#  labs(title = "Attrition Distribution Across Departments", x = "Department", y = "Proportion")

# Exploring the relationship between job satisfaction and attrition
#ggplot(data, aes(x = JobSatisfaction, fill = Attrition)) +
#  geom_bar(position = "fill") +
#  labs(title = "Job Satisfaction vs Attrition", x = "Job Satisfaction Level", y = "Proportion")

# Relationship between total working years and attrition
#ggplot(data, aes(x = TotalWorkingYears, y = after_stat(count), fill = Attrition)) +
#  geom_histogram(binwidth = 1, position = "dodge") +
#  labs(title = "Total Working Years vs Attrition", x = "Total Working Years", y = "Count")

# Analyzing job role specific trends in job satisfaction
#ggplot(data, aes(x = JobRole, y = JobSatisfaction)) +
#  geom_boxplot() +
#  labs(title = "Job Satisfaction Across Different Job Roles", x = "Job Role", y = "Job Satisfaction Level") +
#  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Job role specific attrition trends
#ggplot(data, aes(x = JobRole, fill = Attrition)) +
#  geom_bar(position = "fill") +
#  labs(title = "Attrition Rates Across Different Job Roles", x = "Job Role", y = "Proportion") +
#  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Age distribution with respect to attrition
#ggplot(data, aes(x = Age, fill = Attrition)) +
#  geom_histogram(binwidth = 1, position = "dodge") +
#  labs(title = "Age Distribution vs Attrition", x = "Age", y = "Count")

# Exploring the impact of marital status on attrition
#ggplot(data, aes(x = MaritalStatus, fill = Attrition)) +
#  geom_bar(position = "fill") +
#  labs(title = "Marital Status vs Attrition", x = "Marital Status", y = "Proportion")

Parts of the above EDA were generated by AI and were useful in coming up with creative graphs.

# Analysis of Important Variables

Given the most highly correlated variables, we decided to proceed with a model that includes them in order to test it’s accuracy.

data$Attrition
##   [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1
##  [38] 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0
##  [75] 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
## [112] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0
## [149] 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
## [186] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
## [223] 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
## [260] 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
## [297] 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
## [334] 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0
## [371] 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
## [408] 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0
## [445] 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0
## [482] 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0
## [519] 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [556] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
## [593] 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0
## [630] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
## [667] 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0
## [704] 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0
## [741] 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
## [778] 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
## [815] 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1
## [852] 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0
## Levels: 0 1
# Load the data
data <- read.csv(choose.files())

# Check the unique values in Attrition column
unique(data$Attrition)
## [1] "No"  "Yes"
# Ensure Attrition is converted to a factor with correct levels
#data$Attrition <- factor(data$Attrition, levels = c("No", "Yes"))

# Convert other variables to factors
#data$OverTime <- factor(data$OverTime)
#data$JobRole <- factor(data$JobRole)
#data$MaritalStatus <- factor(data$MaritalStatus)

# Function to calculate attrition rates
#calculate_attrition_rate <- function(data, column_name) {
#  data %>%
#    group_by(!!sym(column_name)) %>%
#    summarise(Attrition_Count = sum(Attrition == "Yes", na.rm = TRUE),
#              Total_Count = n(),
#              Attrition_Rate = Attrition_Count / Total_Count) %>%
#    arrange(desc(Attrition_Rate))
#}

# Calculate attrition rates for Job Role, Overtime, and Marital Status
#job_role_attrition <- calculate_attrition_rate(data, "JobRole")
#overtime_attrition <- calculate_attrition_rate(data, "OverTime")
#marital_status_attrition <- calculate_attrition_rate(data, "MaritalStatus")

# Display the results
#job_role_attrition
#overtime_attrition
#marital_status_attrition

This did not yield a reliable or accurate model, so we began to search elsewhere for better variables.

# T-tests and Variables

# Load the data
data <- read.csv(choose.files())

# Ensure data$Attrition is a factor and check its levels
data$Attrition <- as.factor(data$Attrition)
print(levels(data$Attrition))  # Should output something like '0' and '1' or 'Yes' and 'No'
## [1] "No"  "Yes"
# Identify numeric variables
numeric_vars <- sapply(data, is.numeric)
numeric_vars_names <- names(data)[numeric_vars]

# Initialize an empty data frame to store t-test results
t_test_results <- data.frame(Variable = character(), 
                             p_value = numeric(), 
                             mean_diff = numeric(), 
                             stringsAsFactors = FALSE)

# Corrected code for handling variables with little or no variance within groups
for (var in numeric_vars_names) {
  # Perform t-test if the variable has more than one unique value in both groups
  if (length(unique(data[data$Attrition == levels(data$Attrition)[1], var])) > 1 &&
      length(unique(data[data$Attrition == levels(data$Attrition)[2], var])) > 1) {
    
    # Perform t-test
    t_test <- t.test(data[[var]] ~ data$Attrition)
    
    # Calculate mean difference
    mean_diff <- abs(diff(tapply(data[[var]], data$Attrition, mean, na.rm=TRUE)))
    
    # Append results to the data frame
    t_test_results <- rbind(t_test_results, 
                            data.frame(Variable = var, 
                                       p_value = t_test$p.value, 
                                       mean_diff = mean_diff))
  }
}

# Order results by p-value
t_test_results <- t_test_results[order(t_test_results$p_value),]

# Display the results
print(t_test_results)
##                       Variable      p_value    mean_diff
## Yes11            MonthlyIncome 2.412488e-07 1.937214e+03
## Yes9                  JobLevel 4.041851e-07 4.807241e-01
## Yes18        TotalWorkingYears 6.595682e-07 3.417025e+00
## Yes22       YearsInCurrentRole 1.522152e-06 1.546282e+00
## Yes8            JobInvolvement 1.997298e-06 3.593933e-01
## Yes24     YearsWithCurrManager 5.084229e-06 1.427006e+00
## Yes17         StockOptionLevel 3.860043e-05 3.468689e-01
## Yes1                       Age 5.049764e-05 3.626614e+00
## Yes21           YearsAtCompany 2.563021e-04 2.108513e+00
## Yes10          JobSatisfaction 1.497265e-03 3.259295e-01
## Yes3          DistanceFromHome 1.640519e-02 1.928376e+00
## Yes20          WorkLifeBalance 1.900885e-02 1.738748e-01
## Yes6   EnvironmentSatisfaction 3.397271e-02 2.312133e-01
## Yes19    TrainingTimesLastYear 5.948323e-02 2.171233e-01
## Yes13       NumCompaniesWorked 9.788235e-02 4.182975e-01
## Yes4                 Education 1.421319e-01 1.375734e-01
## Yes                         ID 1.636497e-01 3.230577e+01
## Yes12              MonthlyRate 1.980950e-01 8.358376e+02
## Yes16 RelationshipSatisfaction 2.639669e-01 1.188845e-01
## Yes7                HourlyRate 2.744798e-01 2.001076e+00
## Yes2                 DailyRate 3.188749e-01 3.686742e+01
## Yes5            EmployeeNumber 4.978776e-01 3.749432e+01
## Yes15        PerformanceRating 6.610278e-01 1.497065e-02
## Yes14        PercentSalaryHike 6.692297e-01 1.532290e-01
## Yes23  YearsSinceLastPromotion 8.983165e-01 3.962818e-02

Given these results, we began to proceed with the new model.

# Load the data
train_data <- read.csv(choose.files())
test_data <- read.csv(choose.files())

str(train_data)
## 'data.frame':    870 obs. of  36 variables:
##  $ ID                      : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Age                     : int  32 40 35 32 24 27 41 37 34 34 ...
##  $ Attrition               : chr  "No" "No" "No" "No" ...
##  $ BusinessTravel          : chr  "Travel_Rarely" "Travel_Rarely" "Travel_Frequently" "Travel_Rarely" ...
##  $ DailyRate               : int  117 1308 200 801 567 294 1283 309 1333 653 ...
##  $ Department              : chr  "Sales" "Research & Development" "Research & Development" "Sales" ...
##  $ DistanceFromHome        : int  13 14 18 1 2 10 5 10 10 10 ...
##  $ Education               : int  4 3 2 4 1 2 5 4 4 4 ...
##  $ EducationField          : chr  "Life Sciences" "Medical" "Life Sciences" "Marketing" ...
##  $ EmployeeCount           : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ EmployeeNumber          : int  859 1128 1412 2016 1646 733 1448 1105 1055 1597 ...
##  $ EnvironmentSatisfaction : int  2 3 3 3 1 4 2 4 3 4 ...
##  $ Gender                  : chr  "Male" "Male" "Male" "Female" ...
##  $ HourlyRate              : int  73 44 60 48 32 32 90 88 87 92 ...
##  $ JobInvolvement          : int  3 2 3 3 3 3 4 2 3 2 ...
##  $ JobLevel                : int  2 5 3 3 1 3 1 2 1 2 ...
##  $ JobRole                 : chr  "Sales Executive" "Research Director" "Manufacturing Director" "Sales Executive" ...
##  $ JobSatisfaction         : int  4 3 4 4 4 1 3 4 3 3 ...
##  $ MaritalStatus           : chr  "Divorced" "Single" "Single" "Married" ...
##  $ MonthlyIncome           : int  4403 19626 9362 10422 3760 8793 2127 6694 2220 5063 ...
##  $ MonthlyRate             : int  9250 17544 19944 24032 17218 4809 5561 24223 18410 15332 ...
##  $ NumCompaniesWorked      : int  2 1 2 1 1 1 2 2 1 1 ...
##  $ Over18                  : chr  "Y" "Y" "Y" "Y" ...
##  $ OverTime                : chr  "No" "No" "No" "No" ...
##  $ PercentSalaryHike       : int  11 14 11 19 13 21 12 14 19 14 ...
##  $ PerformanceRating       : int  3 3 3 3 3 4 3 3 3 3 ...
##  $ RelationshipSatisfaction: int  3 1 3 3 3 3 1 3 4 2 ...
##  $ StandardHours           : int  80 80 80 80 80 80 80 80 80 80 ...
##  $ StockOptionLevel        : int  1 0 0 2 0 2 0 3 1 1 ...
##  $ TotalWorkingYears       : int  8 21 10 14 6 9 7 8 1 8 ...
##  $ TrainingTimesLastYear   : int  3 2 2 3 2 4 5 5 2 3 ...
##  $ WorkLifeBalance         : int  2 4 3 3 3 2 2 3 3 2 ...
##  $ YearsAtCompany          : int  5 20 2 14 6 9 4 1 1 8 ...
##  $ YearsInCurrentRole      : int  2 7 2 10 3 7 2 0 1 2 ...
##  $ YearsSinceLastPromotion : int  0 4 2 5 1 1 0 0 0 7 ...
##  $ YearsWithCurrManager    : int  3 9 2 7 3 7 3 0 0 7 ...
# Select relevant columns and convert factors (modify as per your top factors)
#train_data <- train_data %>%
#  select(Attrition, OverTime, JobRole, MaritalStatus) %>%
#  mutate(OverTime = factor(OverTime),
#         Attrition = factor(Attrition, levels = c("No", "Yes")))

# Select relevant columns and convert factors (modify as per your top factors)
#train_data <- train_data %>%
#  select(Attrition, MonthlyIncome, JobLevel, TotalWorkingYears) %>%
#  mutate(MonthlyIncome = factor(MonthlyIncome),
#         Attrition = factor(Attrition, levels = c("No", "Yes")))


# Assuming MonthlyIncome is already loaded in your data frame
# First, check the range of MonthlyIncome
range(train_data$MonthlyIncome)
## [1]  1081 19999
# Now, create the breaks for the intervals
min_income <- min(train_data$MonthlyIncome, na.rm = TRUE)
max_income <- max(train_data$MonthlyIncome, na.rm = TRUE)
breaks <- seq(from = min_income, to = max_income, by = 100)

# Use cut function to create a new factor variable
train_data$IncomeGroup <- cut(train_data$MonthlyIncome, breaks = breaks, include.lowest = TRUE, right = FALSE)

# Display the structure to see the changes
str(train_data$IncomeGroup)
##  Factor w/ 189 levels "[1.08e+03,1.18e+03)",..: 34 186 83 94 27 78 11 57 12 40 ...
# Optional: Convert IncomeGroup to a numeric code if needed
train_data$IncomeGroupCode <- as.numeric(train_data$IncomeGroup)

# Display the first few rows of the dataset to verify
head(train_data)
##   ID Age Attrition    BusinessTravel DailyRate             Department
## 1  1  32        No     Travel_Rarely       117                  Sales
## 2  2  40        No     Travel_Rarely      1308 Research & Development
## 3  3  35        No Travel_Frequently       200 Research & Development
## 4  4  32        No     Travel_Rarely       801                  Sales
## 5  5  24        No Travel_Frequently       567 Research & Development
## 6  6  27        No Travel_Frequently       294 Research & Development
##   DistanceFromHome Education   EducationField EmployeeCount EmployeeNumber
## 1               13         4    Life Sciences             1            859
## 2               14         3          Medical             1           1128
## 3               18         2    Life Sciences             1           1412
## 4                1         4        Marketing             1           2016
## 5                2         1 Technical Degree             1           1646
## 6               10         2    Life Sciences             1            733
##   EnvironmentSatisfaction Gender HourlyRate JobInvolvement JobLevel
## 1                       2   Male         73              3        2
## 2                       3   Male         44              2        5
## 3                       3   Male         60              3        3
## 4                       3 Female         48              3        3
## 5                       1 Female         32              3        1
## 6                       4   Male         32              3        3
##                  JobRole JobSatisfaction MaritalStatus MonthlyIncome
## 1        Sales Executive               4      Divorced          4403
## 2      Research Director               3        Single         19626
## 3 Manufacturing Director               4        Single          9362
## 4        Sales Executive               4       Married         10422
## 5     Research Scientist               4        Single          3760
## 6 Manufacturing Director               1      Divorced          8793
##   MonthlyRate NumCompaniesWorked Over18 OverTime PercentSalaryHike
## 1        9250                  2      Y       No                11
## 2       17544                  1      Y       No                14
## 3       19944                  2      Y       No                11
## 4       24032                  1      Y       No                19
## 5       17218                  1      Y      Yes                13
## 6        4809                  1      Y       No                21
##   PerformanceRating RelationshipSatisfaction StandardHours StockOptionLevel
## 1                 3                        3            80                1
## 2                 3                        1            80                0
## 3                 3                        3            80                0
## 4                 3                        3            80                2
## 5                 3                        3            80                0
## 6                 4                        3            80                2
##   TotalWorkingYears TrainingTimesLastYear WorkLifeBalance YearsAtCompany
## 1                 8                     3               2              5
## 2                21                     2               4             20
## 3                10                     2               3              2
## 4                14                     3               3             14
## 5                 6                     2               3              6
## 6                 9                     4               2              9
##   YearsInCurrentRole YearsSinceLastPromotion YearsWithCurrManager
## 1                  2                       0                    3
## 2                  7                       4                    9
## 3                  2                       2                    2
## 4                 10                       5                    7
## 5                  3                       1                    3
## 6                  7                       1                    7
##           IncomeGroup IncomeGroupCode
## 1 [4.38e+03,4.48e+03)              34
## 2 [1.96e+04,1.97e+04)             186
## 3 [9.28e+03,9.38e+03)              83
## 4 [1.04e+04,1.05e+04)              94
## 5 [3.68e+03,3.78e+03)              27
## 6 [8.78e+03,8.88e+03)              78
train_data <- train_data %>%
  select(Attrition, MonthlyIncome, JobLevel, TotalWorkingYears) %>%
  mutate(MonthlyIncome = factor(MonthlyIncome),
         Attrition = factor(Attrition, levels = c("No", "Yes")))


#Previous test with correlation-determined variables
#test_data <- test_data %>%
#  select(OverTime, JobRole, MaritalStatus) %>%
#  mutate(OverTime = factor(OverTime))

test_data <- test_data %>%
  select(MonthlyIncome, JobLevel, TotalWorkingYears) %>%
  mutate(MonthlyIncome = factor(MonthlyIncome))

# Splitting the training data
set.seed(123)  # for reproducibility
training_indices <- createDataPartition(train_data$Attrition, p = 0.8, list = FALSE)
training_set <- train_data[training_indices, ]
validation_set <- train_data[-training_indices, ]

# Trying different values of k
k_values <- c(3, 5, 7, 9)
sensitivities <- c()
specificities <- c()

for (k in k_values) {
  knn_model <- knn3(Attrition ~ ., data = train_data, k = k)
  knn_pred <- predict(knn_model, validation_set, type = "class")
  conf_matrix <- confusionMatrix(knn_pred, validation_set$Attrition)
  sensitivities <- c(sensitivities, conf_matrix$byClass["Sensitivity"])
  specificities <- c(specificities, conf_matrix$byClass["Specificity"])
}

# Find the best k value
best_k <- k_values[which.max(sensitivities + specificities)]

# Training KNN model
knn_model <- knn3(Attrition ~ ., data = training_set, k = 15)

# Training Naive Bayes model
nb_model <- naiveBayes(Attrition ~ ., data = training_set)

# Ensure the validation set has the same structure as the training set
validation_set_formatted <- validation_set %>% select(-Attrition)

# Predicting on the validation set
knn_pred <- predict(knn_model, validation_set_formatted, type = "class")

# Check if the number of predictions matches the number of observations
if(length(knn_pred) != nrow(validation_set)) {
  stop("Number of predictions does not match the number of observations in the validation set.")
}

# Calculate confusion matrix and sensitivity, specificity
knn_conf_matrix <- confusionMatrix(knn_pred, validation_set$Attrition)
knn_sensitivity <- knn_conf_matrix$byClass["Sensitivity"]
knn_specificity <- knn_conf_matrix$byClass["Specificity"]

# Display KNN Sensitivity and Specificity
list(KNN_Sensitivity = knn_sensitivity, KNN_Specificity = knn_specificity)
## $KNN_Sensitivity
## Sensitivity 
##           1 
## 
## $KNN_Specificity
## Specificity 
##           0
nb_pred <- predict(nb_model, validation_set)

# Calculate sensitivity and specificity
knn_conf_matrix <- confusionMatrix(knn_pred, validation_set$Attrition)
nb_conf_matrix <- confusionMatrix(nb_pred, validation_set$Attrition)

# Sensitivity and Specificity for KNN
knn_sensitivity <- knn_conf_matrix$byClass["Sensitivity"]
knn_specificity <- knn_conf_matrix$byClass["Specificity"]

# Sensitivity and Specificity for Naive Bayes
nb_sensitivity <- nb_conf_matrix$byClass["Sensitivity"]
nb_specificity <- nb_conf_matrix$byClass["Specificity"]

# Display results
list(KNN_Sensitivity = knn_sensitivity, KNN_Specificity = knn_specificity,
     NB_Sensitivity = nb_sensitivity, NB_Specificity = nb_specificity)
## $KNN_Sensitivity
## Sensitivity 
##           1 
## 
## $KNN_Specificity
## Specificity 
##           0 
## 
## $NB_Sensitivity
## Sensitivity 
##   0.9863014 
## 
## $NB_Specificity
## Specificity 
##  0.03571429
# Predicting on test data (example with KNN)
test_predictions <- predict(knn_model, test_data)

# Output predictions
test_predictions
##               No        Yes
##   [1,] 0.9047619 0.09523810
##   [2,] 1.0000000 0.00000000
##   [3,] 0.8095238 0.19047619
##   [4,] 0.8666667 0.13333333
##   [5,] 0.8285714 0.17142857
##   [6,] 0.8750000 0.12500000
##   [7,] 0.8076923 0.19230769
##   [8,] 0.9047619 0.09523810
##   [9,] 0.5789474 0.42105263
##  [10,] 0.9047619 0.09523810
##  [11,] 1.0000000 0.00000000
##  [12,] 0.6666667 0.33333333
##  [13,] 0.9047619 0.09523810
##  [14,] 0.5789474 0.42105263
##  [15,] 0.7272727 0.27272727
##  [16,] 0.8888889 0.11111111
##  [17,] 0.9047619 0.09523810
##  [18,] 0.8589744 0.14102564
##  [19,] 0.8285714 0.17142857
##  [20,] 0.9672131 0.03278689
##  [21,] 0.8648649 0.13513514
##  [22,] 0.8648649 0.13513514
##  [23,] 0.9672131 0.03278689
##  [24,] 0.9672131 0.03278689
##  [25,] 0.8500000 0.15000000
##  [26,] 0.8500000 0.15000000
##  [27,] 0.9672131 0.03278689
##  [28,] 0.8500000 0.15000000
##  [29,] 0.8571429 0.14285714
##  [30,] 0.7307692 0.26923077
##  [31,] 0.8888889 0.11111111
##  [32,] 0.9444444 0.05555556
##  [33,] 1.0000000 0.00000000
##  [34,] 0.7272727 0.27272727
##  [35,] 0.9047619 0.09523810
##  [36,] 0.7307692 0.26923077
##  [37,] 0.8571429 0.14285714
##  [38,] 0.8947368 0.10526316
##  [39,] 0.9375000 0.06250000
##  [40,] 0.6666667 0.33333333
##  [41,] 0.8666667 0.13333333
##  [42,] 0.8888889 0.11111111
##  [43,] 0.8095238 0.19047619
##  [44,] 0.8235294 0.17647059
##  [45,] 0.5789474 0.42105263
##  [46,] 0.7777778 0.22222222
##  [47,] 0.9672131 0.03278689
##  [48,] 0.8750000 0.12500000
##  [49,] 0.5454545 0.45454545
##  [50,] 0.8285714 0.17142857
##  [51,] 0.9259259 0.07407407
##  [52,] 0.8823529 0.11764706
##  [53,] 0.7272727 0.27272727
##  [54,] 0.8888889 0.11111111
##  [55,] 0.9176471 0.08235294
##  [56,] 0.7307692 0.26923077
##  [57,] 0.8076923 0.19230769
##  [58,] 0.7272727 0.27272727
##  [59,] 0.8571429 0.14285714
##  [60,] 0.5789474 0.42105263
##  [61,] 0.8064516 0.19354839
##  [62,] 0.8095238 0.19047619
##  [63,] 0.6666667 0.33333333
##  [64,] 0.5454545 0.45454545
##  [65,] 0.5789474 0.42105263
##  [66,] 0.8076923 0.19230769
##  [67,] 0.8571429 0.14285714
##  [68,] 0.7307692 0.26923077
##  [69,] 0.7307692 0.26923077
##  [70,] 0.8095238 0.19047619
##  [71,] 0.7777778 0.22222222
##  [72,] 0.8500000 0.15000000
##  [73,] 0.9047619 0.09523810
##  [74,] 0.8285714 0.17142857
##  [75,] 0.8095238 0.19047619
##  [76,] 0.8648649 0.13513514
##  [77,] 0.8095238 0.19047619
##  [78,] 0.9000000 0.10000000
##  [79,] 0.9444444 0.05555556
##  [80,] 0.5789474 0.42105263
##  [81,] 0.9375000 0.06250000
##  [82,] 0.8571429 0.14285714
##  [83,] 0.9672131 0.03278689
##  [84,] 0.8648649 0.13513514
##  [85,] 0.9047619 0.09523810
##  [86,] 0.9444444 0.05555556
##  [87,] 1.0000000 0.00000000
##  [88,] 0.7307692 0.26923077
##  [89,] 0.8750000 0.12500000
##  [90,] 0.9500000 0.05000000
##  [91,] 0.5789474 0.42105263
##  [92,] 0.8461538 0.15384615
##  [93,] 0.8076923 0.19230769
##  [94,] 0.9672131 0.03278689
##  [95,] 1.0000000 0.00000000
##  [96,] 1.0000000 0.00000000
##  [97,] 0.8888889 0.11111111
##  [98,] 0.8571429 0.14285714
##  [99,] 0.6842105 0.31578947
## [100,] 0.8076923 0.19230769
## [101,] 0.8285714 0.17142857
## [102,] 0.8461538 0.15384615
## [103,] 0.8500000 0.15000000
## [104,] 0.7307692 0.26923077
## [105,] 0.9375000 0.06250000
## [106,] 0.9259259 0.07407407
## [107,] 0.9672131 0.03278689
## [108,] 0.9375000 0.06250000
## [109,] 0.8648649 0.13513514
## [110,] 0.6842105 0.31578947
## [111,] 0.6666667 0.33333333
## [112,] 0.8666667 0.13333333
## [113,] 0.9600000 0.04000000
## [114,] 0.8947368 0.10526316
## [115,] 0.9375000 0.06250000
## [116,] 0.8095238 0.19047619
## [117,] 0.8750000 0.12500000
## [118,] 0.9672131 0.03278689
## [119,] 0.8636364 0.13636364
## [120,] 0.8888889 0.11111111
## [121,] 0.8095238 0.19047619
## [122,] 0.6666667 0.33333333
## [123,] 0.9600000 0.04000000
## [124,] 0.9047619 0.09523810
## [125,] 0.9672131 0.03278689
## [126,] 0.9672131 0.03278689
## [127,] 0.7272727 0.27272727
## [128,] 0.9672131 0.03278689
## [129,] 1.0000000 0.00000000
## [130,] 0.8421053 0.15789474
## [131,] 0.9672131 0.03278689
## [132,] 0.9047619 0.09523810
## [133,] 0.8589744 0.14102564
## [134,] 0.8589744 0.14102564
## [135,] 0.8888889 0.11111111
## [136,] 0.9047619 0.09523810
## [137,] 0.5789474 0.42105263
## [138,] 0.9545455 0.04545455
## [139,] 0.9259259 0.07407407
## [140,] 0.8571429 0.14285714
## [141,] 0.8666667 0.13333333
## [142,] 0.6666667 0.33333333
## [143,] 0.8461538 0.15384615
## [144,] 0.8589744 0.14102564
## [145,] 0.9375000 0.06250000
## [146,] 0.7906977 0.20930233
## [147,] 0.9259259 0.07407407
## [148,] 0.9047619 0.09523810
## [149,] 0.8285714 0.17142857
## [150,] 0.8500000 0.15000000
## [151,] 0.8888889 0.11111111
## [152,] 0.9672131 0.03278689
## [153,] 0.8648649 0.13513514
## [154,] 0.9176471 0.08235294
## [155,] 0.5789474 0.42105263
## [156,] 0.7906977 0.20930233
## [157,] 0.9375000 0.06250000
## [158,] 1.0000000 0.00000000
## [159,] 0.9600000 0.04000000
## [160,] 1.0000000 0.00000000
## [161,] 0.9672131 0.03278689
## [162,] 0.8095238 0.19047619
## [163,] 0.8500000 0.15000000
## [164,] 0.9672131 0.03278689
## [165,] 0.8571429 0.14285714
## [166,] 0.6666667 0.33333333
## [167,] 0.9000000 0.10000000
## [168,] 0.8095238 0.19047619
## [169,] 0.9047619 0.09523810
## [170,] 0.7777778 0.22222222
## [171,] 0.9516129 0.04838710
## [172,] 0.8947368 0.10526316
## [173,] 1.0000000 0.00000000
## [174,] 0.8095238 0.19047619
## [175,] 1.0000000 0.00000000
## [176,] 0.6666667 0.33333333
## [177,] 0.8235294 0.17647059
## [178,] 0.8285714 0.17142857
## [179,] 0.8750000 0.12500000
## [180,] 0.8648649 0.13513514
## [181,] 0.8571429 0.14285714
## [182,] 0.9176471 0.08235294
## [183,] 0.8500000 0.15000000
## [184,] 0.8750000 0.12500000
## [185,] 0.9259259 0.07407407
## [186,] 0.7307692 0.26923077
## [187,] 0.8589744 0.14102564
## [188,] 1.0000000 0.00000000
## [189,] 0.9523810 0.04761905
## [190,] 0.8750000 0.12500000
## [191,] 0.9176471 0.08235294
## [192,] 0.8750000 0.12500000
## [193,] 0.9545455 0.04545455
## [194,] 0.8888889 0.11111111
## [195,] 0.7307692 0.26923077
## [196,] 0.5789474 0.42105263
## [197,] 0.7272727 0.27272727
## [198,] 1.0000000 0.00000000
## [199,] 0.8750000 0.12500000
## [200,] 0.5789474 0.42105263
## [201,] 1.0000000 0.00000000
## [202,] 0.9672131 0.03278689
## [203,] 0.8888889 0.11111111
## [204,] 0.7272727 0.27272727
## [205,] 0.8285714 0.17142857
## [206,] 0.9285714 0.07142857
## [207,] 0.8589744 0.14102564
## [208,] 0.8571429 0.14285714
## [209,] 0.9259259 0.07407407
## [210,] 0.8571429 0.14285714
## [211,] 1.0000000 0.00000000
## [212,] 1.0000000 0.00000000
## [213,] 0.6842105 0.31578947
## [214,] 0.9047619 0.09523810
## [215,] 0.7307692 0.26923077
## [216,] 0.9259259 0.07407407
## [217,] 0.9047619 0.09523810
## [218,] 0.8666667 0.13333333
## [219,] 0.7307692 0.26923077
## [220,] 0.9259259 0.07407407
## [221,] 0.8500000 0.15000000
## [222,] 0.8750000 0.12500000
## [223,] 0.8589744 0.14102564
## [224,] 0.5789474 0.42105263
## [225,] 0.7272727 0.27272727
## [226,] 0.7777778 0.22222222
## [227,] 0.5789474 0.42105263
## [228,] 0.6842105 0.31578947
## [229,] 0.7906977 0.20930233
## [230,] 0.9444444 0.05555556
## [231,] 0.9672131 0.03278689
## [232,] 0.6666667 0.33333333
## [233,] 0.8421053 0.15789474
## [234,] 0.8947368 0.10526316
## [235,] 0.8421053 0.15789474
## [236,] 0.9047619 0.09523810
## [237,] 0.8235294 0.17647059
## [238,] 0.8500000 0.15000000
## [239,] 0.8285714 0.17142857
## [240,] 1.0000000 0.00000000
## [241,] 0.8095238 0.19047619
## [242,] 0.9500000 0.05000000
## [243,] 0.8285714 0.17142857
## [244,] 0.8285714 0.17142857
## [245,] 0.9672131 0.03278689
## [246,] 0.9259259 0.07407407
## [247,] 0.8461538 0.15384615
## [248,] 0.6666667 0.33333333
## [249,] 0.8648649 0.13513514
## [250,] 1.0000000 0.00000000
## [251,] 0.5789474 0.42105263
## [252,] 0.8648649 0.13513514
## [253,] 0.5789474 0.42105263
## [254,] 0.6666667 0.33333333
## [255,] 0.8064516 0.19354839
## [256,] 0.8076923 0.19230769
## [257,] 0.6666667 0.33333333
## [258,] 0.9047619 0.09523810
## [259,] 0.8750000 0.12500000
## [260,] 0.8076923 0.19230769
## [261,] 0.6666667 0.33333333
## [262,] 0.7777778 0.22222222
## [263,] 0.9259259 0.07407407
## [264,] 0.6666667 0.33333333
## [265,] 0.8285714 0.17142857
## [266,] 0.8285714 0.17142857
## [267,] 0.8260870 0.17391304
## [268,] 0.5789474 0.42105263
## [269,] 0.8888889 0.11111111
## [270,] 0.8589744 0.14102564
## [271,] 0.9672131 0.03278689
## [272,] 0.9176471 0.08235294
## [273,] 0.8888889 0.11111111
## [274,] 0.9176471 0.08235294
## [275,] 0.9375000 0.06250000
## [276,] 0.9523810 0.04761905
## [277,] 0.6666667 0.33333333
## [278,] 0.8641975 0.13580247
## [279,] 0.8500000 0.15000000
## [280,] 0.7906977 0.20930233
## [281,] 0.9672131 0.03278689
## [282,] 0.9444444 0.05555556
## [283,] 0.8648649 0.13513514
## [284,] 0.8648649 0.13513514
## [285,] 0.8076923 0.19230769
## [286,] 0.9375000 0.06250000
## [287,] 0.5789474 0.42105263
## [288,] 0.6666667 0.33333333
## [289,] 0.8095238 0.19047619
## [290,] 0.6666667 0.33333333
## [291,] 0.9259259 0.07407407
## [292,] 0.9176471 0.08235294
## [293,] 0.8076923 0.19230769
## [294,] 0.8666667 0.13333333
## [295,] 1.0000000 0.00000000
## [296,] 0.7307692 0.26923077
## [297,] 0.9672131 0.03278689
## [298,] 0.8888889 0.11111111
## [299,] 0.6842105 0.31578947
## [300,] 0.7307692 0.26923077
## [301,] 0.9672131 0.03278689
## [302,] 0.8750000 0.12500000
## [303,] 0.9259259 0.07407407
## [304,] 0.9672131 0.03278689
## [305,] 0.8076923 0.19230769
## [306,] 0.8285714 0.17142857
## [307,] 0.9259259 0.07407407
## [308,] 0.8285714 0.17142857
## [309,] 0.8571429 0.14285714
## [310,] 0.7906977 0.20930233
## [311,] 0.8888889 0.11111111
## [312,] 1.0000000 0.00000000
## [313,] 0.8076923 0.19230769
## [314,] 0.9672131 0.03278689
## [315,] 0.9672131 0.03278689
## [316,] 0.8888889 0.11111111
## [317,] 0.8285714 0.17142857
## [318,] 0.7906977 0.20930233
## [319,] 0.9047619 0.09523810
## [320,] 0.5789474 0.42105263
## [321,] 0.7307692 0.26923077
## [322,] 0.7272727 0.27272727
## [323,] 0.7272727 0.27272727
## [324,] 0.9545455 0.04545455
## [325,] 1.0000000 0.00000000
## [326,] 0.5789474 0.42105263
## [327,] 0.8823529 0.11764706
## [328,] 0.8888889 0.11111111
## [329,] 1.0000000 0.00000000
## [330,] 1.0000000 0.00000000
## [331,] 0.8888889 0.11111111
## [332,] 0.8666667 0.13333333
## [333,] 0.8285714 0.17142857
## [334,] 0.8750000 0.12500000
## [335,] 0.9545455 0.04545455
## [336,] 0.8888889 0.11111111
## [337,] 0.8750000 0.12500000
## [338,] 0.8589744 0.14102564
## [339,] 0.8750000 0.12500000
## [340,] 0.5789474 0.42105263
## [341,] 0.8285714 0.17142857
## [342,] 0.6666667 0.33333333
## [343,] 0.8750000 0.12500000
## [344,] 0.5789474 0.42105263
## [345,] 0.9047619 0.09523810
## [346,] 1.0000000 0.00000000
## [347,] 0.8750000 0.12500000
## [348,] 0.8500000 0.15000000
## [349,] 0.8285714 0.17142857
## [350,] 0.9444444 0.05555556
## [351,] 0.9600000 0.04000000
## [352,] 0.9672131 0.03278689
## [353,] 0.8947368 0.10526316
## [354,] 0.9047619 0.09523810
## [355,] 0.9444444 0.05555556
## [356,] 0.9375000 0.06250000
## [357,] 0.7307692 0.26923077
## [358,] 0.8285714 0.17142857
## [359,] 0.8888889 0.11111111
## [360,] 0.9117647 0.08823529
## [361,] 0.9333333 0.06666667
## [362,] 0.5789474 0.42105263
## [363,] 0.8666667 0.13333333
## [364,] 0.9500000 0.05000000
## [365,] 0.8823529 0.11764706
## [366,] 0.8823529 0.11764706
## [367,] 0.9375000 0.06250000
## [368,] 0.8888889 0.11111111
## [369,] 0.6842105 0.31578947
## [370,] 0.9672131 0.03278689
## [371,] 0.7906977 0.20930233
## [372,] 0.8095238 0.19047619
## [373,] 0.8750000 0.12500000
## [374,] 0.9259259 0.07407407
## [375,] 0.6666667 0.33333333
## [376,] 0.8666667 0.13333333
## [377,] 0.8500000 0.15000000
## [378,] 0.8888889 0.11111111
## [379,] 0.8285714 0.17142857
## [380,] 0.8076923 0.19230769
## [381,] 1.0000000 0.00000000
## [382,] 0.9259259 0.07407407
## [383,] 0.9375000 0.06250000
## [384,] 0.6666667 0.33333333
## [385,] 0.8500000 0.15000000
## [386,] 0.8571429 0.14285714
## [387,] 0.8095238 0.19047619
## [388,] 0.9047619 0.09523810
## [389,] 0.8571429 0.14285714
## [390,] 0.6666667 0.33333333
## [391,] 0.8500000 0.15000000
## [392,] 0.8750000 0.12500000
## [393,] 0.6842105 0.31578947
## [394,] 0.9545455 0.04545455
## [395,] 0.9259259 0.07407407
## [396,] 0.6666667 0.33333333
## [397,] 0.8666667 0.13333333
## [398,] 0.6666667 0.33333333
## [399,] 0.8648649 0.13513514
## [400,] 0.8064516 0.19354839
## [401,] 0.9176471 0.08235294
## [402,] 0.9176471 0.08235294
## [403,] 0.8076923 0.19230769
## [404,] 0.8750000 0.12500000
## [405,] 0.8333333 0.16666667
## [406,] 1.0000000 0.00000000
## [407,] 0.8648649 0.13513514
## [408,] 0.8076923 0.19230769
## [409,] 0.9411765 0.05882353
## [410,] 1.0000000 0.00000000
## [411,] 0.8285714 0.17142857
## [412,] 0.8095238 0.19047619
## [413,] 0.9259259 0.07407407
## [414,] 0.7906977 0.20930233
## [415,] 0.6666667 0.33333333
## [416,] 0.9375000 0.06250000
## [417,] 0.7777778 0.22222222
## [418,] 0.6842105 0.31578947
## [419,] 0.8888889 0.11111111
## [420,] 0.8095238 0.19047619
## [421,] 0.8750000 0.12500000
## [422,] 0.9375000 0.06250000
## [423,] 0.8648649 0.13513514
## [424,] 0.5454545 0.45454545
## [425,] 0.8750000 0.12500000
## [426,] 0.9600000 0.04000000
## [427,] 0.5789474 0.42105263
## [428,] 0.6666667 0.33333333
## [429,] 0.6842105 0.31578947
## [430,] 0.8648649 0.13513514
## [431,] 0.8750000 0.12500000
## [432,] 0.8285714 0.17142857
## [433,] 1.0000000 0.00000000
## [434,] 0.5789474 0.42105263
## [435,] 0.8461538 0.15384615
## [436,] 0.9047619 0.09523810
## [437,] 0.7307692 0.26923077
## [438,] 0.9259259 0.07407407
## [439,] 0.6666667 0.33333333
## [440,] 0.9672131 0.03278689
## [441,] 0.9672131 0.03278689
## [442,] 0.8641975 0.13580247
## [443,] 0.7307692 0.26923077
## [444,] 0.9259259 0.07407407
## [445,] 0.8235294 0.17647059
## [446,] 0.8095238 0.19047619
## [447,] 0.9545455 0.04545455
## [448,] 0.9672131 0.03278689
## [449,] 0.9672131 0.03278689
## [450,] 0.9672131 0.03278689
## [451,] 0.9672131 0.03278689
## [452,] 0.8285714 0.17142857
## [453,] 0.9672131 0.03278689
## [454,] 0.9672131 0.03278689
## [455,] 1.0000000 0.00000000
## [456,] 1.0000000 0.00000000
## [457,] 0.9672131 0.03278689
## [458,] 0.9176471 0.08235294
## [459,] 0.7307692 0.26923077
## [460,] 0.9672131 0.03278689
## [461,] 0.9259259 0.07407407
## [462,] 0.9545455 0.04545455
## [463,] 0.8064516 0.19354839
## [464,] 0.8888889 0.11111111
## [465,] 0.8285714 0.17142857
## [466,] 0.8285714 0.17142857
## [467,] 0.8076923 0.19230769
## [468,] 0.7307692 0.26923077
## [469,] 0.8589744 0.14102564
## [470,] 0.8750000 0.12500000
## [471,] 0.8285714 0.17142857
## [472,] 0.5789474 0.42105263
## [473,] 0.9047619 0.09523810
## [474,] 0.8641975 0.13580247
## [475,] 0.6842105 0.31578947
## [476,] 0.8888889 0.11111111
## [477,] 0.8888889 0.11111111
## [478,] 0.9047619 0.09523810
## [479,] 0.7777778 0.22222222
## [480,] 0.8064516 0.19354839
## [481,] 0.8500000 0.15000000
## [482,] 0.9259259 0.07407407
## [483,] 0.8947368 0.10526316
## [484,] 0.8695652 0.13043478
## [485,] 0.8666667 0.13333333
## [486,] 0.9090909 0.09090909
## [487,] 0.5789474 0.42105263
## [488,] 0.7307692 0.26923077
## [489,] 0.9444444 0.05555556
## [490,] 0.9672131 0.03278689
## [491,] 0.9500000 0.05000000
## [492,] 0.8421053 0.15789474
## [493,] 0.9047619 0.09523810
## [494,] 0.8461538 0.15384615
## [495,] 0.9672131 0.03278689
## [496,] 1.0000000 0.00000000
## [497,] 0.9259259 0.07407407
## [498,] 0.6842105 0.31578947
## [499,] 0.8571429 0.14285714
## [500,] 0.9672131 0.03278689
## [501,] 0.9444444 0.05555556
## [502,] 0.8285714 0.17142857
## [503,] 0.8695652 0.13043478
## [504,] 0.8095238 0.19047619
## [505,] 0.8666667 0.13333333
## [506,] 0.8648649 0.13513514
## [507,] 0.5789474 0.42105263
## [508,] 0.8666667 0.13333333
## [509,] 0.8636364 0.13636364
## [510,] 0.8823529 0.11764706
## [511,] 0.9672131 0.03278689
## [512,] 0.8461538 0.15384615
## [513,] 0.7272727 0.27272727
## [514,] 0.8571429 0.14285714
## [515,] 0.6363636 0.36363636
## [516,] 0.8648649 0.13513514
## [517,] 0.5789474 0.42105263
## [518,] 0.8076923 0.19230769
## [519,] 0.9672131 0.03278689
## [520,] 0.7307692 0.26923077
## [521,] 0.8285714 0.17142857
## [522,] 0.5789474 0.42105263
## [523,] 0.8750000 0.12500000
## [524,] 0.8666667 0.13333333
## [525,] 0.8148148 0.18518519
## [526,] 0.9444444 0.05555556
## [527,] 0.8888889 0.11111111
## [528,] 0.8500000 0.15000000
## [529,] 0.8285714 0.17142857
## [530,] 0.8076923 0.19230769
## [531,] 1.0000000 0.00000000
## [532,] 0.9375000 0.06250000
## [533,] 0.7272727 0.27272727
## [534,] 0.8888889 0.11111111
## [535,] 0.8076923 0.19230769
## [536,] 0.8076923 0.19230769
## [537,] 0.8095238 0.19047619
## [538,] 0.6842105 0.31578947
## [539,] 0.8285714 0.17142857
## [540,] 0.8888889 0.11111111
## [541,] 0.9672131 0.03278689
## [542,] 0.9444444 0.05555556
## [543,] 0.5789474 0.42105263
## [544,] 0.8888889 0.11111111
## [545,] 0.8285714 0.17142857
## [546,] 0.7272727 0.27272727
## [547,] 0.9411765 0.05882353
## [548,] 0.9672131 0.03278689
## [549,] 1.0000000 0.00000000
## [550,] 0.8333333 0.16666667
## [551,] 0.9500000 0.05000000
## [552,] 0.8285714 0.17142857
## [553,] 0.9672131 0.03278689
## [554,] 0.8636364 0.13636364
## [555,] 0.8750000 0.12500000
## [556,] 0.8571429 0.14285714
## [557,] 0.9545455 0.04545455
## [558,] 0.8285714 0.17142857
## [559,] 0.9672131 0.03278689
## [560,] 0.9047619 0.09523810
## [561,] 0.8636364 0.13636364
## [562,] 0.8888889 0.11111111
## [563,] 0.6842105 0.31578947
## [564,] 0.8461538 0.15384615
## [565,] 0.8076923 0.19230769
## [566,] 0.8285714 0.17142857
## [567,] 0.8888889 0.11111111
## [568,] 0.9672131 0.03278689
## [569,] 0.9672131 0.03278689
## [570,] 1.0000000 0.00000000
## [571,] 0.8888889 0.11111111
## [572,] 0.5789474 0.42105263
## [573,] 0.8589744 0.14102564
## [574,] 0.9672131 0.03278689
## [575,] 0.8500000 0.15000000
## [576,] 0.8589744 0.14102564
## [577,] 0.9444444 0.05555556
## [578,] 0.8148148 0.18518519
## [579,] 0.9672131 0.03278689
## [580,] 0.8500000 0.15000000
## [581,] 0.8076923 0.19230769
## [582,] 0.8260870 0.17391304
## [583,] 0.9375000 0.06250000
## [584,] 0.9047619 0.09523810
## [585,] 0.8888889 0.11111111
## [586,] 0.9375000 0.06250000
## [587,] 0.8571429 0.14285714
## [588,] 0.7272727 0.27272727
## [589,] 0.9259259 0.07407407
## [590,] 0.6842105 0.31578947
## [591,] 0.6842105 0.31578947
## [592,] 0.8947368 0.10526316
## [593,] 0.7307692 0.26923077
## [594,] 0.7272727 0.27272727
## [595,] 0.9600000 0.04000000
## [596,] 0.8888889 0.11111111
## [597,] 0.8064516 0.19354839
## [598,] 1.0000000 0.00000000
## [599,] 0.8500000 0.15000000
## [600,] 0.8285714 0.17142857
## [601,] 0.5789474 0.42105263
## [602,] 0.8888889 0.11111111
## [603,] 0.8750000 0.12500000
## [604,] 0.7272727 0.27272727
## [605,] 0.6666667 0.33333333
## [606,] 0.8666667 0.13333333
## [607,] 1.0000000 0.00000000
## [608,] 0.9047619 0.09523810
## [609,] 0.9259259 0.07407407
## [610,] 0.6666667 0.33333333
## [611,] 0.9672131 0.03278689
## [612,] 0.9672131 0.03278689
## [613,] 0.8636364 0.13636364
## [614,] 0.5789474 0.42105263
## [615,] 0.8095238 0.19047619
## [616,] 0.9375000 0.06250000
## [617,] 0.9259259 0.07407407
## [618,] 0.8888889 0.11111111
## [619,] 0.8750000 0.12500000
## [620,] 0.5789474 0.42105263
## [621,] 0.5789474 0.42105263
## [622,] 1.0000000 0.00000000
## [623,] 0.7272727 0.27272727
## [624,] 0.8750000 0.12500000
## [625,] 0.9259259 0.07407407
## [626,] 0.7307692 0.26923077
## [627,] 0.8750000 0.12500000
## [628,] 0.8571429 0.14285714
## [629,] 0.9444444 0.05555556
## [630,] 0.8750000 0.12500000
## [631,] 0.8695652 0.13043478
## [632,] 0.8666667 0.13333333
## [633,] 0.9545455 0.04545455
## [634,] 0.8076923 0.19230769
## [635,] 0.8095238 0.19047619
## [636,] 0.6666667 0.33333333
## [637,] 0.8888889 0.11111111
## [638,] 0.8750000 0.12500000
## [639,] 0.8285714 0.17142857
## [640,] 0.7307692 0.26923077
## [641,] 0.5789474 0.42105263
## [642,] 0.9375000 0.06250000
## [643,] 0.9411765 0.05882353
## [644,] 0.7307692 0.26923077
## [645,] 0.7307692 0.26923077
## [646,] 0.8571429 0.14285714
## [647,] 0.5454545 0.45454545
## [648,] 0.6666667 0.33333333
## [649,] 0.8947368 0.10526316
## [650,] 0.7272727 0.27272727
## [651,] 0.6666667 0.33333333
## [652,] 0.8648649 0.13513514
## [653,] 1.0000000 0.00000000
## [654,] 0.8571429 0.14285714
## [655,] 0.6842105 0.31578947
## [656,] 0.8750000 0.12500000
## [657,] 0.8064516 0.19354839
## [658,] 0.8666667 0.13333333
## [659,] 0.9047619 0.09523810
## [660,] 0.8500000 0.15000000
## [661,] 0.9672131 0.03278689
## [662,] 0.9444444 0.05555556
## [663,] 0.8461538 0.15384615
## [664,] 0.6666667 0.33333333
## [665,] 0.9672131 0.03278689
## [666,] 0.9672131 0.03278689
## [667,] 0.8461538 0.15384615
## [668,] 0.9259259 0.07407407
## [669,] 0.9672131 0.03278689
## [670,] 0.8823529 0.11764706
## [671,] 0.8064516 0.19354839
## [672,] 0.8500000 0.15000000
## [673,] 0.8750000 0.12500000
## [674,] 0.7272727 0.27272727
## [675,] 0.7307692 0.26923077
## [676,] 0.8500000 0.15000000
## [677,] 0.9672131 0.03278689
## [678,] 0.9672131 0.03278689
## [679,] 0.9047619 0.09523810
## [680,] 0.8636364 0.13636364
## [681,] 0.8750000 0.12500000
## [682,] 0.9259259 0.07407407
## [683,] 0.9672131 0.03278689
## [684,] 0.8571429 0.14285714
## [685,] 0.7307692 0.26923077
## [686,] 0.8461538 0.15384615
## [687,] 0.8750000 0.12500000
## [688,] 0.8076923 0.19230769
## [689,] 0.5789474 0.42105263
## [690,] 0.8636364 0.13636364
## [691,] 0.9672131 0.03278689
## [692,] 0.8095238 0.19047619
## [693,] 0.8888889 0.11111111
## [694,] 0.6666667 0.33333333
## [695,] 0.8500000 0.15000000
## [696,] 0.6666667 0.33333333
## [697,] 0.8888889 0.11111111
## [698,] 0.8947368 0.10526316
## [699,] 0.5454545 0.45454545
## [700,] 0.8125000 0.18750000
## [701,] 0.5789474 0.42105263
## [702,] 0.8500000 0.15000000
## [703,] 0.8064516 0.19354839
## [704,] 0.8285714 0.17142857
## [705,] 0.8076923 0.19230769
## [706,] 0.8947368 0.10526316
## [707,] 0.8888889 0.11111111
## [708,] 0.9259259 0.07407407
## [709,] 0.7307692 0.26923077
## [710,] 0.9411765 0.05882353
## [711,] 0.8750000 0.12500000
## [712,] 0.8666667 0.13333333
## [713,] 0.8214286 0.17857143
## [714,] 0.8064516 0.19354839
## [715,] 0.8095238 0.19047619
## [716,] 0.5789474 0.42105263
## [717,] 0.9672131 0.03278689
## [718,] 0.9672131 0.03278689
## [719,] 0.8648649 0.13513514
## [720,] 0.8095238 0.19047619
## [721,] 0.8095238 0.19047619
## [722,] 0.8888889 0.11111111
## [723,] 0.7272727 0.27272727
## [724,] 0.8571429 0.14285714
## [725,] 0.9259259 0.07407407
## [726,] 0.8750000 0.12500000
## [727,] 0.7272727 0.27272727
## [728,] 0.7307692 0.26923077
## [729,] 0.5789474 0.42105263
## [730,] 0.6666667 0.33333333
## [731,] 0.7906977 0.20930233
## [732,] 0.8648649 0.13513514
## [733,] 0.5789474 0.42105263
## [734,] 0.8500000 0.15000000
## [735,] 0.5789474 0.42105263
## [736,] 0.8888889 0.11111111
## [737,] 1.0000000 0.00000000
## [738,] 0.8648649 0.13513514
## [739,] 0.8750000 0.12500000
## [740,] 0.8888889 0.11111111
## [741,] 0.8500000 0.15000000
## [742,] 0.8095238 0.19047619
## [743,] 0.9672131 0.03278689
## [744,] 0.6666667 0.33333333
## [745,] 0.8500000 0.15000000
## [746,] 0.6666667 0.33333333
## [747,] 0.6842105 0.31578947
## [748,] 0.8888889 0.11111111
## [749,] 0.8285714 0.17142857
## [750,] 0.6842105 0.31578947
## [751,] 0.6666667 0.33333333
## [752,] 0.6666667 0.33333333
## [753,] 0.8666667 0.13333333
## [754,] 0.8666667 0.13333333
## [755,] 0.8064516 0.19354839
## [756,] 0.8641975 0.13580247
## [757,] 0.9672131 0.03278689
## [758,] 1.0000000 0.00000000
## [759,] 0.8076923 0.19230769
## [760,] 0.8500000 0.15000000
## [761,] 0.6666667 0.33333333
## [762,] 0.8666667 0.13333333
## [763,] 0.9545455 0.04545455
## [764,] 0.9545455 0.04545455
## [765,] 0.6842105 0.31578947
## [766,] 0.9672131 0.03278689
## [767,] 0.7272727 0.27272727
## [768,] 1.0000000 0.00000000
## [769,] 0.8648649 0.13513514
## [770,] 0.9375000 0.06250000
## [771,] 0.8888889 0.11111111
## [772,] 0.8750000 0.12500000
## [773,] 1.0000000 0.00000000
## [774,] 0.6666667 0.33333333
## [775,] 0.8750000 0.12500000
## [776,] 0.6666667 0.33333333
## [777,] 0.8285714 0.17142857
## [778,] 0.5789474 0.42105263
## [779,] 0.8076923 0.19230769
## [780,] 0.6842105 0.31578947
## [781,] 0.6842105 0.31578947
## [782,] 1.0000000 0.00000000
## [783,] 0.8076923 0.19230769
## [784,] 0.9672131 0.03278689
## [785,] 0.7906977 0.20930233
## [786,] 0.8750000 0.12500000
## [787,] 0.8571429 0.14285714
## [788,] 0.9176471 0.08235294
## [789,] 0.9333333 0.06666667
## [790,] 0.6666667 0.33333333
## [791,] 0.9672131 0.03278689
## [792,] 0.8641975 0.13580247
## [793,] 0.8095238 0.19047619
## [794,] 0.9047619 0.09523810
## [795,] 0.8589744 0.14102564
## [796,] 0.7272727 0.27272727
## [797,] 1.0000000 0.00000000
## [798,] 0.5789474 0.42105263
## [799,] 0.5789474 0.42105263
## [800,] 0.8648649 0.13513514
## [801,] 0.9672131 0.03278689
## [802,] 0.9672131 0.03278689
## [803,] 1.0000000 0.00000000
## [804,] 0.8750000 0.12500000
## [805,] 0.8571429 0.14285714
## [806,] 0.8571429 0.14285714
## [807,] 0.8500000 0.15000000
## [808,] 0.6666667 0.33333333
## [809,] 0.7272727 0.27272727
## [810,] 0.8285714 0.17142857
## [811,] 0.8648649 0.13513514
## [812,] 0.8076923 0.19230769
## [813,] 0.8750000 0.12500000
## [814,] 0.9333333 0.06666667
## [815,] 0.6666667 0.33333333
## [816,] 0.9545455 0.04545455
## [817,] 0.8648649 0.13513514
## [818,] 0.8666667 0.13333333
## [819,] 0.8285714 0.17142857
## [820,] 0.8500000 0.15000000
## [821,] 0.8285714 0.17142857
## [822,] 0.9672131 0.03278689
## [823,] 0.9047619 0.09523810
## [824,] 0.6666667 0.33333333
## [825,] 0.8589744 0.14102564
## [826,] 0.8823529 0.11764706
## [827,] 0.8095238 0.19047619
## [828,] 0.7906977 0.20930233
## [829,] 0.8641975 0.13580247
## [830,] 0.8823529 0.11764706
## [831,] 0.8888889 0.11111111
## [832,] 0.5454545 0.45454545
## [833,] 0.8285714 0.17142857
## [834,] 0.5789474 0.42105263
## [835,] 0.9333333 0.06666667
## [836,] 0.8750000 0.12500000
## [837,] 0.9259259 0.07407407
## [838,] 0.9672131 0.03278689
## [839,] 1.0000000 0.00000000
## [840,] 1.0000000 0.00000000
## [841,] 0.5454545 0.45454545
## [842,] 0.8095238 0.19047619
## [843,] 0.9411765 0.05882353
## [844,] 0.8095238 0.19047619
## [845,] 0.8500000 0.15000000
## [846,] 0.9672131 0.03278689
## [847,] 0.5789474 0.42105263
## [848,] 1.0000000 0.00000000
## [849,] 0.9047619 0.09523810
## [850,] 0.9259259 0.07407407
## [851,] 0.7906977 0.20930233
## [852,] 0.7272727 0.27272727
## [853,] 0.9672131 0.03278689
## [854,] 0.8888889 0.11111111
## [855,] 0.7906977 0.20930233
## [856,] 0.5789474 0.42105263
## [857,] 0.9259259 0.07407407
## [858,] 0.8095238 0.19047619
## [859,] 0.8076923 0.19230769
## [860,] 0.8095238 0.19047619
## [861,] 0.9259259 0.07407407
## [862,] 0.9444444 0.05555556
## [863,] 0.8888889 0.11111111
## [864,] 1.0000000 0.00000000
## [865,] 0.8095238 0.19047619
## [866,] 0.8461538 0.15384615
## [867,] 0.7906977 0.20930233
## [868,] 0.9176471 0.08235294
## [869,] 0.8076923 0.19230769
## [870,] 0.9672131 0.03278689
data$OverTime
##   [1] "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "Yes" "Yes" "No"  "No"  "No" 
##  [13] "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "Yes" "No" 
##  [25] "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "No"  "Yes" "No"  "No"  "No" 
##  [37] "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes"
##  [49] "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "Yes" "Yes" "Yes"
##  [61] "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No" 
##  [73] "Yes" "Yes" "Yes" "No"  "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "Yes"
##  [85] "Yes" "Yes" "No"  "Yes" "No"  "No"  "Yes" "No"  "Yes" "Yes" "No"  "No" 
##  [97] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes"
## [109] "No"  "No"  "Yes" "No"  "No"  "No"  "Yes" "Yes" "No"  "Yes" "No"  "No" 
## [121] "No"  "Yes" "Yes" "No"  "No"  "Yes" "Yes" "No"  "Yes" "No"  "Yes" "No" 
## [133] "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "Yes" "No"  "No"  "No" 
## [145] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes"
## [157] "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "No" 
## [169] "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "Yes" "Yes" "No"  "No" 
## [181] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [193] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "Yes"
## [205] "No"  "Yes" "No"  "Yes" "No"  "Yes" "No"  "No"  "No"  "Yes" "No"  "No" 
## [217] "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes"
## [229] "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "No"  "No" 
## [241] "Yes" "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "Yes" "No"  "No"  "No" 
## [253] "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "Yes" "No" 
## [265] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [277] "No"  "No"  "Yes" "Yes" "Yes" "Yes" "No"  "No"  "No"  "Yes" "Yes" "No" 
## [289] "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "Yes" "No"  "Yes" "Yes" "Yes"
## [301] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "No" 
## [313] "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "Yes" "No"  "No"  "No"  "Yes"
## [325] "No"  "No"  "Yes" "Yes" "Yes" "No"  "No"  "No"  "Yes" "No"  "No"  "No" 
## [337] "No"  "No"  "Yes" "No"  "Yes" "Yes" "No"  "No"  "No"  "No"  "No"  "No" 
## [349] "No"  "No"  "No"  "No"  "Yes" "Yes" "Yes" "No"  "No"  "No"  "Yes" "No" 
## [361] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [373] "No"  "No"  "No"  "Yes" "No"  "Yes" "Yes" "Yes" "No"  "No"  "No"  "No" 
## [385] "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "Yes" "No"  "Yes" "Yes"
## [397] "No"  "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "No" 
## [409] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [421] "No"  "Yes" "Yes" "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No" 
## [433] "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "No"  "Yes"
## [445] "Yes" "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "No"  "No" 
## [457] "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "Yes" "Yes" "No" 
## [469] "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "Yes"
## [481] "No"  "Yes" "Yes" "Yes" "No"  "Yes" "No"  "No"  "Yes" "No"  "Yes" "Yes"
## [493] "No"  "No"  "Yes" "No"  "No"  "Yes" "No"  "No"  "Yes" "Yes" "Yes" "No" 
## [505] "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "No" 
## [517] "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "No"  "Yes" "Yes"
## [529] "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "Yes" "No" 
## [541] "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [553] "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "No"  "No"  "Yes" "No"  "No" 
## [565] "No"  "Yes" "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "No"  "No"  "No" 
## [577] "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "Yes" "Yes" "Yes" "Yes" "No" 
## [589] "No"  "Yes" "Yes" "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "Yes"
## [601] "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "No"  "Yes"
## [613] "No"  "Yes" "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "Yes" "No"  "Yes"
## [625] "No"  "No"  "Yes" "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "No" 
## [637] "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "No"  "No" 
## [649] "No"  "Yes" "No"  "Yes" "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "No" 
## [661] "No"  "No"  "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No" 
## [673] "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes"
## [685] "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No"  "Yes"
## [697] "No"  "No"  "Yes" "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "No"  "No" 
## [709] "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No" 
## [721] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "Yes"
## [733] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [745] "Yes" "No"  "Yes" "No"  "No"  "No"  "Yes" "Yes" "Yes" "No"  "No"  "No" 
## [757] "Yes" "No"  "No"  "Yes" "Yes" "Yes" "No"  "No"  "No"  "Yes" "No"  "No" 
## [769] "No"  "No"  "No"  "No"  "No"  "Yes" "Yes" "No"  "No"  "No"  "No"  "Yes"
## [781] "Yes" "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No" 
## [793] "Yes" "No"  "Yes" "Yes" "Yes" "Yes" "Yes" "No"  "No"  "Yes" "Yes" "Yes"
## [805] "No"  "Yes" "No"  "No"  "No"  "Yes" "No"  "No"  "Yes" "No"  "No"  "No" 
## [817] "Yes" "No"  "No"  "Yes" "No"  "No"  "No"  "No"  "Yes" "No"  "No"  "Yes"
## [829] "No"  "No"  "Yes" "Yes" "No"  "No"  "Yes" "No"  "Yes" "No"  "Yes" "No" 
## [841] "No"  "No"  "No"  "No"  "No"  "No"  "No"  "No"  "Yes" "No"  "Yes" "No" 
## [853] "Yes" "No"  "Yes" "No"  "Yes" "No"  "No"  "No"  "No"  "No"  "Yes" "Yes"
## [865] "Yes" "No"  "No"  "Yes" "Yes" "No"
# Assuming 'data' is your dataframe
data$OverTime <- as.factor(data$OverTime)  # Convert to factor if it's not
data$JobRole <- as.factor(data$JobRole)  # Convert to factor if it's not
data$MaritalStatus <- as.factor(data$MaritalStatus)  # Convert to factor if it's not

# Building the model
model <- lm(MonthlyIncome ~ OverTime + JobRole + MaritalStatus, data = data)

# Summary of the model to see coefficients and statistics
summary(model)
## 
## Call:
## lm(formula = MonthlyIncome ~ OverTime + JobRole + MaritalStatus, 
##     data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5603.6 -1185.5  -422.4  1150.1  6846.8 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                    7395.68     267.57  27.640   <2e-16 ***
## OverTimeYes                      70.09     151.91   0.461    0.645    
## JobRoleHuman Resources        -4145.07     451.47  -9.181   <2e-16 ***
## JobRoleLaboratory Technician  -4207.64     283.22 -14.856   <2e-16 ***
## JobRoleManager                 9764.88     365.14  26.743   <2e-16 ***
## JobRoleManufacturing Director    71.73     316.35   0.227    0.821    
## JobRoleResearch Director       8311.58     364.73  22.788   <2e-16 ***
## JobRoleResearch Scientist     -4180.24     277.96 -15.039   <2e-16 ***
## JobRoleSales Executive         -542.60     271.56  -1.998    0.046 *  
## JobRoleSales Representative   -4783.88     362.22 -13.207   <2e-16 ***
## MaritalStatusMarried             35.24     177.01   0.199    0.842    
## MaritalStatusSingle               6.65     192.45   0.035    0.972    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2014 on 858 degrees of freedom
## Multiple R-squared:  0.8105, Adjusted R-squared:  0.8081 
## F-statistic: 333.7 on 11 and 858 DF,  p-value: < 2.2e-16

# Conclusion

Given the results of the t-test determined variables, the results were still disappointing. With hours of work put into researching models, and each of these models being no-good, there were no leads towards a better method, the deadline came and went without a good solution. This is not how I wanted this project to come out, nor how I imagined it would come out. This took hours upon hours, and even one all-nighter attempting to find a better way, but in the end, I was unable to do so.