[R] Interpolate through NAs using monotonic smoothing spline

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Oct 24 02:31:42 CEST 2014


A very limited set of attachment types are allowed on this list.. yours was not one of them. Reading the Posting Guide will inform you about many useful things.

Self-contained R code is the expected mode of communication here.

>From your description, you might consider monotonic spline fitting the diff() of your data and integrating the fitted result... but without your sample plots I could be way off.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On October 23, 2014 9:35:28 AM PDT, Ingrid Charvet <Ingrid.Charvet at rms.com> wrote:
>In the figure attached "test", I would like to interpolate the empty -
>"NA" section to connect the two curves.
>
>1/ I tried using "na.approx" and "na.spline", without success.
>
>na.approx(test,na.rm=FALSE)
>na.spline(test,na.rm=FALSE)
>
>In the first case it just draws a straight line between the end and
>beginning points of each curve, respectively, which doesn't look
>smooth. In the second case the cubic spline interpolation results
>overshoot above 1.0 which I would like to avoid (see attached test.na)
>.
>
>2/ I have also used  splinefun for a monotonic increasing spline, which
>is the best result so far
>Yfun <- splinefun(X,test,method="monoH.FC")
>test.spline <- Yfun(X)
>
>however the resulting curve displays a "kink" at the limit of the
>interpolation zone (see attached figure test.splinefun).
>
>is there a way to constrain the spline in na.spline in 1/, for example,
>to force it to be monotonic strictly increasing?
>Alternatively can we alter the smoothing performed by splinefun somehow
>to avoid this "kink"?
>
>Any other suggestions welcome!
>Thank you
>IC
>
>
>________________________________
>This message and any attachments contain information that may be RMS
>Inc. confidential and/or privileged. If you are not the intended
>recipient (or authorized to receive for the intended recipient), and
>have received this message in error, any use, disclosure or
>distribution is strictly prohibited. If you have received this message
>in error, please notify the sender immediately by replying to the
>e-mail and permanently deleting the message from your computer and/or
>storage system.
>
>
>
>
>------------------------------------------------------------------------
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list