# Load necessary libraries
library(readr) # For reading CSV data
library(ggplot2) # For visualizations
library(dplyr) # For data manipulation
##
## 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
# Load the employee attrition dataset
hr <- read_csv('https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv')
## Rows: 14999 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Department, salary
## dbl (8): satisfaction_level, last_evaluation, number_project, average_montly...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# View first few rows of the data
head(hr)
## # A tibble: 6 × 10
## satisfaction_level last_evaluation number_project average_montly_hours
## <dbl> <dbl> <dbl> <dbl>
## 1 0.38 0.53 2 157
## 2 0.8 0.86 5 262
## 3 0.11 0.88 7 272
## 4 0.72 0.87 5 223
## 5 0.37 0.52 2 159
## 6 0.41 0.5 2 153
## # ℹ 6 more variables: time_spend_company <dbl>, Work_accident <dbl>,
## # left <dbl>, promotion_last_5years <dbl>, Department <chr>, salary <chr>
# Correlation between Satisfaction Level and Last Evaluation
cor.test(hr$satisfaction_level, hr$last_evaluation)
##
## Pearson's product-moment correlation
##
## data: hr$satisfaction_level and hr$last_evaluation
## t = 12.933, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.08916727 0.12082195
## sample estimates:
## cor
## 0.1050212
# Scatter plot with regression line
ggplot(hr, aes(x = satisfaction_level, y = last_evaluation)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(title = "Higher Satisfaction, Higher Evaluation Scores",
x = "Satisfaction Level",
y = "Last Evaluation Score") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

#Technical Interpretation:
#The p-value is very small (p < 0.05), indicating that the correlation is statistically significant.
#The correlation coefficient (r) is positive, suggesting a weak-to-moderate positive relationship between satisfaction level and last evaluation.
#Non-Technical Interpretation:
#Employees who report higher job satisfaction tend to receive higher performance evaluations, but the relationship is not very strong.
# Correlation between Average Monthly Hours and Last Evaluation
cor.test(hr$average_montly_hours, hr$last_evaluation)
##
## Pearson's product-moment correlation
##
## data: hr$average_montly_hours and hr$last_evaluation
## t = 44.237, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3255078 0.3538218
## sample estimates:
## cor
## 0.3397418
ggplot(hr, aes(x = average_montly_hours, y = last_evaluation)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
labs(title = "More Work Hours, Higher Evaluation Scores",
x = "Average Monthly Hours",
y = "Last Evaluation Score") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

#Technical Interpretation:
#The p-value is small (p < 0.05), indicating statistical significance.
#The correlation coefficient (r) is positive, meaning that as monthly working hours increase, last evaluation scores also tend to increase.
#Non-Technical Interpretation:
#Employees who work more hours per month generally receive higher performance evaluations. This suggests that working longer hours is linked to better evaluations.
# Correlation between Satisfaction Level and Average Monthly Hours
cor.test(hr$satisfaction_level, hr$average_montly_hours)
##
## Pearson's product-moment correlation
##
## data: hr$satisfaction_level and hr$average_montly_hours
## t = -2.4556, df = 14997, p-value = 0.01408
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.036040356 -0.004045605
## sample estimates:
## cor
## -0.02004811
ggplot(hr, aes(x = average_montly_hours, y = satisfaction_level)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "green") +
labs(title = "More Work Hours, Less Satisfaction",
x = "Average Monthly Hours",
y = "Satisfaction Level") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

#Technical Interpretation:
#The p-value is very small (p < 0.05), meaning the correlation is statistically significant.
#The correlation coefficient (r) is negative, indicating that as working hours increase, job satisfaction tends to decrease.
#Non-Technical Interpretation:
#Employees who work more hours per month tend to be less satisfied with their jobs. This suggests that longer working hours may lead to dissatisfaction.
# Correlation between Time Spent at the Company and Number of Projects
cor.test(hr$time_spend_company, hr$number_project)
##
## Pearson's product-moment correlation
##
## data: hr$time_spend_company and hr$number_project
## t = 24.579, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1813532 0.2121217
## sample estimates:
## cor
## 0.1967859
ggplot(hr, aes(x = time_spend_company, y = number_project)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "purple") +
labs(title = "Longer Time at Company, More Projects",
x = "Years at Company",
y = "Number of Projects") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

#Technical Interpretation:
#The p-value is small (p < 0.05), meaning the correlation is statistically significant.
#The correlation coefficient (r) is positive, meaning that as time spent at the company increases, the number of projects assigned also increases.
#Non-Technical Interpretation:
#Employees who have been with the company for a longer period tend to work on more projects. This suggests that more experienced employees are given more responsibilities.