# Statistics - (Linear spline|Piecewise linear function)

A linear spline, or piecewise linear function has a degree zero Statistics - Piecewise polynomials and is:

• linear in the left and the right.
• forced to be continuous at the knot.

## Definition / Representation

Just like the global polynomials and the piecewise constant functions, we can represent this as a linear expansion in basis functions that are transformations of the variables.

A linear spline with knots at $\xi_k$ with $k = 1, \dots, K$ is a piecewise linear polynomial continuous at each knot.

This model can be represented as:

$$y_i = \beta_0 + \beta_1.b_1(x_i) + \beta_2.b_2(x_i) + \dots + \beta_{K+3}b_{K+3}(x_i) + \epsilon_i$$

where the $b_k$ are basis functions and are:

• the variable itself. One of these basis functions is just the variable itself

$$\begin{array}{rll} b_1(x_i) & = & x_i \\ \end{array}$$

• and additional variables that are a collection of truncated basis transformation functions at each of the knots. They are called truncated power functions, but this one is to power 1.

$$\begin{array}{rll} b_{k+1}(xi) & = & (xi - \xi_k)_+ \text{ where } k = 1, \dots, K \\ \text{where the ()+ means positive part. i.e. } (xi - \xi_k) & = & \left\{ \begin{matrix} xi - \xi_k & \text{ if } x_i > \xi_k & \\ 0 & \text{Otherwise} & \text{It's not allowed to go negative.} \end{matrix} \right. \end{array}$$

## Plot

There is one knot in these pictures, but we can put down multiple knots.

When we fit a linear model with a global linear function plus one of the basis function and their respective coefficient, we get a function that's allowed to change its slope at the knot.

Discover More
R - Spline

Fitting splines in R is easy: bs(x, ...) for any degree splines (one: linear spline, three: cubic spline and ns(x, ...) for natural cubic splines, in package splines.
Statistics - Cubic spline

Cubic splines is a step cubic piecewise polynomial in the left and the right and continuous at the knot. There's the following constraints: The first derivatives continues at the knot, and the...
Statistics - Piecewise polynomials

Piecewise polynomials generalize the idea of piecewise constants. The idea try to get rid of the global polynomial because it's global and not local. Instead of having asingle polynomial over the whole...
Statistics - Splines

A spline is a piecewise polynomial model: Splines have the “maximum” amount of continuity over all knots function.