[R] splineDesign and not-a-knot conditions
Tamas K Papp
tpapp at Princeton.EDU
Wed Nov 15 20:27:02 CET 2006
I finally found the answer: the easiest way to enforce this is just
removing the 2 knots, like this:
## thanks for all those who replied to the increasing sequences questions
incseq <- function(a,b) {
if (a <= b)
seq.int(from=a,to=b)
else
integer(0)
}
## remove & augment knots
extendknots <- function(x) {
stopifnot(length(x) >= 4 && all(diff(x) > 0))
l <- length(x) # last element
c(rep(x[1],4),x[incseq(3,l-2)],rep(x[l],4))
}
library(splines)
x <- 0:10 # knots
splineDesign(extendknots(x),x) # design matrix to fit not-a-knot cubic splines
Tamas
On Tue, Nov 14, 2006 at 10:41:39PM -0500, Tamas K Papp wrote:
> Hi,
>
> I would like to fit an (interpolating) spline to data where the
> derivatives at the endpoints of the interval are nonzero, thus the
> natural spline endpoint-specification does not make sense. Books (de
> Boor, etc) suggest that in this case I use not-a-knot splines.
>
> I know what not-a-knot splines are (so if I were solving for the
> coefficients directly I knew how to do this), but I don't know how to
> sensibly enforce this restriction on the B-spline basis. I would
> appreciate any advice, references or example code.
>
> Thanks,
>
> Tamas
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list