1
2# produce plot of data with horizontal arrows representing
3# certain grouping data.  Get info by using strapply to extract
4# it from the labels of cut
5# based on
6# https://www.stat.math.ethz.ch/pipermail/r-help/2006-May/106042.html
7# with various iterations by G. Grothendieck, Berwin Turlach and Gavin Simpson
8
9set.seed(1)
10dat <- seq(4, 7, by = 0.05)
11x <- sample(dat, 30)
12y <- sample(dat, 30)
13
14## residuals
15error <- x - y
16## break range of x into 10 groups
17
18groups <- cut(x, breaks = 10)
19
20##calculate bias (mean) per group
21max.bias <- tapply(error, groups, mean)
22
23## convert cut intervals into numeric matrix
24library(gsubfn)
25interv <- strapply(levels(groups), "[[:digit:].]+", as.numeric, simplify = TRUE)
26
27## plot the residuals vs observed
28plot(x, error, type = "n")
29abline(h = 0, col = "grey")
30panel.smooth(x, error)
31
32## add bias indicators per group
33arrows(interv[1,], max.bias, interv[2,], max.bias,
34      length = 0.05, angle = 90, code = 3)
35
36