library(readr)

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.
### Correlation 1


library(ggplot2)


cor_test_result <- cor.test(hr$satisfaction_level, hr$average_montly_hours)
cor_test_result
## 
##  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_jitter(alpha = 0.3, width = 0.5, height = 0.02) +
  geom_smooth(method = "lm", se = FALSE, color = "red") +
  labs(title = "Higher Satisfaction Levels Associated with Fewer Monthly Hours",
       x = "Average Monthly Hours",
       y = "Satisfaction Level")
## `geom_smooth()` using formula = 'y ~ x'

# Technical interpretation: The correlation coefficient is -0.02, indicating no meaningful relationship. 
# The p-value (0.8148) is high, meaning the correlation is not statistically significant.

# Non-technical interpretation: Satisfaction level and monthly hours are not meaningfully related in this data.
### Correlation 2

cor_test_1 <- cor.test(hr$satisfaction_level, hr$last_evaluation)
cor_test_1
## 
##  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
ggplot(hr, aes(x = last_evaluation, y = satisfaction_level)) +
  geom_jitter(alpha = 0.3, width = 0.02, height = 0.02) +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Higher Satisfaction Levels May Relate to Last Evaluation Scores",
       x = "Last Evaluation Score",
       y = "Satisfaction Level")
## `geom_smooth()` using formula = 'y ~ x'

# Technical interpretation: The correlation between satisfaction level and last evaluation is calculated.
# The p-value indicates whether this correlation is statistically significant.

# Non-technical interpretation: Higher satisfaction levels may relate to better last evaluation scores, 
# suggesting a possible link between employee satisfaction and performance evaluation.
### Correlation 3

cor_test_3 <- cor.test(hr$last_evaluation, hr$average_montly_hours)
cor_test_3
## 
##  Pearson's product-moment correlation
## 
## data:  hr$last_evaluation and hr$average_montly_hours
## 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_jitter(alpha = 0.2, width = 0.2, height = 0.02, size = 0.8) +
  geom_smooth(method = "lm", se = FALSE, color = "purple") +
  labs(title = "Higher Last Evaluation Scores May Relate to More Monthly Hours",
       x = "Average Monthly Hours",
       y = "Last Evaluation Score") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Technical interpretation: The correlation between last evaluation and average monthly hours is calculated.
# The p-value indicates whether this correlation is statistically significant.

# Non-technical interpretation: Higher last evaluation scores may relate to employees working more monthly hours, 
# suggesting a possible link between evaluation scores and work hours.
### Correlation 4

cor_test_4 <- cor.test(hr$average_montly_hours, hr$number_project)
cor_test_4
## 
##  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
ggplot(hr, aes(x = average_montly_hours, y = number_project)) +
  geom_jitter(alpha = 0.2, width = 0.2, height = 0.2, size = 0.8) +
  geom_smooth(method = "lm", se = FALSE, color = "orange") +
  labs(title = "More Monthly Hours May Relate to More Projects",
       x = "Average Monthly Hours",
       y = "Number of Projects") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Technical interpretation: The correlation between average monthly hours and number of projects is calculated.
# The p-value indicates whether this correlation is statistically significant.

# Non-technical interpretation: Employees with higher monthly hours may handle more projects, 
# suggesting a potential link between workload and project count.