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.
# Fix the known misspelling so code can use average_monthly_hours safely
if ("average_montly_hours" %in% names(hr)) {
hr <- hr |> dplyr::rename(average_monthly_hours = average_montly_hours)
}
##Test One- One Sample T-test (Satisfaction vs .60) ## Question: Is tthe average satisfaction level different from 0.60?
t1 <- t.test(hr$satisfaction_level, mu = 0.60)
t1
##
## One Sample t-test
##
## data: hr$satisfaction_level
## t = 6.3215, df = 14998, p-value = 2.663e-10
## alternative hypothesis: true mean is not equal to 0.6
## 95 percent confidence interval:
## 0.6088542 0.6168128
## sample estimates:
## mean of x
## 0.6128335
ggplot(hr, aes(x = satisfaction_level)) +
geom_histogram(bins = 30) +
labs(title = "Distribution of Satisfaction Level", x = "Satisfaction (0–1)", y = "Count")
group_lh <- hr %>% filter(salary %in% c("low", "high")) %>% droplevels()
t2 <- t.test(satisfaction_level ~ salary, data = group_lh)
t2
##
## Welch Two Sample t-test
##
## data: satisfaction_level by salary
## t = 5.1698, df = 1805, p-value = 2.603e-07
## alternative hypothesis: true difference in means between group high and group low is not equal to 0
## 95 percent confidence interval:
## 0.02278737 0.05064571
## sample estimates:
## mean in group high mean in group low
## 0.6374697 0.6007531
ggplot(group_lh, aes(x = salary, y = satisfaction_level)) +
geom_boxplot() +
labs(title = "Satisfaction by Salary Group (Low vs High)",
x = "Salary", y = "Satisfaction")
t3 <- t.test(last_evaluation ~ as.factor(Work_accident), data = hr)
t3
##
## Welch Two Sample t-test
##
## data: last_evaluation by as.factor(Work_accident)
## t = 0.889, df = 3000.5, p-value = 0.3741
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
## -0.004168157 0.011082974
## sample estimates:
## mean in group 0 mean in group 1
## 0.7166017 0.7131443
ggplot(hr, aes(x = as.factor(Work_accident), y = last_evaluation)) +
geom_boxplot() +
labs(title = "Last Evaluation by Work Accident",
x = "Work Accident (0=No, 1=Yes)", y = "Last Evaluation")
t4 <- t.test(average_monthly_hours ~ as.factor(promotion_last_5years), data = hr)
t4
##
## Welch Two Sample t-test
##
## data: average_monthly_hours by as.factor(promotion_last_5years)
## t = 0.44937, df = 333.03, p-value = 0.6535
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
## -4.143788 6.597589
## sample estimates:
## mean in group 0 mean in group 1
## 201.0764 199.8495
ggplot(hr, aes(x = as.factor(promotion_last_5years), y = average_monthly_hours)) +
geom_boxplot() +
labs(title = "Average_Monthly_Hours by Promotion (Last 5 Years)",
x = "Promoted (0=No, 1=Yes)", y = "Average_Monthly_Hours")