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
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.
q1 <-cor.test(hr$satisfaction_level , hr$average_montly_hours)
q1
##
## 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
fig1 <- plot_ly(
data = hr,
x = ~average_montly_hours,
y = ~satisfaction_level,
type = "scatter",
mode = "markers",
marker = list(color = 'steelblue', opacity = 0.4)
) %>%
layout(
title = "Employees who work more hours per month tend to be less satisfied",
xaxis = list(title = "Average Monthly Hours"),
yaxis = list(title = "Satisfaction Level")
)
fig1
p-value interpretation: The p-value is very small, therefore the correlation between satisfaction level and average monthly hours is significant.
correlation estimate interpretation: The correlation is negative and very small.
non-technical interpretation: Employees who work more hours per month tend to be slightly less satisfied, but the effect is very weak.
q2 <-cor.test(hr$time_spend_company , hr$promotion_last_5years)
fig2 <- plot_ly(
hr,
x = ~factor(promotion_last_5years),
y = ~time_spend_company,
type = 'box'
) %>%
layout(
title = "Employees who have spent more time at the company are get promoted",
xaxis = list(title = "Promotion in Last 5 Years (0=No,1=Yes)"),
yaxis = list(title = "Time Spent in Company (Years)")
)
fig2
p-value interpretation: The p-value is very small, therefore the correlation between time spent at company and promotion is significant. correlation estimate interpretation: The correlation is positive and small.
non-technical interpretation: Employees who have spent more time at the company are somewhat more likely to get promoted
q3 <-cor.test(hr$number_project , hr$time_spend_company)
fig3 <- plot_ly(
data = hr,
x = ~time_spend_company,
y = ~number_project,
type = "scatter",
mode = "markers",
marker = list(color = 'darkgreen', opacity = 0.4)
) %>%
add_lines(
x = ~time_spend_company,
y = fitted(lm(number_project ~ time_spend_company, data = hr)),
line = list(color = 'red', width = 2),
name = "Trend line"
) %>%
layout(
title = "Employees who have spent more time at the company have done more projects",
xaxis = list(title = "Time Spent in Company (Years)"),
yaxis = list(title = "Number of Projects")
)
fig3
## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...
p-value interpretation: The p-value is very small, therefore the correlation between number of projects and time spent at the company.
correlation estimate interpretation: The correlation is positive and small.
non-technical interpretation: Employees who have spent more time at the company have done more projects
cor.test(hr$time_spend_company , hr$promotion_last_5years)
##
## Pearson's product-moment correlation
##
## data: hr$time_spend_company and hr$promotion_last_5years
## t = 8.2768, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.05148468 0.08334679
## sample estimates:
## cor
## 0.06743293
fig4 <- plot_ly(
hr,
x = ~salary,
y = ~satisfaction_level,
type = 'box'
) %>%
layout(
title = "Employees with higher salaries tend to be slightly more satisfied",
xaxis = list(title = "Salary Level"),
yaxis = list(title = "Satisfaction Level")
)
fig4
p-value interpretation: The p-value is very small, therefore the correlation between salary and satisfaction level is significant.
correlation estimate interpretation: The correlation is positive and small.
non-technical interpretation: Employees with higher salaries tend to be slighlty more satisfied