-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbp.R
529 lines (526 loc) · 22.3 KB
/
bp.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
############################################################################
############################################################################
############################################################################
# the bucket plot
# TO DO
############################################################################
############################################################################
############################################################################
# Fernanda De Bastiani, Mikis Stasinopoulos and Bob Rigby
############################################################################
############################################################################
############################################################################
bp <- function ( obj = NULL, # this can be a variable or gamlss model or a list of both types
weights = NULL, # this needs to be checked
type = c("moment", "centile.central", "centile.tail"),
xvar = NULL, # two version simple or formula
bootstrap = TRUE, # whether to plot it
no.bootstrap = 99, # the number of bootstrap samples
col.bootstrap = c("lightblue", "pink", "khaki","thistle", "tan", "sienna1", "steelblue", "coral", "gold", "cyan"), # taken fro colors()
pch.bootstrap = rep(21,10), # design up to 10 the point type of bootstrap samples
asCharacter = TRUE, # whether to plot name or point
col.point = rep("black", 10), # the colour of the plotted point or text
pch.point = 1:10, #
lwd.point = 2, #
text.to.show = NULL, # which text to show, the character of the y or something else
cex.text = 1.5, # size of text
col.text = "black", # color of text
show.legend = FALSE, # adding the legend this do not apply for multiple bp
n.inter = 4, # numner of cuts only for multiple bp
xcut.points = NULL, # if providing cuts only for multiple bp
overlap = 0, # if you overlaping the intervals only for multiple bp
show.given = TRUE, # only for multiple bp whether to show bars
cex = 1, # pass it to coplot()
pch = 21, # pass it to coplot()
data = NULL,
bar.bg = c(num ="lightblue", fac="pink"),# colour or bars
...) # argument for coplot()
{
#############################################################################
#############################################################################
# local functions
# i) momBucket(): to draw the moment bucket used by panel.fun()
# ii) draw.Jarque.Bera(): used by panel.fun()
# iii) CI95() used by draw.Jarque.Bera()
# iv) panel.fun(): used by bp() in coplot()
# v) check.overlap(): used by bp()
# vi) get.intervals(): used by bp()
# vii) deparen(): used by bp()
##############################################################################
##############################################################################
# FUNCTION 1
# This function is used by panel.fun() to draw the moment bucket
momBucket <- function(x)
{
n <- length(x)
boundary <- function(lty = 1, lwd = 2, col = 1){}
fEGB2_1 <- function(x, deriv = 0L){}
fEGB2_2 <- function(v){}
fJSU <- function(x, deriv = 0L){}
fSEP3 <- function(x, deriv = 0L){}
fST3_1 <- function(x, deriv = 0L){}
fST3_2 <- function(x, deriv = 0L){}
fSHASHo <- function(x, deriv = 0L){}
load(system.file("doc", "MomentSkewKurt1.RData", package="gamlss.dist"))
# logNO-JSU
curve(fJSU, 0,1, ylim=c(-1,1), xlim=c(-1,1), xlab="transformed moment skewness",
ylab="transformed moment kurtosis", col=gray(.7), lwd=2, lty=2, add=TRUE)
flipfJSU <- function(x) fJSU(-x)
curve( flipfJSU, -1,0, add=TRUE, col=gray(.7), lwd=2, lty=2)
# SHASHo
curve(fSHASHo, 0.001,1, lty=3, col=gray(.4), lwd=2, add=TRUE)
flipfSHASHo <- function(x) fSHASHo(-x)
curve( flipfSHASHo, -1,-0.001, add=TRUE, lty=3, col=gray(.4), lwd=2)
# SEP3
curve(fSEP3, 0.01,1, lty=4, col=gray(.6), lwd=2, add=TRUE)
flipfSEP3 <- function(x) fSEP3(-x)
curve(flipfSEP3, -1,-0.01, lty=4, col=gray(.6), lwd=2, add=TRUE)
# ST3
curve(fST3_2, 0.5,1, lty=5, col=gray(.8), lwd=2,add=TRUE)
flipfST3_2 <- function(x) fST3_2(-x)
curve(flipfST3_2, -1,-0.5, lty=5, col=gray(.8), lwd=2, add=TRUE)
curve(fST3_1, 0,.49, add=TRUE, lty=5, col=gray(.8), lwd=2)
flipfST3_1 <- function(x) fST3_1(-x)
curve(flipfST3_1, -0.49,0, lty=5, col=gray(.8), lwd=2, add=TRUE)
# EGB2
curve(fEGB2_1, 0, .6666, lty=6, col=gray(.5), lwd=2, add=TRUE)
flipfEGB2_1 <- function(x) fEGB2_1(-x)
curve(flipfEGB2_1, -0.6666, 0, lty=6, col=gray(.5), lwd=2, add=TRUE)
curve(fEGB2_2 , 0.0, .6666, lty=6, col=gray(.5), lwd=2, add=TRUE)
flipfEGB2_2 <- function(x) fEGB2_2(-x)
curve(flipfEGB2_2, -0.6666, 0, lty=6, col=gray(.5), lwd=2, add=TRUE)
# local
boundary()
# local function
boundaryR<-function()
{
tskew<-seq(0,0.99999,length=101)
# tskew<-seq(-0.99999,0,length=1000)
skew <- tskew/(1-tskew)
kurt <- 1 + (skew^2)
ekurt <- kurt - 3
tkurt <- ekurt/(1+abs(ekurt))
lines(tkurt~I(-tskew), type="l", lty=1, lwd=2, col=1)
}
boundaryR()
grid()
lines(c(-1,1), c(1,1), lwd=2)
lines(c(-1,1), c(1,1), lwd=2)
}
##############################################################################
##############################################################################
# FUNCTION 2
# This function is used by panel.fun() to draw the boundaries of Jarque.Bera
draw.Jarque.Bera <- function(n)
{
xx <- seq(0, 0.99, length = 101)
y1 <- CI95(xx, n=n)
y2 <- CI95.2(-xx, n=n)
y3 <- CI95.3(-xx, n=n)
y4 <- CI95.4(xx, n=n)
xy <- na.omit(data.frame(x = c(xx, xx[101:1], -xx, -xx[101:1]),
y = c(y1, y4[101:1], y3, y2[101:1])))
polygon(xy$x, xy$y, lty = 11, col = gray(0.97))
}
##############################################################################
##############################################################################
# FUNCTION 3
# used by draw.Jarque.Bera
CI95 <- function(x,n) {
if (any(abs(x) >= 1))
stop(" x should be in (-1,1)")
gamma.1 <- x/(1 - x)
gamma.2 <- ((24/n) * (qchisq(0.95, df = 2) - (n/6) *
gamma.1^2))^0.5
gamma.2t <- gamma.2/(1 + abs(gamma.2))
gamma.2t
}
CI95.2 <- function(x,n) CI95(-x,n)
CI95.3 <- function(x,n) -CI95(-x,n)
CI95.4 <- function(x,n) -CI95(x,n)
##############################################################################
##############################################################################
# FUNCTION 4 This is the important function
panel.fun <- function (x, y, ...)
{
id <- get("id", envir = parent.frame(1))
n <- length(y)
# N <- length(id)
# if ((n/N)*100 <1) warning("only ", n, " out of ", N, " observations are in this panel \n")
# if moment ##################################################################
if (type=="moment")
{
momBucket(Y[[1]]) # draw the bucket
draw.Jarque.Bera(n)
for (i in 1:K)
{
y <- Y[[i]][id]
w <- W[[i]][id]
if (bootstrap)
{
for (j in 1:no.bootstrap)
{
ind <- sample.int(n, n, replace = TRUE)
sk <- momentSK(y[ind], weights=w[ind])
points(sk$trans.mom.skew, sk$trans.mom.kurt, pch=pch.bootstrap[i] ,
col=col.bootstrap[i])
}
}
}
# this loop is repeated here for the symbols to be clear
for (i in 1:K)
{
y <- Y[[i]][id]
w <- W[[i]][id]
sk <- momentSK(y, weights=w)
if (asCharacter)
text(sk$trans.mom.skew, sk$trans.mom.kurt, text.to.show[i], cex=cex.text, col=col.text )
else
points(sk$trans.mom.skew, sk$trans.mom.kurt, col=col.point[i], pch=pch.point[i],
lwd=lwd.point)
text(-0.9,-0.9, n)
}
}
# end if moment ##############################################################
# if centile central##########################################################
if (type=="centile.central")
{
id <- get("id", envir = parent.frame(1))
n <- length(y)
cenCentralBucket() # draw the bucket
for (i in 1:K)
{
y <- Y[[i]][id]
w <- W[[i]][id]
if (bootstrap)
{
for (j in 1:no.bootstrap)
{
ind <- sample.int(n, n, replace = TRUE)
sk <- centileSK(y[ind], weights=w[ind])
points(sk$S0.25, sk$trans.K0.01, pch=pch.bootstrap[i], col=col.bootstrap[i])
}
}
}
# this loop is repeated here for the symbols to be clear
for (i in 1:K)
{
y <- Y[[i]][id]
w <- W[[i]][id]
sk <-centileSK(y, weights=w)
text(-0.9,-0.9, n)
if (asCharacter)
text(sk$S0.25, sk$trans.K0.01, text.to.show[i], cex=cex.text, col=col.text )
else
points(sk$S0.25, sk$trans.K0.01, col=col.point[i], pch=pch.point[i],
lwd=lwd.point)
}
}
# end centile central#########################################################
# if centile tailt ###########################################################
if (type=="centile.tail")
{
id <- get("id", envir = parent.frame(1))
n <- length(y)
cenTailBucket() # draw the bucket
for (i in 1:K)
{
y <- Y[[i]][id]
w <- W[[i]][id]
if (bootstrap)
{
for (j in 1:no.bootstrap)
{
ind <- sample.int(n, n, replace = TRUE)
sk <- centileSK(y[ind], weights=w[ind])
points(sk$S0.01, sk$trans.K0.01, pch=pch.bootstrap[i], col=col.bootstrap[i])
}
}
}
for (i in 1:K)
{
y <- Y[[i]][id]
w <- W[[i]][id]
sk <-centileSK(y, weights=w)
text(-0.9,-0.9, n)
if (asCharacter)
text(sk$S0.01, sk$trans.K0.01, text.to.show[i], cex=cex.text, col=col.text )
else
points(sk$S0.01, sk$trans.K0.01, col=col.point[i], pch=pch.point[i],
lwd=lwd.point)
}
}
}
# if centile tail ###############################################
##############################################################################
##############################################################################
# FUNCTION 5
check.overlap <- function(interval)
{
if (!is.matrix(interval) ) {stop(paste("The interval specified is not a matrix."))}
if (dim(interval)[2] !=2) {stop(paste("The interval specified is not a valid matrix.\nThe number of columns should be equal to 2."))}
crows = dim(interval)[1]
for (i in 1:(crows-1))
{
#if (interval[i,2] != interval[i+1,1]) {interval[i+1,1]=interval[i,2]}
if (!(abs(interval[i,2]-interval[i+1,1])<0.0001)) {interval[i+1,1]=interval[i,2]}
}
return(interval)
}
##############################################################################
##############################################################################
# FUNCTION 6
# the problem here is that coplot uses for given.values
# MS Tuesday, September 21, 2004
# min <= x <= 20 min <= x < 20 min <= x <= 20-extra
# 20 <= x <= 30 instead of 20 <= x < 30 here uses 20 <= x <= 30-extra
# 30 <= x <= max 30 <= x <= max 30 <= x <= max+extra
get.intervals <- function (xvar, xcut.points )
{
if (!is.vector(xcut.points)) {stop(paste("The interval is not a vector."))}
if ( any((xcut.points < min(xvar)) | any(xcut.points > max(xvar))))
{stop(paste("The specified `xcut.points' are not within the range of the x: (", min(xvar),
" , ", max(xvar), ")"))}
extra <- (max(xvar)-min(xvar))/100000
int <- c(min(xvar), xcut.points, (max(xvar)+2*extra))
ii <- 1:(length(int)-1)
r <- 2:length(int)
x1 <- int[ii]
xr <- int[r]-extra
if (any(x1>xr)) {stop(paste("The interval is are not in a increasing order."))}
cbind(x1,xr)
}
################################################################################
################################################################################
# FUNCTION 7
# this function comes from coplot() to help to get the variables used if more that one xvar is used
deparen <- function(expr)
{
while (is.language(expr) && !is.name(expr) && deparse(expr[[1L]])[1L] ==
"(") expr <- expr[[2L]]
expr
}
###############################################################################
###############################################################################
# FUNCTION 8
cenCentralBucket <- function()
{
cEGB2_1 <- cEGB2_2 <-tEGB2_1 <-tEGB2_2 <- cJSU <- tJSU <-
tST3_1 <- tST3_2 <-function (x, deriv = 0L) {}
cSB <- tSB <- cSEP3 <- tSEP3 <- cSHASH <- tSHASH <- cST3_1 <-
cST3_2 <- function (x, deriv = 0L) {}
cEGB2_1_data <- cEGB2_2_data <- data.frame( cskew=0, ckurt=0)
load(system.file("doc", "CentileSkewKurt.RData", package="gamlss.dist"))
curve(cSEP3, 0.01,.99, ylim=c(-1,1), xlim=c(-1,1), xlab="central centile skewness",
ylab="transformed centle kurtosis",
lty=4, col=gray(.6), lwd=2, add=TRUE)
flipcSEP3 <- function(x) cSEP3(-x)
curve( flipcSEP3, -1,-0.01, add=TRUE, lty=4, col=gray(.6), lwd=2)
curve(cST3_2, 0.1445, 1, add=T, lty=5, col=gray(.8), lwd=2)
curve(cST3_1, 0, 0.1441, add=T, lty=5, col=gray(.8), lwd=2)
flipcST3_2 <- function(x) cST3_2(-x)
curve(flipcST3_2, -1, -0.144, add=T, lty=5, col=gray(.8), lwd=2)
flipcST3_1 <- function(x) cST3_1(-x)
curve(flipcST3_1, -0.1441,0, add=T, lty=5, col=gray(.8), lwd=2)
curve(cJSU, 0.01, .99, add=T, lty=2, col=gray(.7), lwd=2)
flipcJSU <- function(x) cJSU(-x)
curve(flipcJSU, -.99, -0.01, add=T, lty=2, col=gray(.7), lwd=2)
curve(cSHASH, 0, .965, add=T, lty=3, col=gray(.4), lwd=2)
flipcSHASH <- function(x) cSHASH(-x)
curve(flipcSHASH, -.965, 0, add=T, lty=3, col=gray(.4), lwd=2)
#lines(cEGB2_1Data$cskew,cEGB2_1Data$ckurt, lty=6, col=gray(.5), lwd=2)
#lines(-cEGB2_1Data$cskew,cEGB2_1Data$ckurt, lty=6, col=gray(.5), lwd=2)
lines(cEGB2_1_data$cskew,cEGB2_1_data$ckurt, lty=6, col=gray(.5), lwd=2)
lines(-cEGB2_1_data$cskew,cEGB2_1_data$ckurt, lty=6, col=gray(.5), lwd=2)
lines(cEGB2_2_data$cskew[c(-1,-2)],cEGB2_2_data$ckurt[c(-1,-2)], lty=6, col=gray(.5), lwd=2)
lines(-cEGB2_2_data$cskew[c(-1,-2)],cEGB2_2_data$ckurt[c(-1,-2)], lty=6, col=gray(.5), lwd=2)
# curve(cEGB2_2, 0, 0.26, add=T,lty=6, col=gray(.5), lwd=2)
# flipcEGB2_2 <- function(x) cEGB2_2(-x)
# curve(flipcEGB2_2, -0.26, 0, add=T,lty=6, col=gray(.5), lwd=2)
# lines(c(-0.26,-0.26), c(0.5078402, 0.5754391), col=gray(.5), lty=6, lwd=2)
curve(cSB, 0, 0.99, add=T, lty=7, col=gray(.9), lwd=2)
flipcSB <- function(x) cSB(-x)
curve(flipcSB, -0.99, 0, add=T, lty=7, col=gray(.9), lwd=2)
lines(c(-1,1), c(1,1), lwd=2)
grid()
}
###############################################################################
###############################################################################
# FUNCTION 9
cenTailBucket <- function()
{
cEGB2_1 <- cEGB2_2 <-tEGB2_1 <-tEGB2_2 <- cJSU <- tJSU <-
tST3_1 <- tST3_2 <-function (x, deriv = 0L) {}
cSB <- tSB <- cSEP3 <- tSEP3 <- cSHASH <- tSHASH <- cST3_1 <-
cST3_2 <- function (x, deriv = 0L) {}
cEGB2_1_data <- cEGB2_2_data <- data.frame( cskew=0, ckurt=0)
load(system.file("doc", "CentileSkewKurt.RData", package="gamlss.dist"))
curve(tSEP3, 0.01,.99, ylim=c(-1,1), xlim=c(-1,1), xlab="tail centile skewness",
ylab="transformed centle kurtosis",
lty=4, col=gray(.6), lwd=2, add=TRUE)
fliptSEP3 <- function(x) tSEP3(-x)
curve( fliptSEP3, -1,-0.01, add=TRUE, lty=4, col=gray(.6), lwd=2)
curve(tSHASH, 0, .996, add=TRUE, lty=3, col=gray(.4), lwd=2)
fliptSHASH <- function(x) tSHASH(-x)
curve(fliptSHASH, -.996,0, add=T, lty=3, col=gray(.4), lwd=2)
curve(tST3_2, 0.484, 1, add=TRUE, lty=5, col=gray(.8), lwd=2)
fliptST3_2 <- function(x) tST3_2(-x)
curve(fliptST3_2, -1, -0.484, add=T, lty=5, col=gray(.8), lwd=2)
curve(tST3_1, 0, 0.482, add=TRUE, lty=5, col=gray(.8), lwd=2)
fliptST3_1 <- function(x) tST3_1(-x)
curve(fliptST3_1, -0.482, 0, add=T, lty=5, col=gray(.8), lwd=2)
curve(tJSU, 0.01 ,0.99, add=T, lty=2, col=gray(.7), lwd=2)
fliptJSU <- function(x) tJSU(-x)
curve(fliptJSU, -0.99, -0.01, add=T, lty=2, col=gray(.7), lwd=2)
curve(tEGB2_1, 0, 0.70, add=T, lty=6, col=gray(.5), lwd=2)
fliptEGB2_1 <- function(x) tEGB2_1(-x)
curve(fliptEGB2_1, -0.70, 0, add=T, lty=6, col=gray(.5), lwd=2)
curve(tEGB2_2, 0, 0.70, add=T, lty=6, col=gray(.5), lwd=2)
fliptEGB2_2 <- function(x) tEGB2_2(-x)
curve(fliptEGB2_2, -0.70, 0, add=T, lty=6, col=gray(.5), lwd=2)
curve(tSB, 0,1, add=T, lty=7, col=gray(.9), lwd=2)
fliptSB <- function(x) tSB(-x)
curve(fliptSB, -1,0, add=T, lty=7, col=gray(.9), lwd=2)
grid()
lines(c(-1,1), c(1,1), lwd=2)
}
# enf of lcal functions
###############################################################################
###############################################################################
###############################################################################
###############################################################################
##-----------------------------------------------------------------------------
##-here is the main function --------------------------------------------------
##-----------------------------------------------------------------------------
###############################################################################
###############################################################################
###############################################################################
###############################################################################
type <- match.arg(type)
## get residuals
# check whether a list
#DataExist <- FALSE
K <- 1L
Y <- n <- W <-list()
if (is(obj,"list"))
{
K <- length(obj)
for (i in 1L:K)
{
Y[[i]] <- if (is(obj[[i]],"gamlss")) resid(obj[[i]])
else obj[[i]]
W[[i]] <- if (is(obj[[i]],"gamlss")) obj[[i]]$weight
else if (is.null(weights)) rep(1, length(Y[[i]])) else weights[[i]]
n[[i]] <- length(Y[[i]])
NAMES <- paste(substitute(obj))[-1]
}
} else
{
Y[[1L]] <- if (is(obj,"gamlss")) resid(obj)
else obj
W[[1L]] <- if (is(obj,"gamlss")) obj$weights
else if (is.null(weights)) rep(1L, length(obj)) else weights
n[1L] <- length(Y[[1L]])
NAMES <- paste(substitute(obj))
}
text.to.show <- if (is.null(text.to.show)) NAMES else text.to.show
##----------------------------------------------------------------------------
##############################################################################
##############################################################################
##----------------------------------------------------------------------------
# case 1 no x-variable then just somple plot
if(is.null(xvar)) # if xvar=NULL
{
for (i in 1L:K)
{
if (i==1L) add <- FALSE else add <- TRUE
#if (asCharacter==TRUE)
# text.to.show <-if (K>1L) paste(substitute(obj)[[1L+i]]) else paste(substitute(obj))
if (type=="moment")
{
out <-checkMomentSK(Y[[i]], weights=W[[i]],
add = add, bootstrap = bootstrap, no.bootstrap = no.bootstrap,
col.bootstrap = col.bootstrap[i], pch.bootstrap = pch.bootstrap[i],
asCharacter = asCharacter, col.point = col.point[i] , pch.point = pch.point[i],
lwd.point = lwd.point, text.to.show = text.to.show[i], cex.text = cex.text,
col.text = col.text, show.legend = show.legend)
}
if (type=="centile.central")
{
out <-checkCentileSK(Y[[i]], weights=W[[i]], type='central',
add = add, bootstrap = bootstrap, no.bootstrap = no.bootstrap,
col.bootstrap = col.bootstrap[i], pch.bootstrap = pch.bootstrap[i],
asCharacter = asCharacter, col.point = col.point[i] , pch.point = pch.point[i],
lwd.point = lwd.point, text.to.show = text.to.show[i], cex.text = cex.text,
col.text = col.text, show.legend = show.legend)
}
if (type=="centile.tail")
{
out <-checkCentileSK(Y[[i]], weights=W[[i]], type='tail',
add = add, bootstrap = bootstrap, no.bootstrap = no.bootstrap,
col.bootstrap = col.bootstrap[i], pch.bootstrap = pch.bootstrap[i],
asCharacter = asCharacter, col.point = col.point[i] , pch.point = pch.point[i],
lwd.point = lwd.point, text.to.show = text.to.show[i], cex.text = cex.text,
col.text = col.text, show.legend = show.legend)
}
}
return(invisible(out))
}
##----------------------------------------------------------------------------
##############################################################################
##############################################################################
##----------------------------------------------------------------------------
## get data if exist
if (!is.null(data)) Data <- data
form <- if (is(xvar,"formula")) {as.formula(paste0("y.y~x.x|", as.character(xvar))[2])}
else {as.formula(paste0("y.y~x.x|", deparse(substitute(xvar))))}
## get weights
y.y <- Y[[1L]]
x.x <- W[[1L]]
## if w=0 reduce if w=freq expand if all(w=1L) same
## here we need the xvar
#if (all(trunc(w)==w)) xvar <- rep(xvar, w)
if (!is(xvar,"formula"))
{
if(is.null(xcut.points))
{ # getting the intervals automatic
if (is(xvar,"factor")) stop("factors should be used with formula, i.e. ~f1")
given.in <- co.intervals(xvar, number=n.inter, overlap=overlap )
if (overlap==0) given.in <- check.overlap(given.in)
}
else
{ # if xcut.points is set
given.in <- get.intervals(xvar, xcut.points )
}
coplot(form,
given.values = given.in,
panel = panel.fun,
ylim = c(-1, 1),
xlim = c(-1, 1),
ylab = "skewness",
xlab = "kurtosis",
show.given = show.given,
pch = pch,
cex = cex,
bar.bg = bar.bg ,...)
return(invisible())
} else
{
coplot(form,
# given.values = given.in,
panel = panel.fun,
ylim = c(-1, 1),
xlim = c(-1, 1),
ylab = "skewness",
xlab = "kurtosis",
show.given = show.given,
pch = pch,
cex = cex,
number = n.inter,
bar.bg = bar.bg ,...)
return(invisible())
}
}#--------------------------------------------------------- END FUNCTION
#############################################################################
#############################################################################
#############################################################################