-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr_final.md
615 lines (522 loc) · 16.4 KB
/
hr_final.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
---
title: "Exploring HR Data"
author: "Jia Xin Seng, Philip Khor"
date: "18 April 2018"
output:
html_document:
df_print: paged
keep_md: true
md_document:
variant: markdown_github
---
```r
library(readr)
library(tidyverse)
production <- read_csv("~/eda_r/human_resource/production_staff.csv")
core <- read_csv("~/eda_r/human_resource/core_dataset.csv")
HR <- read_csv("~/eda_r/human_resource/HRDataset_v9.csv")
core <- core[1:nrow(core)-1,]
```
## Data Description
* *Data*: Human Resource: Core dataset
* *Observations*: 302
* *Objective*: Pay rate
# Data cleaning
## Missing values
```r
sapply(core, function(x) sum(is.na(x))) %>%
sort(decreasing = TRUE) %>%
knitr::kable(format = 'html')
```
<table>
<thead>
<tr>
<th style="text-align:left;"> </th>
<th style="text-align:right;"> x </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Date of Termination </td>
<td style="text-align:right;"> 198 </td>
</tr>
<tr>
<td style="text-align:left;"> Employee Name </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Employee Number </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> State </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Zip </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> DOB </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Age </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Sex </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> MaritalDesc </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> CitizenDesc </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Hispanic/Latino </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> RaceDesc </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Date of Hire </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Reason For Term </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Employment Status </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Department </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Position </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Pay Rate </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Manager Name </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Employee Source </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Performance Score </td>
<td style="text-align:right;"> 0 </td>
</tr>
</tbody>
</table>
## Text issues
* male -> Male
* Software engineering: extra space
## Age
```r
core %>%
group_by(Age) %>%
summarise(count = n()) %>%
ggplot(aes(x = Age, y = count, fill = factor(Age))) + geom_bar(stat = 'identity') +
ggtitle('Distribution of Ages among Employees') + theme(legend.position = 'none')
```
![](hr_final_files/figure-html/unnamed-chunk-3-1.png)<!-- -->
# Gender
```r
core$Sex <- gsub('\\<male\\>', 'Male', core$Sex)
core %>%
group_by(Sex) %>%
summarise(wage = mean(`Pay Rate`)) %>%
ggplot(aes(x = Sex, y = wage, fill = Sex)) + geom_bar(stat = 'identity') +
theme(legend.position = 'none')
```
![](hr_final_files/figure-html/unnamed-chunk-4-1.png)<!-- -->
```r
core %>%
group_by(Sex) %>%
summarise(wage = mean(`Pay Rate`)) %>%
knitr::kable(format = 'html')
```
<table>
<thead>
<tr>
<th style="text-align:left;"> Sex </th>
<th style="text-align:right;"> wage </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Female </td>
<td style="text-align:right;"> 29.11678 </td>
</tr>
<tr>
<td style="text-align:left;"> Male </td>
<td style="text-align:right;"> 32.90528 </td>
</tr>
</tbody>
</table>
# Race
```r
core %>%
group_by(RaceDesc) %>%
summarise(wage = mean(`Pay Rate`)) %>%
ggplot(aes(x = RaceDesc, y = wage, fill = RaceDesc)) + geom_bar(stat = 'identity') +
theme(legend.position = 'none') + xlab('Race')
```
![](hr_final_files/figure-html/unnamed-chunk-6-1.png)<!-- -->
```r
core %>%
group_by(RaceDesc) %>%
summarise(wage = mean(`Pay Rate`)) %>%
knitr::kable(format = 'html')
```
<table>
<thead>
<tr>
<th style="text-align:left;"> RaceDesc </th>
<th style="text-align:right;"> wage </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> American Indian or Alaska Native </td>
<td style="text-align:right;"> 30.37500 </td>
</tr>
<tr>
<td style="text-align:left;"> Asian </td>
<td style="text-align:right;"> 29.44065 </td>
</tr>
<tr>
<td style="text-align:left;"> Black or African American </td>
<td style="text-align:right;"> 34.62463 </td>
</tr>
<tr>
<td style="text-align:left;"> Hispanic </td>
<td style="text-align:right;"> 39.75000 </td>
</tr>
<tr>
<td style="text-align:left;"> Two or more races </td>
<td style="text-align:right;"> 31.26444 </td>
</tr>
<tr>
<td style="text-align:left;"> White </td>
<td style="text-align:right;"> 29.57705 </td>
</tr>
</tbody>
</table>
# Group by sex, race
* *Females* and *African-Americans* have higher pay rate
* *Males* and *Hispanics* have higher pay rate
Top three earning races by gender:
```r
core %>%
group_by(Sex, RaceDesc) %>%
summarise(av.wage = mean(`Pay Rate`), av.age = mean(`Age`)) %>%
top_n(3, wt = av.wage) %>%
knitr::kable(format = 'html')
```
<table>
<thead>
<tr>
<th style="text-align:left;"> Sex </th>
<th style="text-align:left;"> RaceDesc </th>
<th style="text-align:right;"> av.wage </th>
<th style="text-align:right;"> av.age </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Female </td>
<td style="text-align:left;"> Asian </td>
<td style="text-align:right;"> 26.85550 </td>
<td style="text-align:right;"> 39.80000 </td>
</tr>
<tr>
<td style="text-align:left;"> Female </td>
<td style="text-align:left;"> Black or African American </td>
<td style="text-align:right;"> 34.38367 </td>
<td style="text-align:right;"> 39.96667 </td>
</tr>
<tr>
<td style="text-align:left;"> Female </td>
<td style="text-align:left;"> White </td>
<td style="text-align:right;"> 28.65182 </td>
<td style="text-align:right;"> 38.20000 </td>
</tr>
<tr>
<td style="text-align:left;"> Male </td>
<td style="text-align:left;"> American Indian or Alaska Native </td>
<td style="text-align:right;"> 36.00000 </td>
<td style="text-align:right;"> 38.50000 </td>
</tr>
<tr>
<td style="text-align:left;"> Male </td>
<td style="text-align:left;"> Hispanic </td>
<td style="text-align:right;"> 47.33333 </td>
<td style="text-align:right;"> 36.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> Male </td>
<td style="text-align:left;"> Two or more races </td>
<td style="text-align:right;"> 40.46571 </td>
<td style="text-align:right;"> 42.42857 </td>
</tr>
</tbody>
</table>
# Department
```r
core %>%
group_by(Department) %>%
summarise(wage = mean(`Pay Rate`)) %>%
ggplot(aes(x = Department, y = wage, fill = Department)) + geom_bar(stat = 'identity') +
theme(legend.position = 'none')
```
![](hr_final_files/figure-html/unnamed-chunk-9-1.png)<!-- -->
Average wage by department:
```r
core %>%
group_by(Department) %>%
summarise(wage = mean(`Pay Rate`)) %>%
knitr::kable(format = 'html')
```
<table>
<thead>
<tr>
<th style="text-align:left;"> Department </th>
<th style="text-align:right;"> wage </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Admin Offices </td>
<td style="text-align:right;"> 31.89600 </td>
</tr>
<tr>
<td style="text-align:left;"> Executive Office </td>
<td style="text-align:right;"> 80.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> IT/IS </td>
<td style="text-align:right;"> 44.79220 </td>
</tr>
<tr>
<td style="text-align:left;"> Production </td>
<td style="text-align:right;"> 23.08630 </td>
</tr>
<tr>
<td style="text-align:left;"> Sales </td>
<td style="text-align:right;"> 55.52419 </td>
</tr>
<tr>
<td style="text-align:left;"> Software Engineering </td>
<td style="text-align:right;"> 48.66500 </td>
</tr>
</tbody>
</table>
# Group by department, position
Top two earning positions (on average) in each department:
```r
core %>%
group_by(Department, Position) %>%
summarise(wage = mean(`Pay Rate`)) %>%
top_n(n=2, wt = wage) %>%
knitr::kable(format = 'html')
```
<table>
<thead>
<tr>
<th style="text-align:left;"> Department </th>
<th style="text-align:left;"> Position </th>
<th style="text-align:right;"> wage </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Admin Offices </td>
<td style="text-align:left;"> Shared Services Manager </td>
<td style="text-align:right;"> 55.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> Admin Offices </td>
<td style="text-align:left;"> Sr. Accountant </td>
<td style="text-align:right;"> 34.95000 </td>
</tr>
<tr>
<td style="text-align:left;"> Executive Office </td>
<td style="text-align:left;"> President & CEO </td>
<td style="text-align:right;"> 80.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> IT/IS </td>
<td style="text-align:left;"> CIO </td>
<td style="text-align:right;"> 65.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> IT/IS </td>
<td style="text-align:left;"> IT Director </td>
<td style="text-align:right;"> 65.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> Production </td>
<td style="text-align:left;"> Director of Operations </td>
<td style="text-align:right;"> 60.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> Production </td>
<td style="text-align:left;"> Production Manager </td>
<td style="text-align:right;"> 49.67857 </td>
</tr>
<tr>
<td style="text-align:left;"> Sales </td>
<td style="text-align:left;"> Director of Sales </td>
<td style="text-align:right;"> 60.00000 </td>
</tr>
<tr>
<td style="text-align:left;"> Sales </td>
<td style="text-align:left;"> Sales Manager </td>
<td style="text-align:right;"> 56.75000 </td>
</tr>
<tr>
<td style="text-align:left;"> Software Engineering </td>
<td style="text-align:left;"> Software Engineer </td>
<td style="text-align:right;"> 51.07222 </td>
</tr>
<tr>
<td style="text-align:left;"> Software Engineering </td>
<td style="text-align:left;"> Software Engineering Manager </td>
<td style="text-align:right;"> 27.00000 </td>
</tr>
</tbody>
</table>
Top-earning persons for each department:
- *Admin Offices*: Shared Services Manager
- *Executive Office*: President & CEO
- *IT/IS*: CIO, IT Director
- *Production*: Director of Operations
- *Sales*: Director of Sales
- *Software Engineering*: Software Engineer
## Recruitment tools
* Sales seems to rely heavily on PPC recruitment - but perhaps recruits are keen to show that they are familiar with marketing tools
* Production has the largest proportion in practically every employee source - but note that Production is also the largest department.
```r
core %>%
group_by(Department) %>%
summarise(count = n()) %>%
ggplot(aes(Department, count, fill = Department)) + geom_bar(stat = 'identity') + theme(legend.position = 'none')
```
![](hr_final_files/figure-html/unnamed-chunk-12-1.png)<!-- -->
```r
core$`Employee Source` <- gsub('Pay Per Click - Google|Website Banner Ads',
'Pay Per Click', core$`Employee Source`)
core$`Employee Source` <- gsub('Search Engine - Google Bing Yahoo',
'Internet Search', core$`Employee Source`)
core$`Employee Source` <- gsub('Monster.com|Glassdoor|Careerbuilder',
'Job Sites', core$`Employee Source`)
core$`Employee Source` <- gsub('Newspager/Magazine', 'Newspaper/Magazine',
core$`Employee Source`)
core$`Employee Source` <- gsub('Company Intranet - Partner|Information Session|On-line Web application', 'Other', core$`Employee Source`)
table(core$`Employee Source`, core$Department) %>%
as.data.frame %>%
ggplot(aes(x = Var1, y = Freq, fill = Var2)) + geom_bar(stat = 'identity') +
coord_flip() + labs(x = 'Employee Source', fill = 'Department')
```
![](hr_final_files/figure-html/unnamed-chunk-13-1.png)<!-- -->
## Distribution of pay rates
* We group people according to their level in the organisation: executives, seniors/managers and others
* This approximately matches the distribution.
```r
core$NewPosition <- NA
core[grepl(pattern = 'Director|CIO|CEO', x = core$Position),'NewPosition'] <- 'Executives'
core[grepl(pattern = 'Sr.|Manager', x = core$Position),'NewPosition'] <- 'Senior/Manager'
core[is.na(core$NewPosition), 'NewPosition'] <- 'Others'
ggplot(core, aes(`Pay Rate`, fill = NewPosition)) + geom_histogram() + labs(fill = 'Position group')
```
```
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
```
![](hr_final_files/figure-html/unnamed-chunk-14-1.png)<!-- -->
## Is there a statistically significant difference in the average pay of males and females?
* Yes. The difference in means is 3.8 and is significant at the 5% level.
```r
lmtest::coeftest(lm(`Pay Rate`~factor(Sex), data = core))
```
```
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 29.1168 1.1467 25.3925 < 2e-16 ***
## factor(Sex)Male 3.7885 1.7653 2.1461 0.03267 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
```
## Is there a difference in the distribution of pay between males and females?
* Doesn't seem to be much of a difference in the distribution for junior positions.
* Almost all execs are females, but there's a concentration of females among junior-level managers.
```r
library(ggridges)
ggplot(core, aes(x = `Pay Rate`, y = Sex, fill = NewPosition)) +
geom_density_ridges() + labs('Position group')
```
```
## Picking joint bandwidth of 1.92
```
![](hr_final_files/figure-html/unnamed-chunk-16-1.png)<!-- -->
## Performance ratings
Is there gender disparity in how performance ratings are assigned?
```r
ggplot(as.data.frame(table(core$Sex, core$`Performance Score`)), aes(x=Var1, y = Freq, fill = Var2)) + geom_bar(stat="identity") + labs(x = 'Sex', fill = 'Performance score')
```
![](hr_final_files/figure-html/unnamed-chunk-17-1.png)<!-- -->
# Time to termination within Production
Looks like people who leave Production tend to leave very soon!
```r
production$`Date of Hire` <- as.Date(production$`Date of Hire`, '%m/%d/%Y')
production$`TermDate` <- as.Date(production$`TermDate`, '%m/%d/%Y')
production$TimeDiff <- production$TermDate - production$`Date of Hire`
ggplot(production, aes(x = TimeDiff, fill= Position)) + geom_histogram() + labs(x = 'Time difference (days)')
```
```
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.
```
```
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
```
```
## Warning: Removed 173 rows containing non-finite values (stat_bin).
```
![](hr_final_files/figure-html/unnamed-chunk-18-1.png)<!-- -->
## Why do they leave?
```r
production[!grepl(pattern = 'N/A',production$`Reason for Term`) & !is.na(production$`Reason for Term`),] %>%
group_by(`Reason for Term`) %>%
summarise(Freq = n()) %>%
ggplot(aes(x = reorder(`Reason for Term`, Freq), y = Freq, fill = `Reason for Term`)) +
geom_bar(stat = 'identity') + coord_flip() + labs(x = 'Reason for Termination')
```
![](hr_final_files/figure-html/unnamed-chunk-19-1.png)<!-- -->
## Is it the pay rate?
Most of production consists of junior positions.
```r
core$prod = ifelse(core$Department == 'Production', 'Production', 'Not production')
ggplot(core, aes(x = `Pay Rate`, y = factor(prod), fill = NewPosition)) +
ggridges::geom_density_ridges() + labs(fill = 'Position group') +
theme(axis.title.y = element_blank())
```
```
## Picking joint bandwidth of 2.14
```
![](hr_final_files/figure-html/unnamed-chunk-20-1.png)<!-- -->