Search code examples
rspline

Spline in R terms and wording - degree of the polynom - degree of freedom - degree of continuity - basisspline


I am creating a spline in R with the following function:

spline_model <- lm(sales ~ bs(data_clean$visits, df = 3, knots = 3)+ data_clean$discount -1, data = data_clean)

But I am bit confused with the wording and the terms which I am reading in the scientific literature and in the help of R. There are

  • degree of the polynom: Parameter degree in R. I think degree 1 is linear. Degree 2 is a curve. Degree 3 is a cubic spline with something like a multicurve.
  • degree of freedom: Parameter df in R. This is something like the overall flexibility of the whole spline. Which I do not understand what is flexible.
  • degree of continuity: I have found that in the literature. That is how intensive the changes at the knots are. But somewhere it sounds like degree of freedom. Somewhere else is mentioned that the 3rd degree is a cubic spline. But then it must be the degree of the polynom. I am most cofused about this.

Additionaly there is a basis spline which is used by my function bs. But what is so special about the basis spline?

Can you help me please to bring more clarity in the different terms and how to influence them in R?

Thank you!


Solution

  • I have found an answer: degree of polynom is normally 3 for a cubic polynom. This is how crazy the lines are, e.g. 1 is linear. More than 3 is not neccessarry. In R parameter degree. degree of freedom: This is knots + degree of polynom. If degree of polynom is 3 than you need to have at least degree of freedom 3. You can rather chose knots or degree of freedom because they are connected with each other. Parameter in R is df. degree of continuity, I did not found. But knots are the number or positions of the knots in the spline. Parameter in R is knots.