detrend using cubic splines

Illustration
Yisroel - 2021-01-08T09:49:47+00:00
Question: detrend using cubic splines

How can I detrend a time series using cubic spline interpolation? I would like to get this done over for eg., 0.2 year bins.  

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

detrending is just a process of removing long term deterministic patterns or in short trends. For example your data may look like it is exponentially increasing, but with variation. You are more interested in the variation because the exponential increase renders the data non-stationary.
It is as simple as fitting your data to the best possible curve and subtracting it from your data.
Simple example:
Generate data and get a spline fitted trend:
 
x = 0:100;
y = 100*randn(1,length(x))+x.^2;
xx = 0:10:100;
yy = spline(x,y,xx);

Substract the trend from your original data and  plot the detrended variation sequence.

ytrend = interp1(xx,yy,x,'spline');
subplot(2,1,1)
plot(x,y,'.',x,ytrend);
subplot(2,1,2)
plot(x,y-ytrend)


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!