Quadratic time detrending. Any help or code ???

Hi guys!! I have a question.
For linearly detrending a time-series you can use the detrend(..) function.
If you want to extract the quadratic time trend?? Any function or code you could share??
I have found this code in the 'Parametric Trend Estimation' Mathworks page, but I want to make sure whether it works or not and you opinion.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load(fullfile(matlabroot,'examples','econ','Data_Accidental.mat')); t = [1:N]'; X = [ones(N,1) t t.^2];
B = X\Y;
Th = X*B;
h = plot(Th/1000,'r','LineWidth',2);
legend(h,'Quadratic Trend Estimate');
hold off
Y = Dataset.NUMD;
N = length(Y);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Many thanks

 Respuesta aceptada

Yes, that should work, you just need to define:
Ynew = Y - Th;
to get the new "detrended" timeseries.

7 comentarios

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon el 15 de Jul. de 2014
Editada: Alfonso Nieto-Castanon el 15 de Jul. de 2014
Also, to avoid numerical issues you might want to use:
t = linspace(-1,1,N)';
instead of
t = (1:N)';
Panty
Panty el 15 de Jul. de 2014
I have one more question. In the case of the Linear time detrending you have to subtract the detrended data from the original data in order to get the trend line. The 'Ynew = Y - Th' command is for the same purpose??
Panty
Panty el 15 de Jul. de 2014
Oohhh...my bad...I just saw your explanation below your command.. So thats for getting the new 'detrended' time-series.
But I have another one question. In the case of Linear time detrending, I need to replicate a specific method which says:
"Linear time trend: The (log of) real GDP yt is regressed on a constant term and a linear time trend: X = {1 t}, with coefficients estimated by OLS. The residuals from this regression, scaled by 100, define the output gap,Yt."
%%%%%%%
Is this method described above able to be replicated using the detrend(..) function on the original data. And hence the detrended data is the output gap??
Yes, from that description the detrended data (scaled) of log GDP would be the output gap.
Panty
Panty el 15 de Jul. de 2014
Thats perfect...Two more questions.
1.Are we sure that detrend(...) command estimates the coefficients using OLS???
2. Lets go back to the quadratic detrend. using the script I wrote at the beginning, in which part the coefficients are estimated using OLS??
Much appreciated
Yes, ordinary least squares, linear regression, general linear model, the X\Y part would do just that.
Panty
Panty el 15 de Jul. de 2014
Thats perfect. Thank you very much Alfonso. Much appreciated.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Jul. de 2014

Comentada:

el 15 de Jul. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by