-
Notifications
You must be signed in to change notification settings - Fork 12
/
ss.ca.R
executable file
·628 lines (600 loc) · 22.9 KB
/
ss.ca.R
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# Capability Analysis Functions
#
# Author: Emilio Lopez
###############################################################################
# if(getRversion() >= '2.15.1') utils::globalVariables(c("..density..", "value"))
#' Main calculations regarding The Voice of the Process in SixSigma: Yield, FTY, RTY,
#' DPMO
#'
#' Computes the Yield, First Time Yield, Rolled Throughput Yield and Defects
#' per Million Opportunities of a process.
#'
#' The arguments defects and rework must have the same length.
#'
#' @param defects A vector with the number of defects in each product/batch, ...
#' @param rework A vector with the number of items/parts reworked
#' @param opportunities A numeric value with the size or length of the product/batch
#' @return
#' \item{Yield }{Number of good stuff / Total items}
#' \item{FTY }{(Total - scrap - rework) / Total }
#' \item{RTY }{prod(FTY)}
#' \item{DPMO}{Defects per Million Opportunities}
#' @references
#' Cano, Emilio L., Moguerza, Javier M. and Redchuk, Andres. 2012.
#' \emph{Six Sigma with {R}. Statistical Engineering for Process
#' Improvement}, Use R!, vol. 36. Springer, New York.
#' \url{https://link.springer.com/book/10.1007/978-1-4614-3652-2/}.
#'
#' Gygi C, DeCarlo N, Williams B (2005) \emph{Six sigma for dummies}. --For dummies,
#' Wiley Pub.
#' @author Emilio L. Cano
#' @export
#' @examples
#' ss.ca.yield(c(3,5,12),c(1,2,4),1915)
ss.ca.yield <- function(defects = 0, rework = 0, opportunities = 1){
Yield <- (opportunities - sum(defects)) / opportunities
FTY <- (opportunities - sum(defects) - sum(rework)) / opportunities
RTY <- prod((opportunities - (defects + rework)) / opportunities)
DPU <- sum(defects)
DPMO <- (DPU / opportunities) * 10^6
ss.ca.yield <- (list(Yield = Yield, FTY = FTY,
RTY = RTY, DPU = DPU, DPMO = DPMO))
as.data.frame(ss.ca.yield)
}
#' Capability Indices
#'
#' Compute the Capability Indices of a process, Z (Sigma Score), \eqn{C_p}
#' and \eqn{C_{pk}}.
#'
#' @usage
#' ss.ca.cp(x, LSL = NA, USL = NA, LT = FALSE, f.na.rm = TRUE,
#' ci = FALSE, alpha = 0.05)
#' @usage
#' ss.ca.cpk(x, LSL = NA, USL = NA, LT = FALSE, f.na.rm = TRUE,
#' ci = FALSE, alpha = 0.05)
#' @usage
#' ss.ca.z(x, LSL = NA, USL = NA, LT = FALSE, f.na.rm = TRUE)
#'
#' @aliases ss.ca.z ss.ca.cp ss.ca.cpk
#'
#' @param x A vector with the data of the process performance
#' @param LSL Lower Specification Limit
#' @param USL Upper Specification Limit
#' @param LT Long Term data (TRUE/FALSE). Not used for the moment
#' @param f.na.rm Remove NA data (TRUE/FALSE)
#' @param ci If TRUE computes a Confidence Interval
#' @param alpha Type I error (\eqn{\alpha}) for the Confidence Interval
#' @return A numeric value for the index, or a vector with the limits
#' of the Confidence Interval
#'
#' @references
#' Cano, Emilio L., Moguerza, Javier M. and Redchuk, Andres. 2012.
#' \emph{Six Sigma with {R}. Statistical Engineering for Process
#' Improvement}, Use R!, vol. 36. Springer, New York.
#' \url{https://link.springer.com/book/10.1007/978-1-4614-3652-2/}.
#'
#' Montgomery, DC (2008) \emph{Introduction to Statistical Quality Control}
#' (Sixth Edition). New York: Wiley&Sons\cr
#' @author EL Cano
#' @seealso \code{\link{ss.study.ca}}
#' @keywords cp cpk capability
#' @examples
#' ss.ca.cp(ss.data.ca$Volume,740, 760)
#' ss.ca.cpk(ss.data.ca$Volume,740, 760)
#' ss.ca.z(ss.data.ca$Volume,740,760)
#' @export ss.ca.z ss.ca.cp ss.ca.cpk
ss.ca.z <- function(x, LSL = NA, USL = NA,
LT = FALSE, f.na.rm = TRUE){
if (is.na(LSL) & is.na(USL)) {
stop ("No specification limits provided")
}
zz.m <- mean(x, na.rm = f.na.rm)
zz.s <- sd(x, na.rm = f.na.rm)
zul <- (USL - zz.m) / zz.s
zll <- (zz.m - LSL) / zz.s
if (is.na(zul)){
z <- zll
}
else if (is.na(zll)){
z <- zul
}
else {
z <- min(zul, zll)
}
if (LT != FALSE){
z <- z - 1.5
}
return(as.vector(z))
}
ss.ca.cp <- function(x, LSL = NA, USL = NA,
LT = FALSE, f.na.rm = TRUE,
ci = FALSE, alpha = 0.05){
if (is.na(LSL) & is.na(USL)) {
stop("No specification limits provided")
}
if (!is.numeric(x)){
stop("Incorrect vector data")
}
cp.m <- mean(x, na.rm = f.na.rm)
cp.s <- sd(x, na.rm = f.na.rm)
cp.l <- (cp.m - LSL) / (3 * cp.s)
cp.u <- (USL - cp.m) / (3 * cp.s)
cp <- (USL - LSL) / (6 * cp.s)
if (is.na(cp)){
cp <- max(cp.l, cp.u, na.rm = TRUE)
}
if (ci == FALSE){
return(as.numeric(cp))
}
else{
return(c(
as.numeric(cp)*sqrt((qchisq (alpha/2,length(x)-1,
lower.tail=TRUE)/(length(x)-1))),
as.numeric(cp)*sqrt((qchisq (alpha/2,length(x)-1,
lower.tail=FALSE)/(length(x)-1)))
))
}
}
ss.ca.cpk <- function(x, LSL = NA, USL = NA,
LT = FALSE, f.na.rm = TRUE,
ci = FALSE, alpha = 0.05 ){
if (is.na(LSL) & is.na(USL)) {
stop("No specification limits provided")
}
if (!is.numeric(x)){
stop("Incorrect vector data")
}
ss.n <- length(x[!is.na(x)])
cpk.m <- mean(x, na.rm = f.na.rm)
cpk.s <- sd(x, na.rm = f.na.rm)
cpk.ul <- (USL - cpk.m) / (3 * cpk.s)
cpk.ll <- (cpk.m - LSL) / (3 * cpk.s)
cpk <- min(cpk.ul, cpk.ll, na.rm = TRUE)
if (ci == FALSE){
return(as.numeric(cpk))
}
else{
return(c(
cpk*(1-(qnorm(1-(alpha/2))*sqrt((1/(9*ss.n*cpk^2))+(1/(2*(ss.n-1)))))),
cpk*(1+(qnorm(1-(alpha/2))*sqrt((1/(9*ss.n*cpk^2))+(1/(2*(ss.n-1))))))
))
}
}
###############################################################################
#' Graphs and figures for a Capability Study
#'
#' Plots a Histogram with density lines about the data of a process. Check normality
#' with qqplot and normality tests. Shows the Specification Limits and the
#' Capability Indices.
#'
#' @note
#' The argument \code{f.colours} takes a vector of colours for the graphical outputs. The order of
#' the elements are, first the colour for histogram bars, then Density ST lines, Density LT
#' lines, Target, and Specification limits. It can be partially specified.
#'
#'
#' @param xST Short Term process performance data
#' @param xLT Long Term process performance data
#' @param LSL Lower Specification Limit of the process
#' @param USL Upper Specification Limit of the process
#' @param Target Target of the process
#' @param alpha Type I error for the Confidence Interval
#' @param f.na.rm If TRUE NA data will be removed
#' @param f.main Main Title for the graphic output
#' @param f.sub Subtitle for the graphic output
#' @param f.colours Vector of colours fot the graphic output
#' @return Figures and plot for Capability Analysis
#'
#' @references
#' Cano, Emilio L., Moguerza, Javier M. and Redchuk, Andres. 2012.
#' \emph{Six Sigma with {R}. Statistical Engineering for Process
#' Improvement}, Use R!, vol. 36. Springer, New York.
#' \url{https://link.springer.com/book/10.1007/978-1-4614-3652-2/}.
#'
#' Montgomery, DC (2008) \emph{Introduction to Statistical Quality Control}
#' (Sixth Edition). New York: Wiley&Sons
#'
#' @seealso \code{\link{ss.ca.cp}}
#' @author Main author: Emilio L. Cano. Contributions by Manu Alfaro.
#' @export
#' @examples
#'
#' ss.study.ca(ss.data.ca$Volume, rnorm(40, 753, 3),
#' LSL = 740, USL = 760, T = 750, alpha = 0.05,
#' f.sub = "Winery Project")
#'
#' ss.study.ca(ss.data.ca$Volume, rnorm(40, 753, 3),
#' LSL = 740, USL = 760, T = 750, alpha = 0.05,
#' f.sub = "Winery Project",
#' f.colours = c("#990000", "#007700", "#002299"))
#'
ss.study.ca <- function (xST, xLT = NA, LSL = NA, USL = NA,
Target = NA, alpha = 0.05,
f.na.rm = TRUE,
f.main = "Six Sigma Capability Analysis Study",
f.sub = "",
f.colours = c("#4682B4","#d1d1e0","#000000","#A2CD5A","#D1EEEE",
"#FFFFFF", "#000000", "#000000")){
if (is.na(Target)){
stop("Target is needed")
}
if (is.na(LSL) & is.na(USL)){
stop("No specification limits provided")
}
#Facts
mST = mean(xST, na.rm = f.na.rm)
sST = sd(xST, na.rm = f.na.rm)
nST = length(xST[!is.na(xST)])
nLT = length(xLT[!is.na(xLT)])
zST = ss.ca.z(xST, LSL, USL)
cpST = ss.ca.cp(xST, LSL, USL)
cpiST = ss.ca.cp(xST, LSL, USL, ci = TRUE, alpha = alpha)
cpkST = ss.ca.cpk(xST, LSL, USL)
cpkiST = ss.ca.cpk(xST, LSL, USL, ci = TRUE, alpha = alpha)
DPMO <- (1 - pnorm(zST - 1.5)) * 10^6
if (is.numeric(xLT)){
mLT = mean(xLT, na.rm = f.na.rm)
sLT = sd(xLT,na.rm = f.na.rm)
cpLT = ss.ca.cp(xLT, LSL, USL, LT = TRUE)
cpiLT = ss.ca.cp(xLT, LSL, USL, LT = TRUE, ci = TRUE, alpha = alpha)
cpkLT = ss.ca.cpk(xLT, LSL, USL, LT = TRUE)
cpkiLT = ss.ca.cpk(xLT, LSL, USL, LT = TRUE, ci = TRUE, alpha = alpha)
zLT = ss.ca.z(xLT, LSL, USL, LT = TRUE)
DPMO <- (1 - pnorm(zLT)) * 10^6
}
else{
mLT=NA
sLT=NA
cpLT=NA
cpiLT=NA
cpkLT=NA
cpkiLT=NA
zLT<-zST-1.5
}
#Order of colours c((Bars & Subtitle), Density ST, Density LT, Target, (Specification
# limits & Title & Frame), Background, Labels, Values)
if(length(f.colours) != 8) {
default <- c("#4682B4","#d1d1e0","#000000","#A2CD5A","#D1EEEE",
"#FFFFFF", "#000000", "#000000")
f.colours <- c(f.colours, default[(length(f.colours) + 1):8])
}
######
.ss.prepCanvas(f.main, f.sub, f.colours)
#grid::grid.rect()##########
vp.plots<-grid::viewport(name="plots",
layout=grid::grid.layout(2,2,c(0.6,0.4),c(0.6,0.4)),
gp = grid::gpar(col = f.colours[7]))
grid::pushViewport(vp.plots)
vp.hist <- grid::viewport(name="hist", layout.pos.row=1, layout.pos.col=1)
grid::pushViewport(vp.hist)
#grid::grid.rect()##########
grid::grid.text("Histogram & Density", y=1, just=c("center", "top") )
##############
binwST <- diff(range(xST))/ sqrt(nST)
ggdata <- reshape2::melt(xST)
qqp <- ggplot(ggdata, aes(x = .data$value))
hist <- qqp + geom_histogram(aes(y = after_stat(density)),
binwidth = binwST,
fill = f.colours[1],
stat = "bin")
xST_density <- density(xST, bw = binwST)
if (!is.na(LSL)){
hist <- hist +
annotate(geom = "text",
x = LSL - abs(max(xST_density$x) - min(xST_density$x)) * 0.02,
y = max(xST_density$y),
label = "LSL",
hjust = 'right',
size = 4)
hist <- hist + expand_limits(x = LSL - (abs(max(xST_density$x) - min(xST_density$x)) * 0.04))
}
hist <- hist + annotate(geom = "text",
x = Target + abs(max(xST_density$x) - min(xST_density$x)) * 0.03,
y = max(xST_density$y) + abs(max(xST_density$y) * 0.3),
label = "Target",
hjust = 'left',
size = 4)
if (!is.na(USL)){
hist <- hist +
annotate(geom = "text",
x = USL + abs(max(xST_density$x) - min(xST_density$x)) * 0.02,
y = max(xST_density$y),
label = "USL",
hjust = 'left',
size = 4)
hist <- hist + expand_limits(x = USL + (abs(max(xST_density$x) - min(xST_density$x)) * 0.04))
}
hist <- hist + xlab(NULL) +
ylab(NULL) +
theme(axis.text.y = element_blank())
if (!is.na(LSL)){
hist <- hist + geom_vline(xintercept = LSL,
linetype = 2,
size = 1,
colour = f.colours[5])
}
if (!is.na(USL)){
hist <- hist + geom_vline(xintercept = USL,
linetype = 2,
size = 1,
colour = f.colours[5])
}
hist <- hist + geom_vline(xintercept = Target,
linetype = 3,
size = 1,
colour = f.colours[4]) +
stat_density(geom="path",
position="identity",
size = 1,
colour = f.colours[2]) +
stat_function(
fun = dnorm,
args = with(ggdata, c(mean(value), sd(value))),
linetype = 2,
size = 1,
colour = f.colours[2]
)
if (is.numeric(xLT)){
binwLT <- diff(range(xLT))/ sqrt(nLT)
ggdataLT <- reshape2::melt(xLT)
hist <- hist +
stat_density(geom="path",
data = ggdataLT,
position = "identity",
colour = f.colours[3]) +
stat_function(
fun = dnorm,
args = with(ggdataLT,
c(mean = mean(value), sd = sd(value))),
linetype=2,
colour = f.colours[3]
)
}
print(hist, newpage=FALSE)
grid::popViewport()
vp.norm<-grid::viewport(name="normal",layout.pos.row=2, layout.pos.col=1,
layout=grid::grid.layout(2,2,c(0.6,0.4),c(0.1, 0.9)))
grid::pushViewport(vp.norm)
grid::grid.text("Check Normality", y=1,just=c("center","top"),
gp = grid::gpar(col = f.colours[7]))
#grid::grid.rect()##########
vp.qq<-grid::viewport(name="qqp",layout.pos.row=2,layout.pos.col=1,
height=unit(0.5,"npc"))
grid::pushViewport(vp.qq)
#grid::grid.rect()##########
qqp <- qplot(sample = xST) +
xlab(NULL) + ylab(NULL) +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank())
print(qqp,newpage=FALSE)
grid::popViewport()
vp.testn<-grid::viewport(name="testn",layout.pos.row=2, layout.pos.col=2)
grid::pushViewport(vp.testn)
ss.ts <- shapiro.test(xST)
ss.tl <- nortest::lillie.test(xST)
if (min(ss.ts$p.value, ss.tl$pvalue) < alpha){
warning("Normality test/s failed")
}
grid::grid.text("Shapiro-Wilk Test", y=.9,just=c("center","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(paste("p-value: ",format(ss.ts$p.value,digits=4)),
gp=grid::gpar(cex=.8, col =f.colours[8]), y=.8)
grid::grid.text("Lilliefors (K-S) Test", gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(paste("p-value: ", format(ss.tl$p.value,digits=4)),
gp=grid::gpar(cex=.8, col =f.colours[8]),y=.4)
grid::popViewport()
grid::grid.text("Normality accepted when p-value > 0.05",y=0.02,
just=c("center","bottom"), gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::popViewport()
vpNumbers<-grid::viewport(name="numbers",
layout.pos.row=c(1,2), layout.pos.col=2,
layout=grid::grid.layout(4,1))
grid::pushViewport(vpNumbers)
grid::grid.rect(gp=grid::gpar(col="#BBBBBB",lwd=2))##########
vpLegend<-grid::viewport(name="legend", layout.pos.row=1)
grid::pushViewport(vpLegend)
grid::grid.rect(gp=grid::gpar(col="#BBBBBB",lwd=2))##########
grid::grid.text(expression(bold("Density Lines Legend")),
y=0.95, just=c("center","top"),
gp = grid::gpar(col = f.colours[7]))
grid::grid.lines(x=c(0.05,0.3), y=c(0.7,0.7), gp=grid::gpar(lty=1, lwd=3, col=f.colours[2]))
grid::grid.text("Density ST", x=0.35, y=0.7,just=c("left","center"),
gp=grid::gpar(cex=0.8, col =f.colours[7]))
grid::grid.lines(x=c(0.05,0.3), y=c(0.55,0.55), gp=grid::gpar(lty=2, lwd=3, col=f.colours[2]))
grid::grid.text("Theoretical Dens. ST", x=0.35, y=0.55,just=c("left","center"),
gp=grid::gpar(cex=0.8, col =f.colours[7]))
if (is.numeric(xLT)){
grid::grid.lines(x=c(0.05,0.3), y=c(0.40,0.40), gp=grid::gpar(lty=1, lwd=1, col=f.colours[3]))
grid::grid.text("Density LT", x=0.35, y=0.40,just=c("left","center"),
gp=grid::gpar(cex=0.8, col =f.colours[7]))
grid::grid.lines(x=c(0.05,0.3), y=c(0.25,0.25), gp=grid::gpar(lty=2, lwd=1, col=f.colours[3]))
grid::grid.text("Theoretical Density LT", x=0.35, y=0.25,just=c("left","center"),
gp=grid::gpar(cex=0.8, col =f.colours[7]))
}
grid::popViewport()
vpSpec<-grid::viewport(name="spec", layout.pos.row=2)
grid::pushViewport(vpSpec)
#grid::grid.rect()#############
grid::grid.text(expression(bold("Specifications")), y=.95, just=c("center","top"),
gp = grid::gpar(col = f.colours[7]))
grid::grid.text(expression(bold("LSL: ")),
y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(LSL, y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("Target: ")),
y=unit(.95,"npc")-unit(2.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(Target, y=unit(.95,"npc")-unit(2.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("USL: ")),
y=unit(.95,"npc")-unit(3.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(USL, y=unit(.95,"npc")-unit(3.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::popViewport()
vpProcess<-grid::viewport(name="proc", layout.pos.row=3,
layout=grid::grid.layout(1,2))
grid::pushViewport(vpProcess)
#grid::grid.rect()##############
grid::grid.lines(x=c(0,1),y=c(1,1), gp=grid::gpar(col="#BBBBBB", lwd=3))
grid::grid.text(expression(bold("Process")), y=.95, just=c("center","top"),
gp = grid::gpar(col = f.colours[7]))
vpSTp<-grid::viewport(layout.pos.col=1)
grid::pushViewport(vpSTp)
grid::grid.text("Short Term",x=0.05, y=.95, just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(expression(bold("Mean: ")), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(sprintf("%.4f",mST), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("SD: ")), y=unit(.95,"npc")-unit(2.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(sprintf("%.4f",sST), y=unit(.95,"npc")-unit(2.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("n: ")), y=unit(.95,"npc")-unit(3.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(nST, y=unit(.95,"npc")-unit(3.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold(Z[s]*": ")), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(sprintf("%.2f",zST), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::popViewport()
vpLTp<-grid::viewport(layout.pos.col=2)
grid::pushViewport(vpLTp)
grid::grid.text("Long Term",x=.95, y=.95, just=c("right","top"), gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(expression(bold("Mean: ")), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
if(!is.na(mLT)){
grid::grid.text(sprintf("%.4f",mLT), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
}
grid::grid.text(expression(bold("SD: ")), y=unit(.95,"npc")-unit(2.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
if(!is.na(sLT)){
grid::grid.text(sprintf("%.4f",sLT), y = unit(.95,"npc") - unit(2.5, "lines"),
just = c("left", "top"),
gp = grid::gpar(cex = .8, col =f.colours[8]))
}
grid::grid.text(expression(bold("n: ")), y=unit(.95,"npc")-unit(3.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(nLT, y=unit(.95,"npc")-unit(3.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold(Z[s]*": ")), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(sprintf("%.2f",zLT), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("DPMO: ")), y=unit(.95,"npc")-unit(5.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(round(DPMO,1), y=unit(.95,"npc")-unit(5.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::popViewport()
grid::popViewport()
vpIndices<-grid::viewport(name="ind", layout.pos.row=4,
layout=grid::grid.layout(1,2))
grid::pushViewport(vpIndices)
#grid::grid.rect()###############
grid::grid.lines(x=c(0,1), y=c(1,1), gp=grid::gpar(col="#BBBBBB",lwd=2))
grid::grid.text(expression(bold("Indices")),y=.95,just=c("center","top"),
gp = grid::gpar(col = f.colours[7]))
vpSTi<-grid::viewport(layout.pos.col=1)
grid::pushViewport(vpSTi)
grid::grid.text("Short Term",x=0.05, y=.95, just=c("left","top"),gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(expression(bold(C[p]*": ")), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(sprintf("%.4f",cpST), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("CI: ")), y=unit(.95,"npc")-unit(3,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.7, col =f.colours[7]))
grid::grid.text(paste("[",paste(sprintf("%.1f",cpiST[1]),sep=""),
",",sprintf("%.1f",cpiST[2]),"]",sep=""),
y=unit(.95,"npc")-unit(3,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.7, col =f.colours[8]))
grid::grid.text(expression(bold(C[pk]*": ")), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(sprintf("%.4f",cpkST), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.8, col =f.colours[8]))
grid::grid.text(expression(bold("CI: ")), y=unit(.95,"npc")-unit(6.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.7, col =f.colours[7]))
grid::grid.text(paste("[",paste(sprintf("%.1f",cpkiST[1]),sep=""),
",",sprintf("%.1f",cpkiST[2]),"]",sep=""),
y=unit(.95,"npc")-unit(6.5,"lines"),
just=c("left","top"),
gp=grid::gpar(cex=.7, col =f.colours[8]))
grid::popViewport()
vpLTi<-grid::viewport(layout.pos.col=2)
grid::pushViewport(vpLTi)
grid::grid.text("Long Term",x=.95, y=.95, just=c("right","top"), gp=grid::gpar(cex=.8, col =f.colours[7]))
grid::grid.text(expression(bold(P[p]*": ")), y=unit(.95,"npc")-unit(1.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
if(!is.na(cpLT)){
grid::grid.text(sprintf("%.4f", cpLT), y = unit(.95, "npc") - unit(1.5, "lines"),
just = c("left", "top"),
gp = grid::gpar(cex = .8, col =f.colours[8]))
}
grid::grid.text(expression(bold("CI: ")), y=unit(.95,"npc")-unit(3,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.7, col =f.colours[7]))
if(!is.na(cpiLT[1])){
grid::grid.text(paste("[", paste(sprintf("%.1f", cpiLT[1]), sep = ""),
",", sprintf("%.1f", cpiLT[2]),"]", sep = ""),
y = unit(.95,"npc") - unit(3, "lines"),
just = c("left", "top"),
gp = grid::gpar(cex = .7, col =f.colours[8]))
}
grid::grid.text(expression(bold(P[pk]*": ")), y=unit(.95,"npc")-unit(4.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.8, col =f.colours[7]))
if(!is.na(cpkLT)){
grid::grid.text(sprintf("%.4f", cpkLT), y = unit(.95, "npc") - unit(4.5, "lines"),
just = c("left", "top"),
gp = grid::gpar(cex = .8, col =f.colours[8]))
}
grid::grid.text(expression(bold("CI: ")), y=unit(.95,"npc")-unit(6.5,"lines"),
just=c("right","top"),
gp=grid::gpar(cex=.7, col =f.colours[7]))
## TODO: see one-side specs
if(!is.na(cpkiLT[1])){
grid::grid.text(paste("[", paste(sprintf("%.1f", cpkiLT[1]), sep = ""),
",", sprintf("%.1f", cpkiLT[2]), "]", sep = ""),
y = unit(.95,"npc") - unit(6.5, "lines"),
just = c("left", "top"),
gp = grid::gpar(cex = .7, col =f.colours[8]))
}
grid::popViewport()
grid::popViewport()
}
#trellis.par.set(standard.theme(color=FALSE))
#ss.study.ca(x,LSL=740, USL=760, T=750, f.sub="Winery Project")