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.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ purrr 1.1.0
## ✔ forcats 1.0.0 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(gmodels)
## Warning: package 'gmodels' was built under R version 4.5.2
library(plotly)
##
## 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(dplyr)
CrossTable(hr$salary , hr$left , chisq = T)
##
##
## Cell Contents
## |-------------------------|
## | N |
## | Chi-square contribution |
## | N / Row Total |
## | N / Col Total |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 14999
##
##
## | hr$left
## hr$salary | 0 | 1 | Row Total |
## -------------|-----------|-----------|-----------|
## high | 1155 | 82 | 1237 |
## | 47.915 | 153.339 | |
## | 0.934 | 0.066 | 0.082 |
## | 0.101 | 0.023 | |
## | 0.077 | 0.005 | |
## -------------|-----------|-----------|-----------|
## low | 5144 | 2172 | 7316 |
## | 33.200 | 106.247 | |
## | 0.703 | 0.297 | 0.488 |
## | 0.450 | 0.608 | |
## | 0.343 | 0.145 | |
## -------------|-----------|-----------|-----------|
## medium | 5129 | 1317 | 6446 |
## | 9.648 | 30.876 | |
## | 0.796 | 0.204 | 0.430 |
## | 0.449 | 0.369 | |
## | 0.342 | 0.088 | |
## -------------|-----------|-----------|-----------|
## Column Total | 11428 | 3571 | 14999 |
## | 0.762 | 0.238 | |
## -------------|-----------|-----------|-----------|
##
##
## Statistics for All Table Factors
##
##
## Pearson's Chi-squared test
## ------------------------------------------------------------
## Chi^2 = 381.225 d.f. = 2 p = 1.652087e-83
##
##
##
-P<.001 so we must reject the null hypothesis, there must be a association between salary and leaving. -Employees with high salary leave much less with only .066% of leaving -Employees with medium and low salaries are far more likley to leave then employees with high salaries - Low-High (.297/.066)= 4.5 times more likley to leave - Medium high (.204/.066)= 3.1 times more likley to leave
T1 <- hr %>%
mutate(salary = factor(salary, levels = c("low", "medium", "high")))
summary_T1 <- T1 %>%
group_by(salary) %>%
summarise( pct_left = mean(left == 1) * 100)
plot_ly(
data = summary_T1 ,
x = ~salary,
y = ~pct_left ,
type = "bar"
)%>%
layout(
title = "Higher Salary Employees are more likley to stay",
xaxis = list(title = "salary level"),
yaxis = list(title = "Percent Left (%)")
)
CrossTable(hr$satisfaction_level , hr$left , chisq = T)
##
##
## Cell Contents
## |-------------------------|
## | N |
## | Chi-square contribution |
## | N / Row Total |
## | N / Col Total |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 14999
##
##
## | hr$left
## hr$satisfaction_level | 0 | 1 | Row Total |
## ----------------------|-----------|-----------|-----------|
## 0.09 | 0 | 195 | 195 |
## | 148.574 | 475.470 | |
## | 0.000 | 1.000 | 0.013 |
## | 0.000 | 0.055 | |
## | 0.000 | 0.013 | |
## ----------------------|-----------|-----------|-----------|
## 0.1 | 0 | 358 | 358 |
## | 272.766 | 872.914 | |
## | 0.000 | 1.000 | 0.024 |
## | 0.000 | 0.100 | |
## | 0.000 | 0.024 | |
## ----------------------|-----------|-----------|-----------|
## 0.11 | 0 | 335 | 335 |
## | 255.242 | 816.833 | |
## | 0.000 | 1.000 | 0.022 |
## | 0.000 | 0.094 | |
## | 0.000 | 0.022 | |
## ----------------------|-----------|-----------|-----------|
## 0.12 | 26 | 4 | 30 |
## | 0.432 | 1.383 | |
## | 0.867 | 0.133 | 0.002 |
## | 0.002 | 0.001 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.13 | 51 | 3 | 54 |
## | 2.361 | 7.556 | |
## | 0.944 | 0.056 | 0.004 |
## | 0.004 | 0.001 | |
## | 0.003 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.14 | 63 | 10 | 73 |
## | 0.979 | 3.134 | |
## | 0.863 | 0.137 | 0.005 |
## | 0.006 | 0.003 | |
## | 0.004 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.15 | 73 | 3 | 76 |
## | 3.935 | 12.592 | |
## | 0.961 | 0.039 | 0.005 |
## | 0.006 | 0.001 | |
## | 0.005 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.16 | 78 | 1 | 79 |
## | 5.269 | 16.862 | |
## | 0.987 | 0.013 | 0.005 |
## | 0.007 | 0.000 | |
## | 0.005 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.17 | 67 | 5 | 72 |
## | 2.687 | 8.600 | |
## | 0.931 | 0.069 | 0.005 |
## | 0.006 | 0.001 | |
## | 0.004 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.18 | 63 | 0 | 63 |
## | 4.687 | 14.999 | |
## | 1.000 | 0.000 | 0.004 |
## | 0.006 | 0.000 | |
## | 0.004 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.19 | 68 | 6 | 74 |
## | 2.394 | 7.661 | |
## | 0.919 | 0.081 | 0.005 |
## | 0.006 | 0.002 | |
## | 0.005 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.2 | 65 | 4 | 69 |
## | 2.938 | 9.402 | |
## | 0.942 | 0.058 | 0.005 |
## | 0.006 | 0.001 | |
## | 0.004 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.21 | 66 | 1 | 67 |
## | 4.379 | 14.014 | |
## | 0.985 | 0.015 | 0.004 |
## | 0.006 | 0.000 | |
## | 0.004 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.22 | 59 | 1 | 60 |
## | 3.861 | 12.355 | |
## | 0.983 | 0.017 | 0.004 |
## | 0.005 | 0.000 | |
## | 0.004 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.23 | 52 | 2 | 54 |
## | 2.865 | 9.168 | |
## | 0.963 | 0.037 | 0.004 |
## | 0.005 | 0.001 | |
## | 0.003 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.24 | 77 | 3 | 80 |
## | 4.224 | 13.519 | |
## | 0.963 | 0.037 | 0.005 |
## | 0.007 | 0.001 | |
## | 0.005 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.25 | 31 | 3 | 34 |
## | 1.002 | 3.207 | |
## | 0.912 | 0.088 | 0.002 |
## | 0.003 | 0.001 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.26 | 29 | 1 | 30 |
## | 1.651 | 5.282 | |
## | 0.967 | 0.033 | 0.002 |
## | 0.003 | 0.000 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.27 | 24 | 6 | 30 |
## | 0.057 | 0.183 | |
## | 0.800 | 0.200 | 0.002 |
## | 0.002 | 0.002 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.28 | 28 | 3 | 31 |
## | 0.812 | 2.600 | |
## | 0.903 | 0.097 | 0.002 |
## | 0.002 | 0.001 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.29 | 37 | 1 | 38 |
## | 2.237 | 7.158 | |
## | 0.974 | 0.026 | 0.003 |
## | 0.003 | 0.000 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.3 | 37 | 2 | 39 |
## | 1.786 | 5.716 | |
## | 0.949 | 0.051 | 0.003 |
## | 0.003 | 0.001 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.31 | 42 | 17 | 59 |
## | 0.194 | 0.621 | |
## | 0.712 | 0.288 | 0.004 |
## | 0.004 | 0.005 | |
## | 0.003 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.32 | 42 | 8 | 50 |
## | 0.400 | 1.280 | |
## | 0.840 | 0.160 | 0.003 |
## | 0.004 | 0.002 | |
## | 0.003 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.33 | 33 | 3 | 36 |
## | 1.131 | 3.621 | |
## | 0.917 | 0.083 | 0.002 |
## | 0.003 | 0.001 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.34 | 44 | 4 | 48 |
## | 1.509 | 4.828 | |
## | 0.917 | 0.083 | 0.003 |
## | 0.004 | 0.001 | |
## | 0.003 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.35 | 34 | 3 | 37 |
## | 1.197 | 3.831 | |
## | 0.919 | 0.081 | 0.002 |
## | 0.003 | 0.001 | |
## | 0.002 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.36 | 43 | 96 | 139 |
## | 37.365 | 119.577 | |
## | 0.309 | 0.691 | 0.009 |
## | 0.004 | 0.027 | |
## | 0.003 | 0.006 | |
## ----------------------|-----------|-----------|-----------|
## 0.37 | 47 | 194 | 241 |
## | 101.652 | 325.310 | |
## | 0.195 | 0.805 | 0.016 |
## | 0.004 | 0.054 | |
## | 0.003 | 0.013 | |
## ----------------------|-----------|-----------|-----------|
## 0.38 | 35 | 154 | 189 |
## | 82.509 | 264.048 | |
## | 0.185 | 0.815 | 0.013 |
## | 0.003 | 0.043 | |
## | 0.002 | 0.010 | |
## ----------------------|-----------|-----------|-----------|
## 0.39 | 35 | 140 | 175 |
## | 72.523 | 232.090 | |
## | 0.200 | 0.800 | 0.012 |
## | 0.003 | 0.039 | |
## | 0.002 | 0.009 | |
## ----------------------|-----------|-----------|-----------|
## 0.4 | 40 | 169 | 209 |
## | 89.288 | 285.743 | |
## | 0.191 | 0.809 | 0.014 |
## | 0.004 | 0.047 | |
## | 0.003 | 0.011 | |
## ----------------------|-----------|-----------|-----------|
## 0.41 | 39 | 132 | 171 |
## | 63.962 | 204.693 | |
## | 0.228 | 0.772 | 0.011 |
## | 0.003 | 0.037 | |
## | 0.003 | 0.009 | |
## ----------------------|-----------|-----------|-----------|
## 0.42 | 47 | 108 | 155 |
## | 42.802 | 136.976 | |
## | 0.303 | 0.697 | 0.010 |
## | 0.004 | 0.030 | |
## | 0.003 | 0.007 | |
## ----------------------|-----------|-----------|-----------|
## 0.43 | 46 | 178 | 224 |
## | 91.068 | 291.437 | |
## | 0.205 | 0.795 | 0.015 |
## | 0.004 | 0.050 | |
## | 0.003 | 0.012 | |
## ----------------------|-----------|-----------|-----------|
## 0.44 | 58 | 153 | 211 |
## | 65.690 | 210.221 | |
## | 0.275 | 0.725 | 0.014 |
## | 0.005 | 0.043 | |
## | 0.004 | 0.010 | |
## ----------------------|-----------|-----------|-----------|
## 0.45 | 46 | 157 | 203 |
## | 76.350 | 244.337 | |
## | 0.227 | 0.773 | 0.014 |
## | 0.004 | 0.044 | |
## | 0.003 | 0.010 | |
## ----------------------|-----------|-----------|-----------|
## 0.46 | 27 | 68 | 95 |
## | 28.454 | 91.058 | |
## | 0.284 | 0.716 | 0.006 |
## | 0.002 | 0.019 | |
## | 0.002 | 0.005 | |
## ----------------------|-----------|-----------|-----------|
## 0.47 | 38 | 4 | 42 |
## | 1.125 | 3.600 | |
## | 0.905 | 0.095 | 0.003 |
## | 0.003 | 0.001 | |
## | 0.003 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.48 | 139 | 10 | 149 |
## | 5.716 | 18.293 | |
## | 0.933 | 0.067 | 0.010 |
## | 0.012 | 0.003 | |
## | 0.009 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.49 | 207 | 2 | 209 |
## | 14.324 | 45.840 | |
## | 0.990 | 0.010 | 0.014 |
## | 0.018 | 0.001 | |
## | 0.014 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.5 | 226 | 3 | 229 |
## | 15.213 | 48.686 | |
## | 0.987 | 0.013 | 0.015 |
## | 0.020 | 0.001 | |
## | 0.015 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.51 | 182 | 5 | 187 |
## | 10.963 | 35.083 | |
## | 0.973 | 0.027 | 0.012 |
## | 0.016 | 0.001 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.52 | 196 | 0 | 196 |
## | 14.582 | 46.664 | |
## | 1.000 | 0.000 | 0.013 |
## | 0.017 | 0.000 | |
## | 0.013 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.53 | 171 | 8 | 179 |
## | 8.786 | 28.119 | |
## | 0.955 | 0.045 | 0.012 |
## | 0.015 | 0.002 | |
## | 0.011 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.54 | 179 | 6 | 185 |
## | 10.269 | 32.863 | |
## | 0.968 | 0.032 | 0.012 |
## | 0.016 | 0.002 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.55 | 175 | 4 | 179 |
## | 10.934 | 34.992 | |
## | 0.978 | 0.022 | 0.012 |
## | 0.015 | 0.001 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.56 | 182 | 5 | 187 |
## | 10.963 | 35.083 | |
## | 0.973 | 0.027 | 0.012 |
## | 0.016 | 0.001 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.57 | 202 | 8 | 210 |
## | 11.023 | 35.277 | |
## | 0.962 | 0.038 | 0.014 |
## | 0.018 | 0.002 | |
## | 0.013 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.58 | 179 | 3 | 182 |
## | 11.730 | 37.539 | |
## | 0.984 | 0.016 | 0.012 |
## | 0.016 | 0.001 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.59 | 212 | 7 | 219 |
## | 12.212 | 39.080 | |
## | 0.968 | 0.032 | 0.015 |
## | 0.019 | 0.002 | |
## | 0.014 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.6 | 189 | 4 | 193 |
## | 11.967 | 38.298 | |
## | 0.979 | 0.021 | 0.013 |
## | 0.017 | 0.001 | |
## | 0.013 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.61 | 202 | 6 | 208 |
## | 11.952 | 38.248 | |
## | 0.971 | 0.029 | 0.014 |
## | 0.018 | 0.002 | |
## | 0.013 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.62 | 186 | 2 | 188 |
## | 12.764 | 40.849 | |
## | 0.989 | 0.011 | 0.013 |
## | 0.016 | 0.001 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.63 | 205 | 4 | 209 |
## | 13.149 | 42.081 | |
## | 0.981 | 0.019 | 0.014 |
## | 0.018 | 0.001 | |
## | 0.014 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.64 | 185 | 2 | 187 |
## | 12.690 | 40.611 | |
## | 0.989 | 0.011 | 0.012 |
## | 0.016 | 0.001 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.65 | 198 | 1 | 199 |
## | 14.186 | 45.400 | |
## | 0.995 | 0.005 | 0.013 |
## | 0.017 | 0.000 | |
## | 0.013 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.66 | 217 | 11 | 228 |
## | 10.784 | 34.512 | |
## | 0.952 | 0.048 | 0.015 |
## | 0.019 | 0.003 | |
## | 0.014 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.67 | 176 | 1 | 177 |
## | 12.550 | 40.164 | |
## | 0.994 | 0.006 | 0.012 |
## | 0.015 | 0.000 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.68 | 161 | 1 | 162 |
## | 11.435 | 36.595 | |
## | 0.994 | 0.006 | 0.011 |
## | 0.014 | 0.000 | |
## | 0.011 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.69 | 209 | 0 | 209 |
## | 15.549 | 49.759 | |
## | 1.000 | 0.000 | 0.014 |
## | 0.018 | 0.000 | |
## | 0.014 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.7 | 195 | 10 | 205 |
## | 9.642 | 30.856 | |
## | 0.951 | 0.049 | 0.014 |
## | 0.017 | 0.003 | |
## | 0.013 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.71 | 167 | 4 | 171 |
## | 10.345 | 33.105 | |
## | 0.977 | 0.023 | 0.011 |
## | 0.015 | 0.001 | |
## | 0.011 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.72 | 200 | 30 | 230 |
## | 3.498 | 11.195 | |
## | 0.870 | 0.130 | 0.015 |
## | 0.018 | 0.008 | |
## | 0.013 | 0.002 | |
## ----------------------|-----------|-----------|-----------|
## 0.73 | 204 | 42 | 246 |
## | 1.465 | 4.687 | |
## | 0.829 | 0.171 | 0.016 |
## | 0.018 | 0.012 | |
## | 0.014 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.74 | 206 | 51 | 257 |
## | 0.530 | 1.696 | |
## | 0.802 | 0.198 | 0.017 |
## | 0.018 | 0.014 | |
## | 0.014 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.75 | 188 | 38 | 226 |
## | 1.451 | 4.643 | |
## | 0.832 | 0.168 | 0.015 |
## | 0.016 | 0.011 | |
## | 0.013 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.76 | 189 | 45 | 234 |
## | 0.644 | 2.059 | |
## | 0.808 | 0.192 | 0.016 |
## | 0.017 | 0.013 | |
## | 0.013 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.77 | 201 | 51 | 252 |
## | 0.422 | 1.349 | |
## | 0.798 | 0.202 | 0.017 |
## | 0.018 | 0.014 | |
## | 0.013 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.78 | 191 | 50 | 241 |
## | 0.296 | 0.949 | |
## | 0.793 | 0.207 | 0.016 |
## | 0.017 | 0.014 | |
## | 0.013 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.79 | 172 | 45 | 217 |
## | 0.269 | 0.860 | |
## | 0.793 | 0.207 | 0.014 |
## | 0.015 | 0.013 | |
## | 0.011 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.8 | 194 | 28 | 222 |
## | 3.652 | 11.688 | |
## | 0.874 | 0.126 | 0.015 |
## | 0.017 | 0.008 | |
## | 0.013 | 0.002 | |
## ----------------------|-----------|-----------|-----------|
## 0.81 | 169 | 51 | 220 |
## | 0.011 | 0.036 | |
## | 0.768 | 0.232 | 0.015 |
## | 0.015 | 0.014 | |
## | 0.011 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.82 | 183 | 58 | 241 |
## | 0.002 | 0.007 | |
## | 0.759 | 0.241 | 0.016 |
## | 0.016 | 0.016 | |
## | 0.012 | 0.004 | |
## ----------------------|-----------|-----------|-----------|
## 0.83 | 187 | 47 | 234 |
## | 0.426 | 1.362 | |
## | 0.799 | 0.201 | 0.016 |
## | 0.016 | 0.013 | |
## | 0.012 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.84 | 185 | 62 | 247 |
## | 0.054 | 0.173 | |
## | 0.749 | 0.251 | 0.016 |
## | 0.016 | 0.017 | |
## | 0.012 | 0.004 | |
## ----------------------|-----------|-----------|-----------|
## 0.85 | 171 | 36 | 207 |
## | 1.119 | 3.580 | |
## | 0.826 | 0.174 | 0.014 |
## | 0.015 | 0.010 | |
## | 0.011 | 0.002 | |
## ----------------------|-----------|-----------|-----------|
## 0.86 | 159 | 41 | 200 |
## | 0.287 | 0.919 | |
## | 0.795 | 0.205 | 0.013 |
## | 0.014 | 0.011 | |
## | 0.011 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.87 | 167 | 58 | 225 |
## | 0.115 | 0.367 | |
## | 0.742 | 0.258 | 0.015 |
## | 0.015 | 0.016 | |
## | 0.011 | 0.004 | |
## ----------------------|-----------|-----------|-----------|
## 0.88 | 162 | 25 | 187 |
## | 2.675 | 8.560 | |
## | 0.866 | 0.134 | 0.012 |
## | 0.014 | 0.007 | |
## | 0.011 | 0.002 | |
## ----------------------|-----------|-----------|-----------|
## 0.89 | 181 | 56 | 237 |
## | 0.001 | 0.003 | |
## | 0.764 | 0.236 | 0.016 |
## | 0.016 | 0.016 | |
## | 0.012 | 0.004 | |
## ----------------------|-----------|-----------|-----------|
## 0.9 | 168 | 52 | 220 |
## | 0.001 | 0.003 | |
## | 0.764 | 0.236 | 0.015 |
## | 0.015 | 0.015 | |
## | 0.011 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.91 | 181 | 43 | 224 |
## | 0.625 | 2.001 | |
## | 0.808 | 0.192 | 0.015 |
## | 0.016 | 0.012 | |
## | 0.012 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 0.92 | 178 | 20 | 198 |
## | 4.883 | 15.626 | |
## | 0.899 | 0.101 | 0.013 |
## | 0.016 | 0.006 | |
## | 0.012 | 0.001 | |
## ----------------------|-----------|-----------|-----------|
## 0.93 | 169 | 0 | 169 |
## | 12.573 | 40.236 | |
## | 1.000 | 0.000 | 0.011 |
## | 0.015 | 0.000 | |
## | 0.011 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.94 | 167 | 0 | 167 |
## | 12.424 | 39.760 | |
## | 1.000 | 0.000 | 0.011 |
## | 0.015 | 0.000 | |
## | 0.011 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.95 | 181 | 0 | 181 |
## | 13.466 | 43.093 | |
## | 1.000 | 0.000 | 0.012 |
## | 0.016 | 0.000 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.96 | 203 | 0 | 203 |
## | 15.102 | 48.331 | |
## | 1.000 | 0.000 | 0.014 |
## | 0.018 | 0.000 | |
## | 0.014 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.97 | 176 | 0 | 176 |
## | 13.094 | 41.903 | |
## | 1.000 | 0.000 | 0.012 |
## | 0.015 | 0.000 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.98 | 183 | 0 | 183 |
## | 13.614 | 43.569 | |
## | 1.000 | 0.000 | 0.012 |
## | 0.016 | 0.000 | |
## | 0.012 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 0.99 | 172 | 0 | 172 |
## | 12.796 | 40.950 | |
## | 1.000 | 0.000 | 0.011 |
## | 0.015 | 0.000 | |
## | 0.011 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## 1 | 111 | 0 | 111 |
## | 8.258 | 26.427 | |
## | 1.000 | 0.000 | 0.007 |
## | 0.010 | 0.000 | |
## | 0.007 | 0.000 | |
## ----------------------|-----------|-----------|-----------|
## Column Total | 11428 | 3571 | 14999 |
## | 0.762 | 0.238 | |
## ----------------------|-----------|-----------|-----------|
##
##
## Statistics for All Table Factors
##
##
## Pearson's Chi-squared test
## ------------------------------------------------------------
## Chi^2 = 7937.744 d.f. = 91 p = 0
##
##
##
-P<.001 so we must reject the null hypothesis -Employees with extremley high satisfaction levels >.90 are very likley to not leave -Of employees with satisfaction level >.9, (115/2004)=.0573 have left
T2 <- hr
summary_T2 <- T2 %>%
group_by(satisfaction_level) %>%
summarise(
pct_leftT2 = mean(left == 1) * 100
)
plot_ly(
data = summary_T2 ,
x = ~satisfaction_level,
y = ~pct_leftT2,
type = "bar"
) %>%
layout(
title = "Employees with higher satisfaction level are more likley to stay",
xaxis = list(title = "salary level"),
yaxis = list(title = "Percent left (%)")
)
CrossTable(hr$time_spend_company , hr$Work_accident , chisq = T)
##
##
## Cell Contents
## |-------------------------|
## | N |
## | Chi-square contribution |
## | N / Row Total |
## | N / Col Total |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 14999
##
##
## | hr$Work_accident
## hr$time_spend_company | 0 | 1 | Row Total |
## ----------------------|-----------|-----------|-----------|
## 2 | 2686 | 558 | 3244 |
## | 2.847 | 16.842 | |
## | 0.828 | 0.172 | 0.216 |
## | 0.209 | 0.257 | |
## | 0.179 | 0.037 | |
## ----------------------|-----------|-----------|-----------|
## 3 | 5548 | 895 | 6443 |
## | 0.245 | 1.447 | |
## | 0.861 | 0.139 | 0.430 |
## | 0.432 | 0.413 | |
## | 0.370 | 0.060 | |
## ----------------------|-----------|-----------|-----------|
## 4 | 2239 | 318 | 2557 |
## | 1.225 | 7.247 | |
## | 0.876 | 0.124 | 0.170 |
## | 0.175 | 0.147 | |
## | 0.149 | 0.021 | |
## ----------------------|-----------|-----------|-----------|
## 5 | 1302 | 171 | 1473 |
## | 1.401 | 8.285 | |
## | 0.884 | 0.116 | 0.098 |
## | 0.101 | 0.079 | |
## | 0.087 | 0.011 | |
## ----------------------|-----------|-----------|-----------|
## 6 | 611 | 107 | 718 |
## | 0.016 | 0.097 | |
## | 0.851 | 0.149 | 0.048 |
## | 0.048 | 0.049 | |
## | 0.041 | 0.007 | |
## ----------------------|-----------|-----------|-----------|
## 7 | 162 | 26 | 188 |
## | 0.009 | 0.052 | |
## | 0.862 | 0.138 | 0.013 |
## | 0.013 | 0.012 | |
## | 0.011 | 0.002 | |
## ----------------------|-----------|-----------|-----------|
## 8 | 118 | 44 | 162 |
## | 3.054 | 18.067 | |
## | 0.728 | 0.272 | 0.011 |
## | 0.009 | 0.020 | |
## | 0.008 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## 10 | 164 | 50 | 214 |
## | 1.983 | 11.731 | |
## | 0.766 | 0.234 | 0.014 |
## | 0.013 | 0.023 | |
## | 0.011 | 0.003 | |
## ----------------------|-----------|-----------|-----------|
## Column Total | 12830 | 2169 | 14999 |
## | 0.855 | 0.145 | |
## ----------------------|-----------|-----------|-----------|
##
##
## Statistics for All Table Factors
##
##
## Pearson's Chi-squared test
## ------------------------------------------------------------
## Chi^2 = 74.54918 d.f. = 7 p = 1.770565e-13
##
##
##
-P<.001 so we must reject the null hypothesis, meaning there is an association between time spent at the company and work accidents - Employees with fewer years at the company are less likley to have a work accident, 2 years at co=17.2% had accidents, 10 years at co= 23.4% had accidents
T3 <- hr
summary_T3 <- T3 %>%
group_by(time_spend_company) %>%
summarise(
pct_work_accident = mean(Work_accident == 1) * 100
)
plot_ly(
data = summary_T3 ,
x = ~time_spend_company,
y = ~pct_work_accident,
type = "bar"
) %>%
layout(
title = "Employees who have been at the company longer
are more likley to have a Work Accident",
xaxis = list(title = "Years at company"),
yaxis = list(title = "Percentage of work accidents")
)
CrossTable(hr$number_project , hr$left, chisq = T)
##
##
## Cell Contents
## |-------------------------|
## | N |
## | Chi-square contribution |
## | N / Row Total |
## | N / Col Total |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 14999
##
##
## | hr$left
## hr$number_project | 0 | 1 | Row Total |
## ------------------|-----------|-----------|-----------|
## 2 | 821 | 1567 | 2388 |
## | 547.921 | 1753.471 | |
## | 0.344 | 0.656 | 0.159 |
## | 0.072 | 0.439 | |
## | 0.055 | 0.104 | |
## ------------------|-----------|-----------|-----------|
## 3 | 3983 | 72 | 4055 |
## | 258.355 | 826.794 | |
## | 0.982 | 0.018 | 0.270 |
## | 0.349 | 0.020 | |
## | 0.266 | 0.005 | |
## ------------------|-----------|-----------|-----------|
## 4 | 3956 | 409 | 4365 |
## | 119.428 | 382.197 | |
## | 0.906 | 0.094 | 0.291 |
## | 0.346 | 0.115 | |
## | 0.264 | 0.027 | |
## ------------------|-----------|-----------|-----------|
## 5 | 2149 | 612 | 2761 |
## | 0.977 | 3.128 | |
## | 0.778 | 0.222 | 0.184 |
## | 0.188 | 0.171 | |
## | 0.143 | 0.041 | |
## ------------------|-----------|-----------|-----------|
## 6 | 519 | 655 | 1174 |
## | 157.624 | 504.433 | |
## | 0.442 | 0.558 | 0.078 |
## | 0.045 | 0.183 | |
## | 0.035 | 0.044 | |
## ------------------|-----------|-----------|-----------|
## 7 | 0 | 256 | 256 |
## | 195.051 | 624.206 | |
## | 0.000 | 1.000 | 0.017 |
## | 0.000 | 0.072 | |
## | 0.000 | 0.017 | |
## ------------------|-----------|-----------|-----------|
## Column Total | 11428 | 3571 | 14999 |
## | 0.762 | 0.238 | |
## ------------------|-----------|-----------|-----------|
##
##
## Statistics for All Table Factors
##
##
## Pearson's Chi-squared test
## ------------------------------------------------------------
## Chi^2 = 5373.586 d.f. = 5 p = 0
##
##
##
-P<.001 so we must reject the null hypothesis, meaning there is an association between -how many projects they worked on and whether they left or not. -Employees who fell onto either extreme of number of projects, ie. 1, 6 ,7 -resulted in the highest turnover rate, all above 50% turnover - Employees who had either 3 or 4 projects complete had the lowest turnover rate of .018 and .094 -Employees who had 5 projects complete showed a moderate turnover rate of .222
T4 <- hr
summary_T4 <- T4 %>%
group_by(number_project) %>%
summarise(
pct_leftT4 = mean(left == 1) *100
)
plot_ly(
data = summary_T4,
x = ~number_project,
y = ~pct_leftT4,
type = "bar"
) %>%
layout(
title = "Employees on Either Extreme of Number
of Projects Were the Most Likley to Leave",
xaxis = list(title = "Number of Projects"),
yaxis = list(title = "Percentage left %")
)