D.Mac D.Mac - 27 days ago 5
R Question

Smooth interpolation of my data

I'm trying create smooth lines on a plot which include the maxima of the data points. I've searched around a lot and have tinkered with loess() and ksmooth() but I'm yet to make it work.

My best attempt so far has been with ksmooth() but the line doesn't pass through the maximum data point

enter image description here

I'm a chemist, not a statistician, so the methods/descriptions of various smoothing techniques often go over my head. Any suggestions would be really appreciated.

Edit: Just wanted to make a few things clearer. Basically what I'm after is a smoothed version of the following plot with the line passing through the maximum y value.

enter image description here

To generate the plot in the first picture I used the following code:

plot(ChiM~Temp, xlim=c(2,6), ylim=c(0,0.225), lwd=2, pch=16, col='red',subset=(v=='20'), main='Out-of-Phase AC Suscetability Plot', xlab='Temperature (K)', ylab=expression(chi[M]*'" (cm'^3*~'mol'^-1*')'))
setone <- subset(DSM32ac, v=='20') #v=20 is the subset of the data I have provided
lines(ksmooth(Temp, ChiM, 'normal', bandwidth=0.5), col='red',lwd=2)

I hope this makes things a little clearer. If you need any more information to answer this question just let me know.

Edit 2: I've removed the data since I can't make a neat table. If it's really important I'll try and put it back in.


Try this:

y <- c(.07, .12, .17, .11, .04, .02, .01)
x <- seq_along(y)

s <- spline(x, y)

plot(y ~ x)