forked from toledo60/ggDoE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
308 lines (192 loc) · 6.37 KB
/
README.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
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
---
output: github_document
---
# ggDoE <img src="ggdoe-hexsticker.png" align="right" height="250px" />
[![CRAN status](https://www.r-pkg.org/badges/version/ggDoE)](https://cran.r-project.org/package=ggDoE)
[![R-CMD-check](https://github.com/toledo60/ggDoE/workflows/R-CMD-check/badge.svg)](https://github.com/toledo60/ggDoE/actions)
[![Documentation](https://img.shields.io/badge/Documentation-ggDoE-blue)](https://ggdoe.netlify.app/)
```{r,echo=FALSE}
knitr::opts_chunk$set(
eval = FALSE, fig.width = 6
)
```
## Installation
You can install:
* the latest release from CRAN with
```{r}
install.packages('ggDoE')
```
* the development version from GitHub with
```{r,eval=FALSE}
if (!require("remotes")) install.packages("remotes")
remotes::install_github("toledo60/ggDoE")
```
## Overview
With ggDoE you'll be able to generate common plots used in Design of Experiments with ggplot2.
```{r,eval=TRUE}
library(ggDoE)
```
The following plots are currently available:
**Alias Matrix**
Correlation matrix plot to visualize the Alias matrix
```{r}
alias_matrix(design=aliased_design)
```
![](man/figures/alias_matrix.png)
**Box-Cox Transformation**
```{r}
model <- lm(s2 ~ (A+B+C+D),data = adapted_epitaxial)
boxcox_transform(model,lambda = seq(-5,5,0.2))
```
![](man/figures/boxcox_transformation.png)
**Lambda Plot**
Obtain the trace plot of the *t*-statistics after applying Boxcox transformation across a specified sequence of lambda values
```{r}
model <- lm(s2 ~ (A+B+C)^2,data=original_epitaxial)
lambda_plot(model)
```
![](man/figures/lambda_plot1.png)
```{r}
lambda_plot(model, lambda = seq(0,2,by=0.1))
```
![](man/figures/lambda_plot2.png)
**Boxplots**
```{r}
data <- ToothGrowth
data$dose <- factor(data$dose,levels = c(0.5, 1, 2),
labels = c("D0.5", "D1", "D2"))
gg_boxplots(data,response = 'len',
factor = 'dose')
```
![](man/figures/boxplot1.png)
```{r}
gg_boxplots(data,response = 'len',
factor = 'dose',
group_var = 'supp',
color_palette = 'viridis',
jitter_points = TRUE)
```
![](man/figures/boxplot2.png)
**Regression Diagnostic Plots**
1. Residual vs. Fitted Values
2. Normal-QQ plot
3. Scale-Location plot
4. Residual vs. Leverage
5. Cook's Distance
6. Collinearity
The default plots are 1-4
```{r,fig.height=10,fig.width=8}
model <- lm(mpg ~ wt + am + gear + vs * cyl, data = mtcars)
diagnostic_plots(model,which_plots=1:6)
```
![](man/figures/diagnostic_plots.png)
**GLM Diagnostic Plots**
1. Residual vs. Fitted Values
2. Working Responses vs Linear Predictors
3. Normal Q-Q plot
4. Outlier Detection
5. Half norm plot using leverages
6. Half norm plot using Cook's Distance
7. Cook's Distance
8. DFFITS
9. Collinearity
The default plots are 1-4
```{r,fig.height=10,fig.width=8}
glm_model <- glm(Volume ~ log(Girth) + log(Height), family = Gamma(link = "log"), data = trees)
glm_diagnostic_plots(glm_model, discrete_edm = FALSE, which_plots = c(1:4, 7:8))
```
![](man/figures/glm_diagnostic_plots.png)
**Half-Normal Plot**
```{r}
model <- lm(ybar ~ (A+B+C+D)^4,data=adapted_epitaxial)
half_normal(model)
```
![](man/figures/half_normal1.png)
```{r}
half_normal(model,method='Zahn',alpha=0.1,
ref_line=TRUE,label_active=TRUE,
margin_errors=TRUE)
```
![](man/figures/half_normal2.png)
**Interaction Effects Plot (Factorial Design)**
Interaction effects plot between two factors in a factorial design
```{r,fig.width=8,fig.height=6}
interaction_effects(adapted_epitaxial,response = 'ybar',
exclude_vars = c('s2','lns2'))
```
![](man/figures/interactions1.png)
```{r,fig.width=9,fig.height=4}
interaction_effects(adapted_epitaxial,response = 'ybar',
exclude_vars = c('A','s2','lns2'),
n_columns=3)
```
![](man/figures/interactions2.png)
**Main Effects Plots (Factorial Design)**
Main effect plots for each factor in a factorial design
```{r}
main_effects(original_epitaxial,
response='s2',
exclude_vars = c('ybar','lns2'))
```
![](man/figures/main_effects1.png)
```{r}
main_effects(original_epitaxial,
response='s2',
exclude_vars = c('A','ybar','lns2'),
color_palette = 'viridis',
n_columns=3)
```
![](man/figures/main_effects2.png)
**Contour Plots**
contour plot(s) that display the fitted surface for an *rsm*
object involving two or more numerical predictors
```{r}
heli.rsm <- rsm::rsm(ave ~ SO(x1, x2, x3, x4),
data = rsm::heli)
```
```{r}
gg_rsm(heli.rsm,form = ~x1+x2+x3+x4,
at = rsm::xs(heli.rsm))
```
![](man/figures/contour1.png)
```{r}
gg_rsm(heli.rsm,form = ~x1+x2+x3+x4,
at = rsm::xs(heli.rsm),
filled = TRUE)
```
![](man/figures/contour2.png)
**Pareto Plot**
Pareto plot of effects with cutoff values for the margin of error (ME) and simultaneous margin of error (SME)
```{r}
model <- lm(lns2 ~ (A+B+C+D)^4,data=original_epitaxial)
pareto_plot(model)
```
![](man/figures/pareto_plot1.png)
```{r}
pareto_plot(model,method='Zahn',alpha=0.1)
```
![](man/figures/pareto_plot2.png)
**Two Dimensional Projections**
This function will output all two dimensional projections from a Latin hypercube design
```{r}
set.seed(10)
X <- lhs::randomLHS(n=10, k=4)
twoD_projections(X,n_columns=3,grid = TRUE)
```
![](man/figures/twoD_projections.png)
Lastly, the following datasets/designs are included in ggDoE as tibbles:
- **adapted_epitaxial**: Adapted epitaxial layer experiment obtain from the book <br>
*"Experiments: Planning, Analysis, and Optimization, 2nd Edition"*
- **original_epitaxial**: Original epitaxial layer experiment obtain from the book <br>
*"Experiments: Planning, Analysis, and Optimization, 2nd Edition"*
- **aliased_design**: D-efficient minimal aliasing design obtained from the article <br>
*"Efficient Designs With Minimal Aliasing by Bradley Jones and Christopher J. Nachtsheim"* <br>
*Source:* <https://www.tandfonline.com/doi/abs/10.1198/TECH.2010.09113>
## Citation
If you want to cite this package in a scientific journal or in any other context, run the following code in your `R` console
```{r,eval=TRUE,comment=NA}
citation('ggDoE')
```
## Contributing to the package
I welcome feedback, suggestions, issues, and contributions!
Check out the [CONTRIBUTING](https://github.com/toledo60/ggDoE/blob/main/.github/CONTRIBUTING.md) file for more details.