Objective:
Given a set of data, how can I determine if a new data point is above or below the line connecting the points.
For example, how can I determine if the red point shown is above or below the line (without visual inspection)?
I'd like to fit an exact line to the points. Essentially joining the points, and need a fit to be able to use any point on the line for a comparator.
Current attempts:
So far I've tried fitting various splines to the data, but it is still a bit too smooth. I'm really looking for an exact fit to the data, sharp corners and all.
I've tried a natural spline (as well as smooth.splines), but can't quite get the fit exact/sharp enough:
plot(df$lowerx, df$lowery, type='b', xlab='x', ylab='y', pch=21, bg='steel blue')
myspline <- splinefun(df$lowerx, df$lowery, method='natural')
curve(myspline, add=T, from = 0, to=140, n = 100, col='green')
I think once I get the fit right it will be straightforward use it to figure out if points are above or below the line (e.g. using predict or the function), but I need help with the fit.
Also would welcome another approach entirely.
Data:
df <- structure(list(lowerx = c(11.791, 18.073, 23.833, 35.875, 39.638, 44.153, 59.206, 71.498, 83.289, 95.091, 119.676, 131.467, 143.76), lowery = c(5.205, 5.89, 6.233, 9.041, 10, 10.342, 12.603, 13.493, 14.658, 15.274, 15.89, 15.616, 15.342)), .Names = c("lowerx", "lowery"), class = "data.frame", row.names = c(NA, -13L))