-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issues when internal knot values equal boundary knot values #5
Comments
I am curious about this as well because in the past I opened an issue that might be related (see #1 (comment)). As you indicated, in earlier versions (e.g., v0.4.1) whenever an internal knot lied on the boundary, bSpline(1:10, knots = c(1, 5, 10), degree = 3, intercept = TRUE) The error message was also thrown when In v0.4.3 it seems this is not the case anymore. # Data.
x <- seq(10, 100, length.out = 10)
# Creating basis with internal knots that lie on the boundary.
b <- bSpline(x, knots = c(10, 50, 100), degree = 3, intercept = TRUE)
# Predicting for boundary knots.
predict(b, c(10, 100))
# Which gives:
# 1 2 3 4 5 6 7
# [1,] 0 1 0 0 0 0 0
# [2,] 0 0 0 NaN NaN NaN NaN And the attributes of the basis matrix used by attributes(b)
# $x
# [1] 10 20 30 40 50 60 70 80 90 100
#
# $degree
# [1] 3
#
# $knots
# [1] 10 50 100
#
# $Boundary.knots
# [1] 10 100
#
# $intercept
# [1] TRUE
#
# $class
# [1] "matrix" "bSpline2" |
Thanks for reporting this issue. I do not think setting an internal knot at the boundary can be practically useful. Although library(splines)
bs(1:10, knots = c(1, 5, 10), degree = 3, intercept = TRUE)
Internal knots should be placed inside the boundary. A check has been added via 3d0dc97. |
Thanks for the prompt response. I also do not think that intentionally setting an internal knot at the boundary can be practically useful, however it might occur for some data generating processes when a user selects knot locations using quantiles of an observed data distribution. |
It makes sense to me. |
When an internal knot has the same value as a boundary knot and degree is set to >0, the bSpline function produces NAs for datapoints at the boundary. For example, for a uniform random variable with support [0,1], if we choose an internal knot at 1 and boundary knots at c(0,1), bSpline (v0.4.3) will produce NAs when evaluating the basis function at any datapoints with the value 1. This is not consistent with the behavior of the bs() function or with older versions of splines2 (I tried v0.2.8).
The text was updated successfully, but these errors were encountered: