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

 采纳的回答

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)';
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??
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.
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.
Thats perfect. Thank you very much Alfonso. Much appreciated.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by