Closed mihaiconstantin closed 4 years ago
I am glad that you ask a question here. It would be of help to other users having similar questions.
By the definition of knot sequence, each boundary knot is repeated m times, where m represents the order of spline basis. Given specified boundary knots and order, the generation of such a knot sequence is done internally in splines2 so that users can simply specify the range to anchor the splines via boundary_knots
without generating the knot sequence on their own. In contrast, splines::splineDesign()
requires users to specify the knot sequence. The difference is clear in the following example.
library(splines)
library(splines2)
x <- seq.int(0, 1, 0.01)
degree <- 3
ord <- degree + 1
knots <- seq.int(0.1, 0.9, 0.1)
b_knots <- range(x)
all_knots <- sort(c(knots, rep(b_knots, ord)))
out1 <- splineDesign(x, knots = all_knots, ord = ord)
out2 <- bSpline(x, knots = knots, degree = degree,
intercept = TRUE, Boundary.knots = b_knots)
all.equal(out1, out2, check.attributes = FALSE)
Hi @wenjie2wang,
Thank you very much for the prompt and detailed response! This not only answers my question but also helps me clarify a couple of things. I hope it will also be helpful to others as well.
Do you want me to close the 'issue'?
My pleasure. Glad to hear that it helps. I can close this issue.
This may not be the best place to ask this question. I apologize for that.
I would appreciate it if you can help me understand a use case scenario regarding the
boundary_knots
.Is it possible to define an extended partition (i.e., by specifying some knots with multiplicities)? I a nutshell, I am interested to see if
splines2
can account for the following scenario (https://rpubs.com/deleeuw/268327):Looking at the code of
clean_knots()
in classSplineBase
, I believe this is not possible since only unique elements are retained after executingarma::unique(boundary_knots)
.https://github.com/wenjie2wang/splines2/blob/1de1d904bc6c48fdaa6a7e8806e3e3d8ea6206c2/inst/include/splines2Armadillo/SplineBase.h#L81-L89
Is there a workaround for this, or am I missing something?
P.S. Thanks for this great package! :)