# spence21

## PURPOSE

function for Spencer's 21-point graduation rule.

## SYNOPSIS

function yhat=spence21(y)

## DESCRIPTION

     function for Spencer's 21-point graduation rule.
     set out following Spencer's hand-calculation method,
     which isn't the shortest computer program!

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- fig1_2 Local Regression and Likelihood, Figure 1.2.

## SOURCE CODE

    0001 function yhat=spence21(y)
    0002 % function for Spencer's 21-point graduation rule.
    0003 % set out following Spencer's hand-calculation method,
    0004 % which isn't the shortest computer program!
    0005
    0006 oten = ones(10,1);
    0007 n = length(y);
    0008 y = [ oten*y(1); y; oten*y(n) ];
    0009
    0010 n = length(y);
    0011 k = 4:(n-3);
    0012 y1 = -y(k-3) + y(k-1) + 2*y(k) + y(k+1) -y(k+3);
    0013
    0014 n = length(y1);
    0015 k = 4:(n-3);
    0016 y2 = y1(k-3)+y1(k-2)+y1(k-1)+y1(k)+y1(k+1)+y1(k+2)+y1(k+3);
    0017
    0018 n = length(y2);
    0019 k = 3:(n-2);
    0020 y3 = y2(k-2)+y2(k-1)+y2(k)+y2(k+1)+y2(k+2);
    0021
    0022 n = length(y3);
    0023 k = 3:(n-2);
    0024 y4 = y3(k-2)+y3(k-1)+y3(k)+y3(k+1)+y3(k+2);
    0025
    0026 yhat = y4/350;
    0027 return;