From Repeating Measurements to a Model
A sinusoidal model is useful when measurements rise and fall in a regular repeating pattern. Examples include approximate daily temperature cycles, seasonal measurements, and the height of a rotating object above the ground. Real data are rarely perfect: measurements may be noisy, and the pattern may not repeat at exactly the same values each time.
The aim here is to build a reasonable model from observed data, rather than to claim that every measurement lies exactly on one ideal curve. We will estimate a cycle length, a typical high and low, and then use those estimates to make predictions. Crucially, we will check predictions against observations that were not used to choose the model.
The Model and Its Parameters
For data that repeat approximately every \(P\) input units, a convenient cosine model is
Here \(x\) is the input, \(y\) is the measured output, \(M\) is the midline, \(A\) is the amplitude, \(P\) is the period, and \(C\) is a reference input chosen to correspond to a peak. We take \(A\) and \(P\) to be positive. The formula uses radians: one full cosine cycle corresponds to an increase of \(2\pi\) in its angle.
In an exact model, the maximum output is \(M+A\) and the minimum is \(M-A\). A peak at \(x=C\) fixes the horizontal reference point: substituting \(x=C\) makes the cosine equal to \(1\). If the input has units, \(P\) and \(C\) have those same units; \(M\) and \(A\) have the output's units.
Earlier material on sinusoidal models establishes how these parameters determine the graph. The practical task here is to estimate them from repeated measurements, where observed highs and lows may differ slightly from cycle to cycle.
Turning Observed Extremes into Estimates
Start by arranging measurements in order of input and looking for repeated peaks and troughs. Peaks are observations near local highs; troughs are observations near local lows. A local high need not be the largest value in the entire data set: it is a high relative to nearby measurements. Once corresponding peaks have been identified, estimate the period from the gaps between their input values. The same can be done with repeated troughs.
Because observations can vary, it is often sensible to average several measured highs and several measured lows. Let \(H\) be the average of the selected high values and \(L\) the average of the selected low values. Then estimate the midline and amplitude by
These formulas come from the maximum and minimum levels of the model. If its upper level is \(H=M+A\) and its lower level is \(L=M-A\), adding the equations gives \(H+L=2M\), while subtracting the lower-level equation from the upper gives \(H-L=2A\). Dividing by \(2\) yields the estimates above. When measurements are noisy, the equations are approximate descriptions of the data, not claims that every observed extreme equals the fitted model's extreme exactly.
For peak inputs \(x_1,x_2,\ldots,x_n\) observed in order, there are \(n-1\) intervals between successive peaks. A useful period estimate is their average:
Averaging multiple intervals can reduce the effect of small measurement or timing differences. It is important to compare like with like: the gap from a peak to the next peak estimates a full period, while the gap from a peak to the next trough is about half a period.
A Practical Fitting Sequence
Locate several plausible peaks and troughs, recording their input and output values. Keep track of which observations will be used to estimate the model.
Measure the input gaps between successive peaks or successive troughs, then average the gaps if there is more than one.
Average the selected high outputs and low outputs to obtain \(H\) and \(L\), then calculate \(M=(H+L)/2\) and \(A=(H-L)/2\).
Choose an observed peak input as \(C\), then write the cosine model using the estimated \(M\), \(A\), \(P\), and \(C\).
Substitute inputs that were not used to estimate the parameters, compare each prediction with its observed output, and describe the differences.
This sequence is a transparent hand-fitting method. It does not guarantee the single “best” model under every possible definition of best. Instead, it gives estimates that can be explained and checked directly against the data.
Worked Examples
Worked Example: Estimating a Daily Cycle from Repeated Highs and Lows
Suppose measurements \(y\), in degrees, are taken at input values \(x\), in hours. Three observed peaks occur at \(x=1,25,49\), with outputs \(20,22,21\). Two observed troughs occur at \(x=13,37\), with outputs \(8,10\). Use these extrema to fit a cosine model. Then check observations \(y=15.3\) at \(x=7\) and \(y=14.8\) at \(x=31\), which were not used in fitting.
The successive peak gaps are
Their average is \((24+24)/2=24\), so estimate the period as \(P=24\) hours. The trough inputs are also separated by \(37-13=24\) hours, consistent with that estimate.
The average high output and average low output are
Thus
Choose the observed peak at \(C=1\). The fitted model is
At \(x=7\), the angle is \(\frac{\pi}{12}(7-1)=\frac{\pi}{2}\), and \(\cos(\pi/2)=0\). The predicted output is \(15+6(0)=15\) degrees. The residual, defined here as observed output minus predicted output, is \(15.3-15=0.3\) degrees.
At \(x=31\), the angle is \(\frac{\pi}{12}(31-1)=\frac{30\pi}{12}=\frac{5\pi}{2}\), and \(\cos(5\pi/2)=0\). The predicted output is again \(15+6(0)=15\) degrees. The residual is \(14.8-15=-0.2\) degrees. Both separate observations are within \(0.3\) degrees of the model's predictions, which is a useful check, though it does not prove that the model will be accurate at every input.
Worked Example: Using Noisy Extreme Measurements
A repeating measurement has observed peaks at \(x=3,13,23\), with outputs \(9,8.8,9.2\), and troughs at \(x=8,18\), with outputs \(3.1,2.9\). Estimate a model and check separate observations \(y=6.2\) at \(x=5.5\) and \(y=5.8\) at \(x=10.5\).
The peak gaps are \(13-3=10\) and \(23-13=10\), so their average is \((10+10)/2=10\). The trough gap is \(18-8=10\), supporting the estimate \(P=10\).
The average of the three high outputs is
The average low output is \(L=(3.1+2.9)/2=6/2=3\). Therefore,
With \(C=3\), the model is
For \(x=5.5\), the angle is \(\frac{\pi}{5}(5.5-3)=\frac{\pi}{5}(2.5)=\frac{\pi}{2}\). The prediction is \(6+3\cos(\pi/2)=6\). Its residual is \(6.2-6=0.2\).
For \(x=10.5\), the angle is \(\frac{\pi}{5}(10.5-3)=\frac{\pi}{5}(7.5)=\frac{3\pi}{2}\). The prediction is \(6+3\cos(3\pi/2)=6\). Its residual is \(5.8-6=-0.2\). These check inputs are distinct from the peak and trough inputs used in the fit. The small differences are consistent with measurement variation around the idealized curve.
Worked Example: Estimating a Cycle from Repeated Features
Suppose peaks are observed at \(x=0,8,16\), with outputs \(5,6,5.5\), and troughs at \(x=4,12\), with outputs \(-1,-0.5\). Estimate a cosine model, then check observations \(y=2.5\) at \(x=2\) and \(y=2.2\) at \(x=6\).
The peak gaps are \(8-0=8\) and \(16-8=8\), with average \((8+8)/2=8\). The trough gap is \(12-4=8\). Estimate \(P=8\).
The average high and low outputs are
Hence
Choose \(C=0\), giving
At \(x=2\), the angle is \(\frac{\pi}{4}(2)=\frac{\pi}{2}\), so the prediction is \(2.375+3.125(0)=2.375\). The residual is \(2.5-2.375=0.125\).
At \(x=6\), the angle is \(\frac{\pi}{4}(6)=\frac{3\pi}{2}\), so the prediction is again \(2.375\). The residual is \(2.2-2.375=-0.175\). The two checks are near the fitted midline, as expected at these quarter-cycle positions.
Why the Parameter Estimates Work
The vertical estimates follow directly from the model's extreme values. At a peak, the cosine value is \(1\), so the model output is \(M+A\). Half a period later, the cosine value is \(-1\), so the output is \(M-A\). If the observed high and low levels are represented by \(H\) and \(L\), then solving those two equations gives
The period estimate has a similarly direct basis. The cosine function completes a cycle when its angle increases by \(2\pi\). In the fitted model, increasing \(x\) by \(P\) changes the angle by \(\frac{2\pi}{P}P=2\pi\). Thus the model repeats after an input interval \(P\). Successive peaks correspond to the same phase of the cycle, so their input separation estimates this period.
Checking a Fit and Avoiding Common Mistakes
A check is most informative when its observation was not used to choose the model parameters. If a measured high helped determine \(H\), comparing the model to that same high is not an independent test. It can still confirm that the arithmetic was carried out consistently, but it provides little evidence about how well the model predicts other data. Set aside some observations for checking whenever the data set allows it.
For each check, calculate the prediction by substituting its input into the fitted equation. Then calculate the residual as observed output minus predicted output. A positive residual means the observation is above the prediction; a negative residual means it is below. Residuals are measured in the output's units. Their sizes help describe the fit, but a few small residuals do not establish that every future prediction will be close.
A common period error is to mistake a peak-to-trough gap for a full cycle. For example, if peaks are 24 hours apart, a trough about 12 hours after a peak is expected. Calling that 12-hour gap the period would produce a model that repeats twice as quickly as the data. Check whether the features being compared are the same phase: peak to peak or trough to trough gives a full cycle; peak to the next trough gives about half a cycle.
Another mistake is to treat noisy observations as exact extremes. In the second example, the three peak outputs were not identical. Their average, \(9\), represents a typical high; it does not mean that each observed peak must equal \(9\). Averaging estimates can be useful, but the resulting model remains an approximation.
Finally, a sinusoidal model is appropriate only when the pattern is reasonably periodic and its typical high, low, and cycle length remain broadly stable. A strong upward trend, irregular cycles, or changing amplitudes can make a single sinusoid misleading. Inspect the data before fitting, and judge the equation by separate checks as well as by how plausible its parameters are.
Check Your Understanding
Use the definitions and fitting steps above to answer these questions.
- Observed peaks occur at \(x=2,14,27\). What are the successive peak gaps, and what is their average period estimate?
- If the average observed high is \(18\) and the average observed low is \(6\), calculate the estimated midline and amplitude.
- For a cosine model with period \(P=8\) and a peak at \(C=1\), what angle is used when \(x=3\), and what fraction of a cycle after the peak is this?
- Why is a data point used to estimate a model parameter a less informative check than a point held back from fitting?
- A model predicts \(12.4\) units at a check input, while the observed output is \(12.1\) units. Find the residual using observed minus predicted, and interpret its sign.