[R] intervals from cut() as numerics?
Gavin Simpson
gavin.simpson at ucl.ac.uk
Sat May 20 11:01:04 CEST 2006
Hi,
Given some example data:
dat <- seq(4, 7, by = 0.05)
x <- sample(dat, 30)
y <- sample(dat, 30)
error <- x - y
I have broken the rage of x into 10 groups and I can calculate the bias
(mean(error)) for each of these 10 groups:
groups <- cut(x, breaks = 10)
max.bias <- aggregate(error, list(group = groups), mean)
max.bias
group x
1 (4,4.3] -0.7750000
2 (4.3,4.6] -0.9750000
3 (4.6,4.9] -0.6750000
4 (4.9,5.2] -0.9125000
5 (5.2,5.5] 1.0500000
6 (5.5,5.8] 0.3166667
7 (5.8,6.1] 0.1375000
8 (6.1,6.4] 1.1833333
9 (6.4,6.7] 0.2500000
10 (6.7,7] 1.7000000
Which is fine. Now I am producing a plot of the residuals vs observed
and I want to draw line segments from e.g. (4,4.3] at height =
-0.7750000, but for all 10 groups, like so:
plot(x, error, type = "n")
abline(h = 0, col = "grey")
panel.smooth(x, error)
arrows(4, -0.775, 4.3, -0.775, length = 0.05, angle = 90, code = 3)
The problem is getting the range/interval for each group from (4,4.3],
so I can automate this.
Anyone think of a way to do this - happy to change the way the groups
are generated if cut() is not the right tool for the job here.
Many thanks,
Gav
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
*Note new Address and Fax and Telephone numbers from 10th April 2006*
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [t] +44 (0)20 7679 0522
ECRC [f] +44 (0)20 7679 0565
UCL Department of Geography
Pearson Building [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street
London, UK [w] http://www.ucl.ac.uk/~ucfagls/cv/
WC1E 6BT [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list