Piecewise Linear Function: An Introduction
Definition and meaning
Wikipedia defines a piecewise linear function as:
“a function defined on a (possibly unbounded) interval of real numbers, such that there is a collection of intervals on each of which the function is an affine function”
Example
# piecewise linear functions using if statements
# piecewise linear function defined using if for cases.
pw.function <- function(t) {
if(t < 0.5) {
0.7 * t/0.5
} else {
0.7 + 0.3*(t-0.5)/0.5
}
}
pw.function <- Vectorize(pw.function)
tibble(t = seq(0.05:0.99, by = 0.05)) %>%
mutate(pfun_out = pw.function(t)) %>%
ggplot() +
geom_line(aes(x = t, y = pfun_out), group = "combined_grp")
Application
In segmentation and curve fitting. For a larger discourse refer to segmented package in cran.