library(readr)
library(ggplot2)
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
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.

1st Correlation: Satisfaction Level vs. Last Evaluation

##Perform Correlation Analysis

cor_test_result <- cor.test(hr$satisfaction_level, hr$last_evaluation)

# Display the correlation result
cor_test_result
## 
##  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

##Interpret the P Value (technical terms) The p-value is extremely small so we reject the null hypothesis, which makes this statistically significant. The correlation coefficient is .105 which shows a weak positive correlation between satisfaction levels and last evaluations.

##Interpret the results in non-technical terms higher job satisfaction may lead to better performance evaluations.

##Create a plot that helps visualize the correlation (.5 point) 
ggplot(hr, aes(x = satisfaction_level, y = last_evaluation)) +
  geom_point(alpha = 0.5, color = "blue") +
  geom_smooth(method = "lm", color = "red") +
  ggtitle("Higher Job Satisfaction May Lead to Better Performance Evaluations") +
  xlab("Satisfaction Level") +
  ylab("Last Evaluation Score")
## `geom_smooth()` using formula = 'y ~ x'

2nd Correlation: Average Monthly Hours vs. Number of Projects

cor_test2 <- cor.test(hr$average_montly_hours, hr$number_project)
cor_test2
## 
##  Pearson's product-moment correlation
## 
## data:  hr$average_montly_hours and hr$number_project
## t = 56.219, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4039037 0.4303411
## sample estimates:
##       cor 
## 0.4172106

##Interpret the P Value (technical terms) The p-value is extremely small so we reject the null hypothesis, which makes this statisically significant. The correlation coefficient is .417 which shows a moderate positive correleation between average monthly hours and the number of projects.

##Interpret the results in non-technical terms The more hours a person works, they more projects they will complete.

##Create a plot that helps visualize the correlation

ggplot(hr, aes(x = average_montly_hours, y = number_project)) +
  geom_point(alpha = 0.5, color = "blue") +
  geom_smooth(method = "lm", color = "red") +
  ggtitle("Working More Hours Leads to More Projects Being Completed") +
  xlab("Average Monthly Hours") +
  ylab("Number of Projects")
## `geom_smooth()` using formula = 'y ~ x'

3rd Correlation: Time Spent at Company vs. Satisfaction Level

cor_test3 <- cor.test(hr$time_spend_company, hr$satisfaction_level)
cor_test3
## 
##  Pearson's product-moment correlation
## 
## data:  hr$time_spend_company and hr$satisfaction_level
## t = -12.416, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.11668153 -0.08499948
## sample estimates:
##        cor 
## -0.1008661

##Interpret the P Value (technical terms) The p-value is extremely small so we reject the null hypothesis, which makes this statisically significant. The correlation coefficient is -.10086 which shows a Weak negative correleation between time spent at the company and the satisfaction levels.

##Interpret the results in non-technical terms Long-term employees might experience burnout or dissatisfaction.

##Create a plot that helps visualize the correlation

ggplot(hr, aes(x = time_spend_company, y = satisfaction_level)) +
  geom_point(alpha = 0.5, color = "blue") +
  geom_smooth(method = "lm", color = "red") +
  ggtitle("Long-term employees might experience burnout or dissatisfaction") +
  xlab("Years at Company") +
  ylab("Satisfaction Level")
## `geom_smooth()` using formula = 'y ~ x'

## 4th Correlation: Last Evaluation vs. Number of Projects

cor_test4 <- cor.test(hr$last_evaluation, hr$number_project)
cor_test4
## 
##  Pearson's product-moment correlation
## 
## data:  hr$last_evaluation and hr$number_project
## t = 45.656, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3352028 0.3633053
## sample estimates:
##       cor 
## 0.3493326

##Interpret the P Value (technical terms) The p-value is extremely small so we reject the null hypothesis, which makes this statisically significant. The correlation coefficient is .3493 which shows a Weak positive correleation between evaluation scores and the number of projects

##Interpret the results in non-technical terms An employee with a higher evaluation score may complete more projects

##Create a plot that helps visualize the correlation

ggplot(hr, aes(x = number_project, y = last_evaluation)) +
  geom_point(alpha = 0.5, color = "blue") +
  geom_smooth(method = "lm", color = "red") +
  ggtitle("An Employee With a Higher Evaluation Score May Complete More Projects") +
  xlab("Number of Projects") +
  ylab("Last Evaluation Score")
## `geom_smooth()` using formula = 'y ~ x'