Functions and Graphs
A function maps each input to exactly one output, . These same shapes are the shapes of biology: exponential outbreak growth, the logistic sigmoid of a dose–response curve, saturating uptake curves, and the bell-shaped spread of biological measurements. Recognizing the shapes of common functions lets you read transformations, link functions, and model curves at a glance.
Common functions in statistics
- Linear: — a straight line, slope , intercept .
- Quadratic: — a parabola (e.g. squared error).
- Absolute value: — a V shape (e.g. L1 loss).
- Square root: — defined for (standard errors scale like ).
- Exponential: — always positive, grows rapidly.
- Natural log: — defined for , the inverse of .
Domain and range
The domain is the set of allowed inputs; the range is the set of achievable outputs. For example has domain and range , while has domain and range . Exponential has domain and range — which is why it is used to keep modeled rates positive.
Piecewise functions
A piecewise function uses different rules on different parts of its domain. A worked example:
Evaluating: , , and . The pieces meet continuously at (both give ) and at (both give ).
Computing it
R
# Plot several functions on one panel
curve(x^2, from = -2, to = 2, ylab = "f(x)")
curve(abs(x), add = TRUE, col = "red")
curve(exp(x), from = -2, to = 2, col = "blue")
# Piecewise function
f <- function(x) ifelse(x < 0, -x, ifelse(x <= 1, x^2, 1))
f(c(-3, 0.5, 4)) # 3.00 0.25 1.00
Python
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2, 2, 400)
plt.plot(x, x**2, label="x^2")
plt.plot(x, np.abs(x), label="|x|")
plt.plot(x, np.exp(x), label="e^x")
plt.legend()
# Piecewise function
f = lambda x: np.piecewise(x, [x < 0, (x >= 0) & (x <= 1), x > 1],
[lambda v: -v, lambda v: v**2, 1.0])
print(f(np.array([-3, 0.5, 4]))) # [3. 0.25 1. ]
[3. 0.25 1. ]
Julia
using Plots
x = range(-2, 2, length = 400)
plot(x, x.^2, label = "x^2")
plot!(x, abs.(x), label = "|x|")
plot!(x, exp.(x), label = "e^x")
# Piecewise function
f(x) = x < 0 ? -x : (x <= 1 ? x^2 : 1.0)
f.([-3, 0.5, 4]) # [3.0, 0.25, 1.0]
Why it matters for statistics
Nearly every model is a function: regression lines, link functions in GLMs (log, logit), loss functions, and density curves. Knowing domains keeps you from taking of a negative number or a square root of a negative variance, and recognizing shapes helps you diagnose fit and transformations.