Closed mihaiconstantin closed 3 years ago
I want to clarify my question further. My confusion stems from what is written in this paper on p. 15:
To get a basis for the increasing splines we need to add the constant function to the I-splines and allow it to enter the linear combination with either sign.
In the splines2
package documentation, where the intercept argument for iSpline()
is described, you write:
Notice that when using I-Spline for monotonic regression, 'intercept = TRUE' should be set even when an intercept term is considered additional to the spline bases in the model.
What I get from this is that if I want to fit a monotone spline with, say, nnls::nnls()
, then I need to add a constant function to the I-Spline basis, i.e., h <- cbind(1, h)
, assuming that h
is the basis matrix output of iSpline()
.
However, in the paper linked above, that's not always the case. Sometimes the author replaces the first column of the basis matrix (i.e., h <- cbind(1, h[ -1]
) with the constant function, and, other times, he appends the constant function to the basis matrix.
For instance, if I create the I-Spline basis matrix as follows:
h <- iSpline(x, knots = c(3, 5, 8), degree = 0, intercept = TRUE)
Then, depending on how I "add" the constant function (or not) I get different splines:
Can you please shed some light on how the basis matrix provided by iSpline()
is intended to be used in this case?
Sorry for the late response. I somehow missed the notification of this issue.
When intercept = TRUE
, iSpline()
returns the integrals of the corresponding M-spline basis functions without removing the first column. Otherwise, the first column will be removed from the output. This usage is consistent with the intercept
in splines::bs()
.
What I get from this is that if I want to fit a monotone spline with, say,
nnls::nnls()
, then I need to add a constant function to the I-Spline basis, i.e.,h <- cbind(1, h)
, assuming thath
is the basis matrix output ofiSpline()
.
Your understanding is correct. An additional intercept term should be considered (unless the underlying curve is assumed to pass through 0 at the left boundary knot). Also, the coefficient estimate of the intercept term is unconstrained.
However, in the paper linked above, that's not always the case. Sometimes the author replaces the first column of the basis matrix (i.e.,
h <- cbind(1, h[ -1]
) with the constant function, and, other times, he appends the constant function to the basis matrix.
I will have a look at the paper linked above later today. For monotone regression, you may check Ramsay (1988).
Thank you a lot for your answer, @wenjie2wang, and sorry for the confusion around this question, which in hindsight is definitely not an issue with the splines2
package.
Your answer helped me clarify how to use splines2::iSplines()
for monotonic regression properly, and this is in line with what I read in Ramsay (1998): construct the full I-Spline basis (i.e., intercept = TRUE
) then add the constant function.
Now I see that the implementation for I-Splines in splines2
is based on Ramsay (1998) whereas, in the other paper, the discussion is based on De Boor (1976). Perhaps that's why the resulting I-Spline bases are not identical, and the author treats the first basis function differently. Or I am completely misunderstanding what he is doing. Regardless, thank you for clarifying this!
I want to clarify my question further. My confusion stems from what is written in this paper on p. 15:
The link does not work for me. What is the title of the paper?
The link does not work for me. What is the title of the paper?
It's De Leeuw (2017) titled Computing and Fitting Monotone Splines. Here is another link, this one should work. Direct link also here: de_leeuw_2017_splines.pdf.
I had a quick look at the I-splines example in Section 5.2. Dr. De Leeuw probably wanted the fitted curve to be flat at the beginning (from the left boundary to the first internal knot). So the first I-spline basis function was not considered.
Oh, that makes sense... Thank you a lot! You really helped me clarify my question and I highly appreciate it. I will go ahead and close this issues now.
I have the following data to which I want to fit a monotone non-decreasing spline.
To achieve this, I use an
iSpline
basis paired with non-negative coefficients.And this gives me the following:
However, with
intercept = TRUE
, I would expect the spline to start somewhere above the first data point. For instance, this seems to be the case when I set the first basis function to 1.If I set
intercept = FALSE
, then things go haywire.Can you please help me understand what is going on, i.e., why is the spline not starting at
(300, 0.5)
?