Why I think I need to fit a constrained natural spline
I'm working with IBI (interbeat intervals). The measured IBI's include some invalid values. I'm working on an imputation algorithm to impute for the invalid IBI's. Suppose I have an interval with 5 invalid IBI's. Part of my idea on imputing for the invalid IBI's is to have a natural spline fit that is constrained between the last valid point before these invalid IBI values and the first valid point after these invalid points.
Is there any way that I can fit a natural spline constrained to pass through a certain pre-specified points?
I am working in R, and R implementations would be particularly useful.
As an example, consider the data below:
data <- data.frame(X = rep(NA, 1000), Y = rep(NA, 1000)) set.seed(123456) data$X <- cumsum(abs(c(0, rnorm(999, 0.8, 0.05)))) data$Y <- c(rnorm(100,700, 50), rnorm(100,800, 50), rnorm(100,900, 50), rnorm(100,800, 50), rnorm(100,700, 50), rnorm(100,800, 50), rnorm(300,700, 50), rnorm(100,600, 50))
Now, suppose that I'd like to have a natural spline with knots on every 20 seconds (assume time is in second) AND to have the fitted natural spline fit to pass through obs 4 and obs 15 (row # 4 and row # 15). Is there anyway to do that?
My solution: one solution is to use very close knots in those points.