SMOOTH

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

SMOOTH

Previous pageReturn to chapter overviewNext page

SMOOTH replaces missing values ("holes") inside a timeseries with values generated by means of a particular (user-chosen) method. The statement ignores the global time period, and a local time period cannot be set. Only holes between non-holes are smoothed, so the statement only deals with holes that occur after the timeseries' first non-missing value and before the timeseries' last non-missing value (use the fromSeries() function with 'dataStart'/'dataEnd' arguments if you need to know start/end dates of a timeseries).

 

Instead of the SMOOTH statement, you may alternatively use the similar smooth() function, for instance plot x.smooth(); (see under functions).

 


 

Syntax

 

smooth var1 = var2  type;

 

var1

The new corrected timeseries

var2

The timeseries that contains missings/holes

type

The type of smoothing, choose between:

 

LINEAR. Linear interpolation (default).

GEOMETRIC. Geometric interpolation.

REPEAT. Repeats last known observation.

SPLINE. Cubic splines.

OVERLAY. Insert another series into the holes.

 

Note: default is LINEAR. You can alter the default with option smooth method = ... ; (cf. OPTION).

 

The methods are as follows:

 

LINEAR

Use linear interpolation (adds a fixed amount for each period in the hole(s)).

GEOMETRIC

Use geometric interpolation (multiplies with a fixed amount for each period in the hole(s)).

REPEAT

Set the values to the last known value before the hole(s).

SPLINE

Uses cubic splines to fill the hole(s).

OVERLAY

Uses another timeseries to fill the hole(s).

 

If no period is given inside the <...> angle brackets, the global period is used (cf. TIME).

If a variable on the right-hand side of = is stated without databank, Gekko may look for it in the list of open databanks (if databank search is active, cf. MODE).

Looping: with a list like for instance #= a, b;, you may use for string %= #m; smooth y{%i} = x{%i}; end; to smooth xa into ya, and xb into yb.

 


 

Example

 

For instance:

 

reset;

time 2002 2010;
ts <2002 2004> = 2, 3, 4;
ts <2008 2010> = 12, 11, 10;
tsb <2004 2008> = -1, -2, -3, -4, -5;
smooth ts1 = ts linear;
smooth ts2 = ts geometric;
smooth ts3 = ts repeat;
smooth ts4 = ts spline;
smooth ts5 = ts overlay tsb;
prt <n> ts1, ts2, ts3, ts4, ts5;  //or use plot instead of prt

 

As you can see, the timeseries ts has a hole in the middle, namely the observations 2005-2007 (inclusive). Using the SMOOTH statement, these three observations are filled out. Below, the four different interpolation methods are shown (interpolated values in red):

 

                   ts            ts1            ts2            ts3            ts4            ts5 
  2002         2.0000         2.0000         2.0000         2.0000         2.0000         2.0000 
  2003         3.0000         3.0000         3.0000         3.0000         3.0000         3.0000 
  2004         4.0000         4.0000         4.0000         4.0000         4.0000         4.0000 
  2005              M         6.0000         5.2643         4.0000         6.1349        -2.0000 
  2006              M         8.0000         6.9282         4.0000         8.8696        -3.0000 
  2007              M        10.0000         9.1180         4.0000        11.1694        -4.0000 
  2008        12.0000        12.0000        12.0000        12.0000        12.0000        12.0000 
  2009        11.0000        11.0000        11.0000        11.0000        11.0000        11.0000 
  2010        10.0000        10.0000        10.0000        10.0000        10.0000        10.0000 

 

 

clip0133

Regarding the GEOMETRIC (green) method, note that the growth rate of ts2 is constant (31.61%) in the three interpolated years. In this particular case, SPLINE (yellow) perhaps provides the most realistic hole-filling, since it takes the curvature of the ts timeseries into consideration.

 

 


 

Note

 

See the hpfilter() function regarding the smoothing of timeseries without holes.

 

 


 

Related options

 

option smooth method = linear;

 

 


 

Related statements

 

SPLICE