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(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.

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

cor_test <- cor.test(hr$satisfaction_level, hr$average_montly_hours)
cor_test
## 
##  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

Interpret the results in technical terms (.5 point) For each correlation, explain what the test’s p-value means (significance).

The Correlation Coefficient is -0.020, nearly zero. There is practically no relationship between satisfaction_level and average_montly_hours because the p-value is nearly zero so there is a small negative correlation.

Interpret the results in non-technical terms (1 point) For each correlation, what do the results mean in non-techical terms.

There is no impact from the employees working more hours and their satisfaction levels.

Create a plot that helps visualize the correlation (.5 point) For each correlation, create a graph to help visualize the realtionship between the two variables. The title must be the non-technical interpretation.

ggplot(hr, aes(x = average_montly_hours, y = satisfaction_level)) +
  geom_point(alpha = 0.5) +
  geom_smooth(method = "lm", color = "blue") +
  labs(
    title = "No Association Between Satisfaction Level and Average Monthly Hours Worked",
    x= "Average Monthly Hours Worked",
    y = "Satisfaction Level"
  )
## `geom_smooth()` using formula = 'y ~ x'

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

cor_test_time_spent <- cor.test(hr$average_montly_hours, hr$time_spend_company)
cor_test_time_spent
## 
##  Pearson's product-moment correlation
## 
## data:  hr$average_montly_hours and hr$time_spend_company
## t = 15.774, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1119801 0.1434654
## sample estimates:
##       cor 
## 0.1277549

Interpret the results in technical terms (.5 point) For each correlation, explain what the test’s p-value means (significance).

The Correlation Coefficient is 0.1277, nearly zero. There is practically no relationship between time spent at the company and average_montly_hours because the p-value is nearly zero so ther is a small positive correlation.

Interpret the results in non-technical terms (1 point) For each correlation, what do the results mean in non-techical terms.

The average monthly hours worked is not influenced by the time spent at the company.

Create a plot that helps visualize the correlation (.5 point) For each correlation, create a graph to help visualize the realtionship between the two variables. The title must be the non-technical interpretation.

ggplot(hr, aes(x = average_montly_hours, y = time_spend_company)) +
  geom_point(alpha = 0.5) +  # Scatter plot points
  geom_smooth(method = "lm", color = "blue") +  # Linear regression line
  labs(
    title = "There is no clear relationship between time spent working and time spent at the company",
    x = "Average Monthly Hours Worked",
    y = "Time Spent at the Company (Years)"
  )
## `geom_smooth()` using formula = 'y ~ x'

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

cor_test_time_spent <- cor.test(hr$satisfaction_level, hr$last_evaluation)
cor_test_time_spent
## 
##  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 results in technical terms (.5 point) For each correlation, explain what the test’s p-value means (significance).

The correlation coefficient is .1050, there is a small positive correlation between satisfaction level and last evaluation.

Interpret the results in non-technical terms (1 point) For each correlation, what do the results mean in non-techical terms.

There is a small association between satisfaction level and last evaluation, last evaluations hardly impact satisfaction levels.

Create a plot that helps visualize the correlation (.5 point) For each correlation, create a graph to help visualize the relationship between the two variables. The title must be the non-technical interpretation.

ggplot(hr, aes(x = satisfaction_level, y = last_evaluation)) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  geom_smooth(method = "lm", color = "blue") +
  labs(title = "Weak positive correlation between Satisfaction and Last Evaluation",
       x = "Satisfaction Level",
       y = "Last Evaluation") 
## `geom_smooth()` using formula = 'y ~ x'

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

cor_test_time_spent <- cor.test(hr$average_montly_hours, hr$last_evaluation)
cor_test_time_spent
## 
##  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

Interpret the results in technical terms (.5 point) For each correlation, explain what the test’s p-value means (significance).

The correlation coefficient is .3397, there is a moderate postitive correlation between average monthly hours and last evaluation.

Interpret the results in non-technical terms (1 point) For each correlation, what do the results mean in non-techical terms.

Average monthly hours have a moderate impact on the employees last evaluation.

Create a plot that helps visualize the correlation (.5 point) For each correlation, create a graph to help visualize the realtionship between the two variables. The title must be the non-technical interpretation.

ggplot(hr, aes(x = last_evaluation, y = average_montly_hours)) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  geom_smooth(method = "lm", color = "blue") +
  labs(title = "Relationship between Last Evaluation and Average Monthly Hours",
       x = "Last Evaluation",
       y = "Average Monthly Hours") 
## `geom_smooth()` using formula = 'y ~ x'