Thursday, August 29, 2013

Finding local extrema of a density function using splines

http://stats.stackexchange.com/questions/30750/finding-local-extrema-of-a-density-function-using-splines

require(graphics)
#some data
d <- density(faithful$eruptions, bw = "sj")

#make it a time series
ts_y<-ts(d$y)

#calculate turning points (extrema)
require(pastecs)
tp<-turnpoints(ts_y)
#plot
plot(d)
points(d$x[tp$tppos],d$y[tp$tppos],col="red")

No comments: