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

 채택된 답변

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon 2014년 7월 15일

0 개 추천

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

댓글 수: 7

Also, to avoid numerical issues you might want to use:
t = linspace(-1,1,N)';
instead of
t = (1:N)';
Panty
Panty 2014년 7월 15일
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 2014년 7월 15일
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 2014년 7월 15일
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 2014년 7월 15일
Thats perfect. Thank you very much Alfonso. Much appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

질문:

2014년 7월 15일

댓글:

2014년 7월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by