-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempAnalysis.Rmd
187 lines (164 loc) · 6.13 KB
/
tempAnalysis.Rmd
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
---
title: "Initial_Analysis"
author: "Samantha Sprague"
date: "12/2/2018"
output: html_document
---
#Enviornment Setup
```{r setup, include=FALSE}
library(readxl)
library(pander)
library(ggthemes)
library(ggplot2)
library(grid)
library(gridExtra)
```
#Reading in Data and Cleaning
```{r}
#Reading in hr data file
raw<-readRDS("data/hr-data.rds")
pander(head(raw))
#Turning Variables into Factors
names <- c('WorkLifeBalance' ,'StockOptionLevel','PerformanceRating','JobSatisfaction',
'RelationshipSatisfaction','JobLevel','JobInvolvement','EnvironmentSatisfaction','Education')
raw[,names] <- lapply(raw[,names] , factor)
#Looking at dataset structure
pander(str(raw))
```
#Initial Variable Plot Objects
```{r}
ggplot(raw,aes(Attrition,fill=Attrition))+geom_bar()+theme_tufte()+scale_fill_few("Dark")+ggtitle("Attrition Frequencies")+ylab("Frequency of Employees")+ theme(plot.title = element_text(hjust = 0.5))
pander(prop.table(table(raw$Attrition)))
#We see that there is a 16% attrition rate.
```
#Variable Density Plots
```{r}
# Age
agePlot <- ggplot(raw,aes(Age,fill=Attrition))+
geom_density()+
facet_grid(~Attrition)+
theme_tufte()+
scale_fill_few("Dark")
# Travel
travelPlot <-ggplot(raw, aes(BusinessTravel, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark");
ratePlot <- ggplot(raw, aes(DailyRate, Attrition)) +
geom_point(size = 4, alpha = 0.05) +
theme_tufte() +
scale_fill_few("Dark")
depPlot <-
ggplot(raw, aes(Department, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
distPlot <-
ggplot(raw, aes(DistanceFromHome, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
eduPlot <-
ggplot(raw, aes(Education, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
edufieldPlot <-
ggplot(raw, aes(EducationField, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
envPlot <-
ggplot(raw, aes(EnvironmentSatisfaction, fill = Attrition)) + geom_bar() +
theme_tufte() + scale_fill_few("Dark")
genPlot <-
ggplot(raw, aes(Gender, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
hourlyPlot <-
ggplot(raw, aes(HourlyRate, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
jobInvPlot <-
ggplot(raw, aes(JobInvolvement, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
jobLevelPlot <-
ggplot(raw, aes(JobLevel, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
jobSatPlot <-
ggplot(raw, aes(JobSatisfaction, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
marPlot <-
ggplot(raw, aes(MaritalStatus, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
monthlyIncPlot <-
ggplot(raw, aes(MonthlyIncome, fill = Attrition)) + geom_density() + theme_tufte() +
scale_fill_few("Dark")
monthlyRatePlot <-
ggplot(raw, aes(MonthlyRate, fill = Attrition)) + geom_density() + theme_tufte() +
scale_fill_few("Dark")
numCompPlot <-
ggplot(raw, aes(NumCompaniesWorked, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
overTimePlot <-
ggplot(raw, aes(OverTime, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
hikePlot <-
ggplot(raw, aes(PercentSalaryHike, Attrition)) + geom_point(size = 4, alpha = 0.01) +
theme_tufte() + scale_fill_few("Dark")
perfPlot <-
ggplot(raw, aes(PerformanceRating, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
RelSatPlot <-
ggplot(raw, aes(RelationshipSatisfaction, fill = Attrition)) + geom_bar() +
theme_tufte() + scale_fill_few("Dark")
overTimePlot <-
ggplot(raw, aes(OverTime, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
hikePlot <-
ggplot(raw, aes(PercentSalaryHike, Attrition)) + geom_point(size = 4, alpha = 0.01) +
theme_tufte() + scale_fill_few("Dark")
perfPlot <-
ggplot(raw, aes(PerformanceRating, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
RelSatPlot <-
ggplot(raw, aes(RelationshipSatisfaction, fill = Attrition)) + geom_bar() +
theme_tufte() + scale_fill_few("Dark")
StockPlot <-
ggplot(raw, aes(StockOptionLevel, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
workingYearsPlot <-
ggplot(raw, aes(TotalWorkingYears, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
TrainTimesPlot <-
ggplot(raw, aes(TrainingTimesLastYear, fill = Attrition)) + geom_bar() +
theme_tufte() + scale_fill_few("Dark")
WLBPlot <-
ggplot(raw, aes(WorkLifeBalance, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
YearAtComPlot <-
ggplot(raw, aes(YearsAtCompany, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
YearInCurrPlot <-
ggplot(raw, aes(YearsInCurrentRole, fill = Attrition)) + geom_bar() + theme_tufte() +
scale_fill_few("Dark")
YearsSinceProm <-
ggplot(raw, aes(YearsSinceLastPromotion, fill = Attrition)) + geom_bar() +
theme_tufte() + scale_fill_few("Dark")
YearsCurrManPlot <-
ggplot(raw, aes(YearsWithCurrManager, fill = Attrition)) + geom_bar() +
theme_tufte() + scale_fill_few("Dark")
```
#Consolidated Plot of All Variables with Respect to Attrition
```{r}
grid.arrange(marPlot,monthlyIncPlot,monthlyRatePlot,numCompPlot,hourlyPlot,jobInvPlot,jobLevelPlot,jobSatPlot,overTimePlot,hikePlot,perfPlot,RelSatPlot,StockPlot,workingYearsPlot,TrainTimesPlot,WLBPlot,YearAtComPlot,YearInCurrPlot,YearsSinceProm,YearsCurrManPlot,ncol=3,top = "Analysis of Attrition in Comparison to All Dataset Variables")
```
#Consolidated Plot of All Variables with Respect to Attrition
```{r}
grid.arrange(agePlot,travelPlot,ratePlot,depPlot,distPlot,eduPlot,edufieldPlot,envPlot,genPlot,ncol=3,top="plots")
```
#Missing Value Analysis
```{r}
na_count <- data.frame(sapply(raw, function(y) sum(length(which(is.na(y))))))
pander(na_count)
#No nulls, it's a miracle!
```
#Data Refactorization
```{r}
#We did all of our refactorization in another data file. It is read in here and used for further analysis. We leveraged the data description file to redine these new feature.
# fd <-read(factored-definitions)
```
```{r}
distPlot
```
#Feature Engineering
```{r}
```