📄 acorf.m
字号:
function [ACF,stderr,lpq,qpval] = acorf(Z,N);
% Autocorrelation function
% Calculates autocorrelations for multiple data series.
% Also calculates Ljung-Box Q stats and p-values.
%
% [ACF,stderr,lpq,qpval] = acorf(Z,KMAX);
% If mean should be removed use
% [ACF,stderr,lpq,qpval] = acorf(detrend(Z',0)',KMAX);
%
% INPUT
% Z is data series for which autocorrelations are required
% each in a row
% KMAX is the number of autocorrelations to be calculated
%
% OUTPUT
% ACF nr x KMAX matrix of autocorrelations
% stderr nr x KMAX matrix of (approx) std errors
% lpq nr x KMAX matrix of Ljung-Box Q stats
% qpval nr x KMAX matrix of p-values on Q stats
%
% All input and output parameters are organized in rows, one row
% corresponds to one series
% Version 2.44
% last revision 19.06.1998
% Copyright (c) 1997, 1998 by Alois Schloegl
% e-mail: a.schloegl@ieee.org
% calculating lpq, stderr, qpval from
% suggested by Philip Gray, University of New South Wales,
% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Library General Public
% License as published by the Free Software Foundation; either
% version 2 of the License, or (at your option) any later version.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% Library General Public License for more details.
%
% You should have received a copy of the GNU Library General Public
% License along with this library; if not, write to the
% Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
[nr,nc]=size(Z);
ACF=acovf(Z,N);
ACF = ACF(:,2:N+1) ./ ACF(:,ones(1,N));
if nargout > 1
stderr=ones(nr,N)*sqrt(1/nc);
lpq=zeros(nr,N);
qpval=zeros(nr,N);
cum=zeros(nr,1);
for k=1:N,
cum=cum+ACF(:,k).^2/(nc-k);
lpq(:,k)=nc*(nc+2)*cum; % Ljung box Q for k lags
qpval(:,k)=1-chi2cdf(lpq(:,k),k); % p-value of Q stat
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -