-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intrepid_potash.Rmd
176 lines (112 loc) · 5.09 KB
/
Intrepid_potash.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
---
title: "Intrepid Potash"
author: "Chris Trivino"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
keep_md: true
toc: true
toc_float: true
code_folding: hide
fig_height: 6
fig_width: 12
fig_align: 'center'
---
```{r load_libraries, message=FALSE, warning=FALSE, include=FALSE}
# Use this R-Chunk to load all your libraries!
#install.packages("tidyverse") # run this line once in console to get package
library(tidyverse)
library(nycflights13)
library(knitr)
library(gt)
library(readr)
library(lubridate)
library(stringr)
library(grid)
library(gridExtra)
library(downloader)
library(haven)
library(foreign)
library(textreadr)
library(readxl)
library(directlabels)
library(pander)
intrepid <- read_csv("C:/Users/Admin/Downloads/two_col_na.csv")
```
```{r load_data, message=FALSE, warning=FALSE}
# Use this R-Chunk to import all your !
intrepid$NS1M1[intrepid$NS1M1=="[-11059] No Good Data For Calculation"]<-NA
intrepid$NS1M1 <-as.numeric(intrepid$NS1M1)
intrepid$NS2M1[intrepid$NS2M1=="[-11059] No Good Data For Calculation"]<-NA
intrepid$NS2M1 <-as.numeric(intrepid$NS2M1)
intrepid$NS2M2[intrepid$NS2M2=="[-11059] No Good Data For Calculation"]<-NA
intrepid$NS2M2 <-as.numeric(intrepid$NS2M2)
intrepid$RollGap1[intrepid$RollGap1=="[-11059] No Good Data For Calculation"]<-NA
intrepid$RollGap1 <-as.numeric(intrepid$RollGap1)
intrepid$RollGap2[intrepid$RollGap2=="[-11059] No Good Data For Calculation"]<-NA
intrepid$RollGap2 <-as.numeric(intrepid$RollGap2)
intrepid$NS1Gate[intrepid$NS1Gate=="[-11059] No Good Data For Calculation"]<-NA
intrepid$NS1Gate <-as.numeric(intrepid$NS1Gate)
intrepid$NS2Gate[intrepid$NS2Gate=="[-11059] No Good Data For Calculation"]<-NA
intrepid$NS2Gate <-as.numeric(intrepid$NS2Gate)
intrepid$BinLevel[intrepid$BinLevel=="[-11059] No Good Data For Calculation"]<-NA
intrepid$BinLevel <-as.numeric(intrepid$BinLevel)
intrepid$NS2Gate[intrepid$NS2Gate=="[-11059] No Good Data For Calculation"]<-NA
intrepid$NS2Gate <-as.numeric(intrepid$NS2Gate)
dat <- intrepid %>% filter(Method == "clamshells", intrepid$Product == 230)
dat <- intrepid %>% filter(Method == "clamshells", intrepid$Product == 230)
dat$NS1Diff <- dat$NS1M2-dat$NS1M1
data1 <- subset(dat, select = -c(Method, Product,Time))
data1 <- data1 %>% filter(AvgBelt6TPHTime>0)
data2 <- data1 %>% select(c(AvgBelt6TPHTime,NS1Diff, NS1M1, NS1M2,Tumbler))
```
## Trying to find linear models
This can help me get off to a start.
```{r}
mylm <- lm(AvgBelt6TPHTime ~ . , data = data1 )
pander(summary(mylm))
mylm2 <- lm(AvgBelt6TPHTime ~ .^2 , data = data1 )
#pander(summary(mylm2))
mylm3 <- lm(AvgBelt6TPHTime ~ .^3 , data = data1 )
#pander(summary(mylm3))
```
## Lets take a look at the pairs plots
```{r}
#pairs(cbind(Res = mylm3$res, Fit = mylm3$fit, data1),panel=panel.smooth)
pairs(data2,panel=panel.smooth)
```
## finding a linear model to work with
After much trial and tribulation I found a good lead, but there are still some problems
```{r tidy_data}
# Use this R-Chunk to clean & wrangle your data!
lm8 <- lm(AvgBelt6TPHTime~I(NS1Diff^2)+I(NS1Diff^3)+(Tumbler)+CompactorRollSpeed,data1)
pander(summary(lm8)) #.80
par(mfrow=c(1,3))
plot(lm8, which=1:2)
plot(lm8$residuals, main="Residuals vs Order", xlab="",
ylab="Residuals")
```
Good news: The model is simple and is 2D explainable.
Bad news: From the diagnostic plots almost every linear assumption is being violated. There are lots of problems.
## Data Visualizations
Time to try and find what's going on in the data that's causing my linear assumptions to fail.
```{r plot_data}
# Use this R-Chunk to plot & visualize your data!
ggplot(data1, aes(x=CompactorRollSpeed,y=AvgBelt6TPHTime, color=Tumbler)) + geom_point(opacity=.3) + theme_bw()
```
hmm.. Why did the compactor roller speed stay at 65 for such a large amount of time? I will have to email our contact with the company. The grey dots are NA's, I wonder if I can find out if they are supposed to be zero.
```{r}
data1 <- data1 %>% mutate(tumbler_no_na = case_when(Tumbler == 0 ~ "off",
Tumbler ==1 ~ "on",
is.na(Tumbler) ~ "unknown",
TRUE~"unknown"))
```
```{r}
#ggplot(data1, aes(x=CompactorRollSpeed,y=AvgBelt6TPHTime, color=Tumbler)) + geom_point()
data1 %>%
filter(CompactorRollSpeed>65.2 & CompactorRollSpeed <= 65.26) %>%
ggplot(aes(x=CompactorRollSpeed,y=AvgBelt6TPHTime, color=tumbler_no_na)) + geom_boxplot()+ facet_wrap(~tumbler_no_na)
```
If I can try and find out if NA's are zero's that would help significantly.
## Next step:
You could hire someone helping them understand the NA values in the data set along with the information you provided us. This would help someone with industry experience give you an appropriate regression model faster. Or you could bring the project back to DSS and let students work with the data to help create a linear model.