[R] Find inflection points using smooth.spline
Ravi Varadhan
rvaradhan at jhmi.edu
Sun Mar 29 16:46:26 CEST 2009
Hi,
Here is another approach:
set.seed(123)
x <- sort(runif(200))
y <- sin(3*pi*x) + rnorm(200, sd=0.1)
smspl <- smooth.spline(x, y)
d2 <- function(x) predict(smspl, x , deriv=2)$y
x <- seq(0, 1, length=500)
plot(x, d2(x), type="l")
abline(h=0, lty=2)
uniroot(f=d2, interval=c(0.1, 0.5)) # first inflection point
uniroot(f=d2, interval=c(0.5, 0.9)) # second inflection point
Ravi.
____________________________________________________________________
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu
----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
Date: Saturday, March 28, 2009 5:58 pm
Subject: Re: [R] Find inflection points using smooth.spline
To: r-help at stat.math.ethz.ch
> T.D.Rudolph <prairie.picker <at> gmail.com> writes:
>
> >
> >
> > Is there any way to identify or infer the inflection points in a smooth
> > spline object? I am doing a comparison of various methods of time-series
> > analysis (polynomial regression, spline smoothing, recursive partitioning)
> > and I am specifically interested in obtaining the julian dates associated
> > with the inflection points inferred by the various models.
> >
> > Tyler
> >
> > e.g.
> > smooth.spline.pdf
>
>
> You can get an analog of first and second derivatives via using first
> and
> second differences:
>
> ?diff
>
> If your spline object is spl, try:
>
> diff(diff(spl))
>
> It's possible that you would find lag and rle functions useful as well.
>
> --
> David Winsemius
>
> ______________________________________________
> R-help at r-project.org mailing list
>
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list