[R] Closest fit data to a particular formula

David david at serendipityscience.com
Tue Nov 20 05:58:31 CET 2012


R folks,
  I am somewhat new to R and have started to stumble...
  I have a set of data that I am trying to model, so that I can predict on
a much larger set - and I have been using loess to get a model.. but it is
not what I would like to see.  For instance, I know from the nature of the
data that the shape of this line should only decrease, and yet the loess is
being affected by the sample outliers at 1100.  What I am interested in is
the "best fit" of the sample data to a formula that I supply it.  Reading
the documentation for loess - it seems that I can do this by supplying a
formula.. but I have not had much luck.  Perhaps I am reading the
documentation incorrectly.  Here is my current loess line code:

mg.lo = loess(y ~ x, mg, span=0.25)
mg$x_c <- predict(mg.lo)

which produces a curve like the attached file loess_curve.png.

and I would like to have a curve "something like" the arccot in the
attached file arccotangent.png (from wikipedia), but all x values are
positive - meaning just the best fit of the sample data to that type of
curve.. starts high and finishes low but doesn't go below zero and only
decreases.  Looking at the arccot(x) definition I can see it as:

arccot x = pi/2 - atan(x)

So I tried to apply variations of that to the loess first "formula"
parameter with underwhelming results.

Am I even remotely on the right track?  Can loess get me there?  If not -
another function?

Any and all comments would be greatly appreciated.

David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loess_curve.png
Type: image/png
Size: 31940 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121119/856d4157/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arccotangent.png
Type: image/png
Size: 11740 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121119/856d4157/attachment-0001.png>


More information about the R-help mailing list