On Sat, 27 Jul 2013, Mark Knecht <markkne...@gmail.com> writes: > For the sake of asking here assume I have 5 models that attempt to > predict a pair of future values like tomorrow's high & low. The > predictions are placed in a matrix with the low prediction in column 1 > and the high prediction in column 2. _IF_ there is an intersection of > all 5 predictions then I can test for that using the simple equation > in Range1. However if there is a prediction that's a complete outlier > as is Pred2[4,] then the simple equation fails and says the high is > less than the low. > > Are there any R packages that automatically handle simple intersection > problems like this? My real goals include things like probability > distributions across the ranges, but for now I'm just looking for > what's out there? > > Thanks, > Mark > > > Pred1 = matrix(data=NA, nrow=5, ncol=2) > Pred1[1,] = c(100,110) > Pred1[2,] = c(88,125) > Pred1[3,] = c(92,120) > Pred1[4,] = c(25,105) > Pred1[5,] = c(91,121) > > Range1 = c(max(Pred1[,1]), min(Pred1[,2])) > Range1 > > Pred2 = matrix(data=NA, nrow=5, ncol=2) > Pred2[1,] = c(100,110) > Pred2[2,] = c(88,125) > Pred2[3,] = c(92,120) > Pred2[4,] = c(25,70) #outlier - the high is too low > Pred2[5,] = c(91,121) > > Range2 = c(max(Pred2[,1]), min(Pred2[,2])) > Range2 >
Yes, taking the intersection "fails" because in the second case the intersection is empty. So /you/ will have to decide how you want to handle such cases. Perhaps remove the outlier, or use some majority rule to find a "most likely" outcome (according to your preditions). For instance, you could count how often a given price falls in the range of any of the models. ind <- function(x, min, max) { s <- numeric(length(x)) for (i in seq_along(min)) s <- s + as.integer(x >= min[i] & x <= max[i]) s } x <- seq(0, 130, by = 0.5) s <- ind(x, Pred2[ ,1], Pred2[ ,2]) plot(x, s, type = "S") range(ca <- x[s == max(s)]) ## "consensus area" all.equal(max(diff(ca)), diff(x)[1L]) ## single area? Regards, Enrico -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.