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

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

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

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

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.
data <- mtcars

head(data)
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
head(data)
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
correlation_result <- cor.test(data$mpg, data$hp)
correlation_result
## 
##  Pearson's product-moment correlation
## 
## data:  data$mpg and data$hp
## t = -6.7424, df = 30, p-value = 1.788e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.8852686 -0.5860994
## sample estimates:
##        cor 
## -0.7761684
library(ggplot2)

ggplot(data, aes(x = hp, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue", se = FALSE) +
  labs(title = "Cars with More Horsepower Tend to Have Lower Fuel Efficiency",
       x = "Horsepower",
       y = "Miles Per Gallon") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

-Correlation is -0.7761684 so it is strongly correlated and the P value is 1.788e-07 which is less than 0.5 making it a significant correlation

-When there is more Horsepower the worse the fuel efficiency is

-The correlation is negative and large

correlation_result <- cor.test(data$cyl, data$hp)
correlation_result
## 
##  Pearson's product-moment correlation
## 
## data:  data$cyl and data$hp
## t = 8.2286, df = 30, p-value = 3.478e-09
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6816016 0.9154223
## sample estimates:
##       cor 
## 0.8324475
ggplot(data, aes(x = hp, y = cyl)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue", se = FALSE) +
  labs(title = "Cars with More Horsepower Tend to Have More Cylinders",
       x = "Horsepower",
       y = "Cylinders") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

-Positive Correlation is strong at 0.8324475 and the P value proves that the correlation is strong as it is lower than the significance level at 3.478e-09

-P value reveals a strong link between the hp and cyl as the graph proves the higher the horse power the more cylinders needed for the car

-The correlation is strong and positive

correlation_result <- cor.test(data$gear, data$mpg)
correlation_result
## 
##  Pearson's product-moment correlation
## 
## data:  data$gear and data$mpg
## t = 2.9992, df = 30, p-value = 0.005401
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1580618 0.7100628
## sample estimates:
##       cor 
## 0.4802848
ggplot(data, aes(x = cyl, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue", se = FALSE) +
  labs(title = "Cars with More Cylinders Tend to Have Lower MPG",
       x = "Cylinders",
       y = "Miles Per Gallon") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

-There is a weak correlation of -0.4802848 the p value is above 0.05 showing week significance at 0.005401.

-The correlation is weak and negative. Cars With More Cylinders Tend To Have Less MPG.

correlation_result <- cor.test(data$wt, data$mpg)
correlation_result
## 
##  Pearson's product-moment correlation
## 
## data:  data$wt and data$mpg
## t = -9.559, df = 30, p-value = 1.294e-10
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.9338264 -0.7440872
## sample estimates:
##        cor 
## -0.8676594
ggplot(data, aes(x = wt, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue", se = FALSE) +
  labs(title = "Cars with A Larger Weight Tend to Have Lower MPG",
       x = "Weight",
       y = "Miles Per Gallon") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

-The correlation is strong at -0.8676594. P Value is well below 0.05 proving the hypothesis significance at 1.294e-10

-The heavier the car the worse the mpg. The correlation is strong and negative.