# spence15

## PURPOSE

function for Spencer's 15-point graduation rule.

## SYNOPSIS

function yhat=spence15(y)

## DESCRIPTION

     function for Spencer's 15-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=spence15(y)
    0002 % function for Spencer's 15-point graduation rule.
    0003 % set out following Spencer's hand-calculation method,
    0004 % which isn't the shortest computer program!
    0005
    0006 osev = ones(7,1);
    0007 n = length(y);
    0008 y = [ osev*y(1); y; osev*y(n) ];
    0009
    0010 n = length(y);
    0011 k = 3:(n-2);
    0012 a3 = y(k-1) + y(k) + y(k+1);
    0013 a2 = y(k-2) + y(k+2);
    0014 y1 = y(k)+3*(a3-a2);
    0015
    0016 n = length(y1);
    0017 k = 1:(n-3);
    0018 y2 = y1(k)+y1(k+1)+y1(k+2)+y1(k+3);
    0019
    0020 n = length(y2);
    0021 k = 1:(n-3);
    0022 y3 = y2(k)+y2(k+1)+y2(k+2)+y2(k+3);
    0023
    0024 n = length(y3);
    0025 k = 1:(n-4);
    0026 y4 = y3(k)+y3(k+1)+y3(k+2)+y3(k+3)+y3(k+4);
    0027
    0028 yhat = y4/320;
    0029 return;