4
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ It would help to make your question more clearly on-topic here (rather than SO, say) if you framed it as 'how do I fit a constrained natural spline?' and then added that you work in R and any suggestions for how to achieve it in R would be especially helpful (that is, present a statistics problem which you're implementing in R, rather than an inherently 'what R code do I use' question, which is a programming problem) $\endgroup$ – Glen_b -Reinstate Monica Sep 4 '13 at 0:39
  • $\begingroup$ Thanks @Glen_b, I agree. I'll try to make the question more on-topic $\endgroup$ – Sam Sep 4 '13 at 1:45
  • $\begingroup$ @Glen_b, I tried to make it more clear that why I need to have a constrained N.S. fit $\endgroup$ – Sam Sep 4 '13 at 1:52
  • $\begingroup$ Using a constraint there doesn't make sense to me, but perhaps I misunderstood something. Possibly asking about how to address that problem would be an even better (if new) question. $\endgroup$ – Glen_b -Reinstate Monica Sep 4 '13 at 1:55
  • $\begingroup$ I have edited your question. Framed this way, it's more likely to avoid closure, and more likely to be reopened if it does close. By putting the reason for your question up front, you're more likely to solve the problem you actually have rather than the problem you think you have. $\endgroup$ – Glen_b -Reinstate Monica Sep 4 '13 at 1:59
1
$\begingroup$

The function smooth.spline allows you to specify weights for each observation. I think if you set very high weights for the pair of valid observations on each side of a missing data run you would effectively force the spline to go through those valid observations.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.