← Back to course

Sinusoidal Regression & Model Fitting

You’ll be able to

Four parameters, estimated in order

Given periodic data, extract the four parameters in a fixed sequence and the fit almost writes itself. Midline k = (max + min)/2. Amplitude a = (max − min)/2. Period from the observed cycle length, then b = 2π/period. Phase h from a landmark — the location of a maximum if you are modeling with cosine. This estimate is usually within a few percent of what regression software returns.

Estimating a sinusoidal fit
k = (max + min)/2 · a = (max − min)/2 · b = 2π/period · h = x-value of a maximum (for a cosine model)
Real data rarely has an exact maximum at a sampled point, so h is an estimate. Averaging two consecutive cycles improves it.
Worked example

Average monthly high temperature in a city peaks at 29°C in July (month 7) and bottoms at 3°C in January (month 1). Fit a sinusoidal model with t in months.

  1. 1.Midline: k = (29 + 3)/2 = 16.
  2. 2.Amplitude: a = (29 − 3)/2 = 13.
  3. 3.Period: annual temperature cycles once per year, so 12 months. b = 2π/12 = π/6.
  4. 4.Landmark: the maximum is at t = 7, and cosine peaks at argument 0, so h = 7.
  5. 5.Model: T(t) = 13·cos((π/6)(t − 7)) + 16.
  6. 6.Check January: T(1) = 13 cos((π/6)(−6)) + 16 = 13 cos(−π) + 16 = −13 + 16 = 3. ✓
Answer: T(t) = 13·cos((π/6)(t − 7)) + 16 degrees Celsius. Verifying against the other extreme is the check that matters — a model can match the maximum by construction and still have the wrong period, and January is where that error would show.

When one sinusoid is not enough

A single sinusoid is symmetric: it spends equal time above and below the midline, rises and falls at mirror-image rates, and has identical peaks and troughs. Real periodic data often violates this. Tides have two unequal highs per day. Daylight hours change faster near the equinoxes than a pure sinusoid predicts. Electricity demand has a sharp evening peak and a broad overnight trough. The residual plot reveals it: a systematic pattern within each cycle, repeating cycle after cycle, means the shape is wrong even when the period is right.

Watch out

Sinusoidal models cannot be extrapolated indefinitely. A temperature model fitted to one year predicts the same cycle forever, capturing no trend at all — so it will steadily diverge from data in a warming climate. Periodicity is an assumption imposed by the model, not a fact discovered in the data.

Checkpoint

Data on daily high tide height has maximum 4.6 m and minimum 1.2 m. What are the midline and amplitude?

Separating trend from cycle

When data both cycles and drifts, a pure sinusoid cannot fit both. The standard approach is to model the sum: f(t) = (trend) + (sinusoid), for example f(t) = 0.02t + 13cos((π/6)(t − 7)) + 16, where the linear term captures a slow warming and the sinusoid captures the seasons. Fitting only the sinusoid leaves the trend in the residuals, where it appears as a slow drift from negative to positive across the whole record — a distinctive and easily recognized signature.

Worked example

Monthly measurements of atmospheric CO₂ show a steady rise plus an annual wiggle of about ±3 ppm. What model form is appropriate, and what would a pure sinusoid leave behind?

  1. 1.Two features are present: a long-run increase and a 12-month cycle.
  2. 2.A sinusoid alone has a constant midline, so it cannot represent the rise.
  3. 3.A line alone has no periodicity, so it cannot represent the wiggle.
  4. 4.Combine them: C(t) = (mt + b) + 3·sin((π/6)(t − h)), with m from the long-run slope.
  5. 5.Fitting only the sinusoid would leave residuals that climb steadily across the record.
Answer: A sum of a linear trend and a sinusoid, C(t) = mt + b + 3 sin((π/6)(t − h)). A pure sinusoid would leave a monotonically increasing residual pattern — the clearest possible sign that a trend term is missing rather than that the period is wrong.
Checkpoint

A sinusoidal model is fit to monthly data. The residuals are small but show the same up-down pattern within every single year. What does this indicate?

Answer the 2 checkpoints as you read.

Sign in to save your progress