Zhipeng Wang
2011-Mar-30 01:32 UTC
[R] Connect observed values by a smooth curve, is there any method to get coordinate value of arbitrary point on the curve?
Dear all, I have the problem as the title shows. It is time series of measurements. I want to estimate the value at time point when we have no actual measured value (Only in the time range, not for prediction in future time). Hope you could give me some suggestion or hint. Thank you so much. Wang Zhipeng [[alternative HTML version deleted]]
Duncan Murdoch
2011-Mar-30 11:33 UTC
[R] Connect observed values by a smooth curve, is there any method to get coordinate value of arbitrary point on the curve?
On 11-03-29 9:32 PM, Zhipeng Wang wrote:> Dear all, > > I have the problem as the title shows. It is time series of measurements. I > want to estimate the value at time point when we have no actual measured > value (Only in the time range, not for prediction in future time). > > Hope you could give me some suggestion or hint. Thank you so much.If you want to interpolate the data, use splinefun. For example, x <- 1:5 y <- rnorm(5) f <- splinefun(x,y) curve(f, from=1, to=5) points(x,y) If you want to draw a smooth curve through the data, then use one of the model fitting functions, and then predict to compute values at new x values. For example, library(mgcv) x <- 1:50 # Smoothing needs more data y <- rnorm(50) fit <- gam(y ~ s(x)) newx <- seq(1,50, len=1000) newy <- predict(fit, newdata=data.frame(x=newx)) plot(x,y) lines(newx, newy) Duncan Murdoch
David Winsemius
2011-Mar-30 11:49 UTC
[R] Connect observed values by a smooth curve, is there any method to get coordinate value of arbitrary point on the curve?
On Mar 29, 2011, at 9:32 PM, Zhipeng Wang wrote:> Dear all, > > I have the problem as the title shows. It is time series of > measurements. I > want to estimate the value at time point when we have no actual > measured > value (Only in the time range, not for prediction in future time). > > Hope you could give me some suggestion or hint. Thank you so much.?approxfun -- David Winsemius, MD Heritage Laboratories West Hartford, CT
Zhipeng Wang
2011-Apr-01 15:21 UTC
[R] Connect observed values by a smooth curve, is there any method to get coordinate value of arbitrary point on the curve?
Dear Prof. Murdoch and Dr. Winsemius, Thank you very much for your suggestion. They were big help. One of my friends told me another approach by using "smooth.spline". Here is the code: x <- c(1,2,3,4,5,6) y <- c(1,4,9,16,25,36) sp <- smooth.spline(x,y) x <- seq(1, 6, length=100) pred <- predict(sp, x) real <- x^2 err <- real - pred$y cbind(pred$x, pred$y, real, err) plot(pred) Thank a lot. Have a nice weekend :) Wang Zhipeng [[alternative HTML version deleted]]