Functions and Graphs

A function maps each input to exactly one output, f:xf(x)f: x \mapsto f(x). 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

Domain and range

The domain is the set of allowed inputs; the range is the set of achievable outputs. For example x\sqrt{x} has domain [0,)[0, \infty) and range [0,)[0, \infty), while lnx\ln x has domain (0,)(0, \infty) and range R\mathbb{R}. Exponential exe^x has domain R\mathbb{R} and range (0,)(0, \infty) — 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:

f(x)={xx<0x20x11x>1f(x) = \begin{cases} -x & x < 0 \\ x^2 & 0 \le x \le 1 \\ 1 & x > 1 \end{cases}

Evaluating: f(3)=3f(-3) = 3, f(0.5)=0.25f(0.5) = 0.25, and f(4)=1f(4) = 1. The pieces meet continuously at x=0x = 0 (both give 00) and at x=1x = 1 (both give 11).

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 ln\ln of a negative number or a square root of a negative variance, and recognizing shapes helps you diagnose fit and transformations.