Vectorize linear trend estimates

1 回表示 (過去 30 日間)
David Wang
David Wang 2013 年 5 月 24 日
I have a few thousand time series of the same length, and for each I'd like to obtain its linear trend and the corresponding p-value. I use for loops and estimate the trend/p-value for each time series sequentially using the robustfit function.
The whole thing doesn't take much time. But still I wonder whether it is possible to vectorize the trend estimates. I understand I can get all linear trends at once using the backslash operator. But that doesn't give p-values.

採用された回答

Matt J
Matt J 2013 年 5 月 24 日
編集済み: Matt J 2013 年 5 月 24 日
I understand I can get all linear trends at once using the backslash operator. But that doesn't give p-values.
First, it might not be a good idea to use backslash straightforwardly. Polynomial fitting has certain numerically sensitive properties. POLYFIT uses a QR decomposition:
[Q,R] = qr(V,0);
ws = warning('off','all');
p = R\(Q'*y); % Same as p = V\y;
warning(ws);
if size(R,2) > size(R,1)
warning(message('MATLAB:polyfit:PolyNotUnique'))
elseif warnIfLargeConditionNumber(R)
if nargout > 2
warning(message('MATLAB:polyfit:RepeatedPoints'));
else
warning(message('MATLAB:polyfit:RepeatedPointsOrRescale'));
end
end
But anyway, once you've found a solution to the system V*x=Y, it seems to me that you could vectorize the p-values by analyzing the residuals,
R=V*x-Y; %residuals
Rmean=mean(R,2);
Rstd=std(R,0,2);
R=bsxfun(@minus,R,Rmean); %Normalize the residuals
R=bsxfun(@rdivide,R,Rstd);
pvalues=sum(R>=quantile,2);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by