Skip to content

Polynomial Curve Fitting

Vector 3:4, page 117

The text of this article is not yet online. No complete scan of this issue has been found. The only copy found, on vector.org.uk, is damaged: its page images are lost, but the text machine-read from them survives, shown below (help find a scan).

Unedited OCR text, machine-read from a scan now lost: it contains errors, and its APL is wrong. Shown for searching.

VECTOR Vol.3 No.4

Polynomial Curve Fitting

by Douglas

[refer to Dick Bowman’s and the Editor’s comments (VECTOR Vol.3, No.1, pp 99-100) on the different responses of different APL systems to a dyadic use of domino for polynomial curve fitting.

Dick’s remark, that it is interesting  when the same code applied to the same data gives different results, is certainly valid. But without downplaying the importance of having good algorithmic and numerical procedures (“the code”), [ should like to emphasize the other aspect, the data, of what is a perpetual problem. The perpetual problem” is to devise methods sufficiently robust for appropriate aralysis of any data; it is perpetual because whatever method may be devised it is always possible to invent data for which the method will misbehave.

What is often sought is a“. . . fitted curve . to look nice and smooth . . .” So let’s graph Dick’s data (see Figure 1). The curious behaviour at odd and even years is obvious, and no meaningful smooth curve seems plausible  in particular, a cubic cannot possibly reproduce the marked oscillation of the Y-values at the later years X. To obviate readily removable DOMAIN or LIMIT ERROR difficulties, which may arise simply because large numbers like 1995 are raised to high powers in the calculations, subtract 1984 from X. This gives numerically reliable regression coefficients and a smooth fitted curve (see Figure 2) which is basically nonsense when thought of as representing the data. (APL*PLUS PC is capable of giving an equivalent to this result without having to subtract the 1984.) A more detailed analysis shows that of the four regression coefficients, only the first, associated with the constant term, is large (compared with its standard error) and likely to be meaningful, and that the mean square about the fitted cubic really isn’t much less than that about a constant fitted value.

The numerical results are as follows, with the data first: X:

1234567 8 91011 36 39 39 43 38 43 35 42 +B+YRA+Xe.*#0 1 returns the regression coefficients

34.212 2.040 -0.225 0.00777

for which the standard errors are:

5.1 3.5 0.67 0.037;

fitted values are calculated from a+.x3 Inspecting the data, the graph suggests that two distinct quadratics would represent them well at the years recorded: one quadratic for the odd, and another for the even, years. This fitting can be achieved by replacing the matrix A by the matrix C; both are shown below.

M17

VECTOR Vol.3 No.4

A c

oto. 1 1 1 0 0 1 2 4 8 1 0 0 2 4 1 39 2 1 3 9 0 0 1 4 16 64 1 0 0 4 16

Tay 12d 1331 T dW i 0. 0

Then executing: YBC returns five coefficients all of which are large compared with their standard errors, the fit being displayed in Figure 3. (The coefficients and their standard errors are:

34.141 2.082 -0.1234 1.632 -0.1507 0.72 0.29 =

0.024 0.31 0.029)

So in some sense this smoothly, and quite closely, reproduces the data. It leaves uncertain what meaning should be attached to interpolated values  but so do the data.

J believe the principal message to be that one should always look at the data and what any procedure predicts for the data, to see that the question and the answer are reasonable. The misbehaviour  of domino is minor compared with the mis-specification of a cubic for the representation of the data. Figure 1. Bowman’s original data

45.0] | |

1 ° ° 42.51] + | ° 5 ¥ ! ° | v 40.04 A | L | ° ° u ! E | ° ° s 37.5] I ° | t °o | 35.04 | | I 1 | ! 1 ' ! ° t 1984 1986 1988 1990 1992 1994 1996 YEARS - X VALUES >

118

VECTOR Vol.3 No.4

Figure 2. Original data with a fitted cubic

45.0] | | 1 t ° ° 42.54 + | ° | Yy | ° t v 40.01 * * * * A t * LB [ ° ° u | * EB | ° ° § 37.51 * | ° | t * ° | 35.0 | | | t t 1 | | | ° ' | 1984 1986 1988 1990 1992 1994 1996

YEARS - X VALUES + O OBSERVED * PITTED CURIC

Figure 3. Original data with a fitted pair of quadratics 45.01 | | | | ° * ! 42.5] * i + I * | * y ' ° { v 40,0[ A | * L ( ° ° u | * * E | Ss 37.5| * ! ° * 1 | * 0 [ * 35.0] t | | | | | | ° t | 19984 1986 1988 1990 19932 1994 1996 YEARS - X VALUES + Oo OBSERVED * PITTED QUADRATICS

119