An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120310/79fb515d/attachment.pl>
How to fit a line through the "Mountain crest", i.e., through the highest density of points - in a "loess-like" fashion.
3 messages · Emmanuel Levy, David Winsemius
On Mar 10, 2012, at 3:55 PM, Emmanuel Levy wrote:
Hi, I'm trying to normalize data by fitting a line through the highest density of points (in a 2D plot). In other words, if you visualize the data as a density plot, the fit I'm trying to achieve is the line that goes through the "crest" of the mountain.
Are you familiar with the kde2d of bkde2D functions in various packages? If you then collected the max density for each X and Y you might want to see whether that 2-d function would follow a sufficiently regular path that would represent the projection of the ridge on the z=0 plane.
This is similar yet different to what LOESS does.
Do you want a curve or a line?
I've been using loess before, but it does not exactly that as it takes into account all points. Although points farther from the fit have a smaller weight, they result in the fit being a bit off the crest. Do you know a package or maybe even an option in loess that would allow me achieve this?
I don't. I happen to have a dataset where I could test it. But you are likely to get better responses if you provide a test case.
Any advice or idea appreciated. Emmanuel [[alternative HTML version deleted]]
Plain text is preferred.
David Winsemius, MD West Hartford, CT
Hi, Thanks a lot for your reply - I posted a second message where I provide a "dummy" example, entitled "How to improve the robustness of "loess"? - example included". I need to fit a curve which makes it a bit difficult to work with kde2d only. I'm actually trying to use kde2d in combination with loess - basically I give the output density of kde2d as weights in the "loess" function. It seems to give nice results :) In my second post I wrote that the "weight" option did not work but that's because I was writing "weigth" - not sure why I did not get an error message. I'll post the lines of code as a reply to the second post. All the best, Emmanuel
On 10 March 2012 19:46, David Winsemius <dwinsemius at comcast.net> wrote:
On Mar 10, 2012, at 3:55 PM, Emmanuel Levy wrote:
Hi, I'm trying to normalize data by fitting a line through the highest density of points (in a 2D plot). In other words, if you visualize the data as a density plot, the fit I'm trying to achieve is the line that goes through the "crest" of the mountain.
Are you familiar with the kde2d of bkde2D functions in various packages? If you then collected the max density for each X and Y you might want to see whether that 2-d function would follow a sufficiently regular path that would represent the projection of the ridge on the z=0 plane.
This is similar yet different to what LOESS does.
Do you want a curve or a line?
I've been using loess before, but it does not exactly that as it takes into account all points. Although points farther from the fit have a smaller weight, they result in the fit being a bit off the crest. Do you know a package or maybe even an option in loess that would allow me achieve this?
I don't. I happen to have a dataset where I could test it. But you are likely to get better responses if you provide a test case.
Any advice or idea appreciated.
Emmanuel
[[alternative HTML version deleted]]
Plain text is preferred. -- David Winsemius, MD West Hartford, CT