library(readr)
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggplot2)

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.

1. Perform the correlation (.5 point) Choose any two appropriate variables from the data and perform the correlation, displaying the results.

cor.test(hr$average_montly_hours, hr$satisfaction_level)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$average_montly_hours and hr$satisfaction_level
## 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
p-value interpretation: The p value is 0.01408. The results show that the relationship is statistically significant.
correlation estimate interpretation: The correlation is negative and small.
non-technical interpretation: The more hours employees work, there is a slight decrease in satisfaction levels.
ggplot(hr, aes(x = average_montly_hours, y = satisfaction_level)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Scatter Plot: Average Monthly Hours  vs Satisfaction Level",
       x = "Average Monthly Hours",
       y = "Satisfaction Level") 
## `geom_smooth()` using formula = 'y ~ x'

2. Perform the correlation (.5 point) Choose any two appropriate variables from the data and perform the correlation, displaying the results.

 cor.test(hr$time_spend_company, hr$satisfaction_level)
## 
##  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
p-value interpretation: The p value is 2.2e-16. The results show that the relationship is statistically significant.
correlation estimate interpretation: The correlation is negative and small.
non-technical interpretation: The more time spent at the company, satisfaction tends to decrease
ggplot(hr, aes(x = time_spend_company, y = satisfaction_level)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Scatter Plot: Time Spend at Company  vs Satisfaction Level",
       x = "Time Spend at Company",
       y = "Satisfaction Level") 
## `geom_smooth()` using formula = 'y ~ x'

3. Perform the correlation (.5 point) Choose any two appropriate variables from the data and perform the correlation, displaying the results.

cor.test(hr$number_project, hr$satisfaction_level)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$number_project and hr$satisfaction_level
## t = -17.69, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1586105 -0.1272570
## sample estimates:
##        cor 
## -0.1429696
p-value interpretation: The p value is 2.2e-16. The results show that the relationship is statistically significant.
correlation estimate interpretation: The correlation is negative and small.
non-technical interpretation: As employees work on more projects, their satisfaction level tends to decrease
ggplot(hr, aes(x = number_project, y = satisfaction_level)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Scatter Plot: Number of Projects  vs Satisfaction Level",
       x = "Number of Projects",
       y = "Satisfaction Level") 
## `geom_smooth()` using formula = 'y ~ x'

4. Perform the correlation (.5 point) Choose any two appropriate variables from the data and perform the correlation, displaying the results.

cor.test(hr$Work_accident, hr$satisfaction_level)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$Work_accident and hr$satisfaction_level
## t = 7.2006, df = 14997, p-value = 6.279e-13
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.04273358 0.07463094
## sample estimates:
##        cor 
## 0.05869724
p-value interpretation: The p value is 6.279e-13. The results show that the relationship is statistically significant.
correlation estimate interpretation: The correlation is positive and small.
non-technical interpretation: Employees who have had a work accident tend to report slightly higher satisfaction.
ggplot(hr, aes(x = Work_accident, y = satisfaction_level)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Scatter Plot: Work Accidents vs Satisfaction Level",
       x = "Work Accidents",
       y = "Satisfaction Level")
## `geom_smooth()` using formula = 'y ~ x'