Derivatives
A derivative measures the instantaneous rate of change of a function — the slope of the line tangent to its graph at a point. In an epidemic, is exactly this: how fast case counts are changing right now, and its early value is the epidemic growth rate that determines how explosively an outbreak takes off. It is the engine behind optimization, maximum likelihood estimation, and the differential equations used in disease modeling.
The limit definition
The derivative of at is the limit of the average rate of change (the slope of a secant line) as the interval shrinks to zero:
Geometrically, is the slope of the secant through and . As that secant rotates into the tangent line, whose slope is .
Notation
The same object is written many ways:
Lagrange’s and Leibniz’s are the most common; (Newton) is typical for time derivatives in dynamical systems.
Differentiable implies continuous
If is differentiable at , then it is continuous at . The converse fails: is continuous at but has no derivative there (the left slope is , the right slope is ). Differentiability is the stronger, smoother condition.
Worked example: from the definition
Let . Apply the limit definition:
So ; the tangent to at has slope .
Computing it
R
# Symbolic derivative with base R
f <- expression(x^2)
D(f, "x") # 2 * x
# Numeric derivative at x = 3
library(numDeriv)
grad(function(x) x^2, 3) # 6
# Function and its tangent line at x = 3
x <- seq(-1, 5, length.out = 200)
a <- 3; slope <- 2 * a
plot(x, x^2, type = "l")
abline(a = a^2 - slope * a, b = slope, lty = 2) # tangent y = 6x - 9
Python
import sympy as sp
x = sp.symbols("x")
sp.diff(x**2, x) # 2*x
# Numeric (finite difference) at x = 3
import numpy as np
f = lambda x: x**2
h = 1e-6
(f(3 + h) - f(3 - h)) / (2 * h) # ~6.0 (central difference)
# Plot with tangent line at x = 3
import matplotlib.pyplot as plt
xs = np.linspace(-1, 5, 200)
a, slope = 3, 6
plt.plot(xs, xs**2)
plt.plot(xs, slope * (xs - a) + a**2, "--") # y = 6(x-3) + 9
plt.show()
Julia
using Symbolics
@variables x
Symbolics.derivative(x^2, x) # 2x
using ForwardDiff
ForwardDiff.derivative(t -> t^2, 3.0) # 6.0
using Plots
xs = range(-1, 5, length = 200)
a, slope = 3, 6
plot(xs, xs .^ 2)
plot!(xs, slope .* (xs .- a) .+ a^2, ls = :dash) # tangent
Why it matters for statistics
Derivatives locate the maxima and minima that drive statistical inference: setting the derivative of a log-likelihood to zero yields maximum likelihood estimates, and the second derivative (curvature) quantifies their precision through the Fisher information. They are also the building block of the gradients used to fit essentially every modern model.