Home > matlab > autoregressive_process_specification.m

autoregressive_process_specification

PURPOSE ^

This function computes the parameters of an AR(p) process from the variance and the autocorrelation function

SYNOPSIS ^

function [InnovationVariance,AutoregressiveParameters] = autoregressive_process_specification(Variance,Rho,p)

DESCRIPTION ^

 This function computes the parameters of an AR(p) process from the variance and the autocorrelation function
 (the first p terms) of this process.

 INPUTS 
  [1] Variance                 [double]  scalar, variance of the variable.
  [2] Rho                      [double]  p*1 vector, the autocorelation function: \rho(1), \rho(2), ..., \rho(p).
  [3] p                        [double]  scalar, the number of lags in the AR process.

 OUTPUTS 
  [1] InnovationVariance       [double]  scalar, the variance of the innovation.
  [2] AutoregressiveParameters [double]  p*1 vector of autoregressive parameters.

 NOTES 

 The AR(p) model for {y_t} is:
   
           y_t = \phi_1 * y_{t-1} +  \phi_2 * y_{t-2} + ... +  \phi_p * y_{t-p} + e_t    

 Let \gamma(0) and \rho(1), ..., \rho(2) be the variance and the autocorrelation function of {y_t}. This function
 compute the variance of {e_t} and the \phi_i (i=1,...,p) from the variance and the autocorrelation function of {y_t}. 
 We know that:
    
    \gamma(0) = \phi_1 \gamma(1) + ... + \phi_p \gamma(p) + \sigma^2

 where \sigma^2 is the variance of {e_t}. Equivalently we have:

    \sigma^2 = \gamma(0) (1-\rho(1)\phi_1 - ... - \rho(p)\phi_p)     

 We also have for any integer  h>0:
 
    \rho(h) = \phi_1 \rho(h-1) + ... + \phi_p \rho(h-p)

 We can write the equations for \rho(1), ..., \rho(p) using matrices. Let R be the p*p autocorelation
 matrix and v be the p*1 vector gathering the first p terms of the autocorrelation function. We have: 

           v = R*PHI
    
 where PHI is a p*1 vector with the autoregressive parameters of the AR(p) process. We can recover the autoregressive
 parameters by inverting the autocorrelation matrix: PHI = inv(R)*v.
 
 This function first computes the vector PHI by inverting R and computes the variance of the innovation by evaluating

           \sigma^2 = \gamma(0)*(1-PHI'*v)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [InnovationVariance,AutoregressiveParameters] = autoregressive_process_specification(Variance,Rho,p)
0002 % This function computes the parameters of an AR(p) process from the variance and the autocorrelation function
0003 % (the first p terms) of this process.
0004 %
0005 % INPUTS
0006 %  [1] Variance                 [double]  scalar, variance of the variable.
0007 %  [2] Rho                      [double]  p*1 vector, the autocorelation function: \rho(1), \rho(2), ..., \rho(p).
0008 %  [3] p                        [double]  scalar, the number of lags in the AR process.
0009 %
0010 % OUTPUTS
0011 %  [1] InnovationVariance       [double]  scalar, the variance of the innovation.
0012 %  [2] AutoregressiveParameters [double]  p*1 vector of autoregressive parameters.
0013 %
0014 % NOTES
0015 %
0016 % The AR(p) model for {y_t} is:
0017 %
0018 %           y_t = \phi_1 * y_{t-1} +  \phi_2 * y_{t-2} + ... +  \phi_p * y_{t-p} + e_t
0019 %
0020 % Let \gamma(0) and \rho(1), ..., \rho(2) be the variance and the autocorrelation function of {y_t}. This function
0021 % compute the variance of {e_t} and the \phi_i (i=1,...,p) from the variance and the autocorrelation function of {y_t}.
0022 % We know that:
0023 %
0024 %    \gamma(0) = \phi_1 \gamma(1) + ... + \phi_p \gamma(p) + \sigma^2
0025 %
0026 % where \sigma^2 is the variance of {e_t}. Equivalently we have:
0027 %
0028 %    \sigma^2 = \gamma(0) (1-\rho(1)\phi_1 - ... - \rho(p)\phi_p)
0029 %
0030 % We also have for any integer  h>0:
0031 %
0032 %    \rho(h) = \phi_1 \rho(h-1) + ... + \phi_p \rho(h-p)
0033 %
0034 % We can write the equations for \rho(1), ..., \rho(p) using matrices. Let R be the p*p autocorelation
0035 % matrix and v be the p*1 vector gathering the first p terms of the autocorrelation function. We have:
0036 %
0037 %           v = R*PHI
0038 %
0039 % where PHI is a p*1 vector with the autoregressive parameters of the AR(p) process. We can recover the autoregressive
0040 % parameters by inverting the autocorrelation matrix: PHI = inv(R)*v.
0041 %
0042 % This function first computes the vector PHI by inverting R and computes the variance of the innovation by evaluating
0043 %
0044 %           \sigma^2 = \gamma(0)*(1-PHI'*v)
0045 
0046 % Copyright (C) 2009 Dynare Team
0047 %
0048 % This file is part of Dynare.
0049 %
0050 % Dynare is free software: you can redistribute it and/or modify
0051 % it under the terms of the GNU General Public License as published by
0052 % the Free Software Foundation, either version 3 of the License, or
0053 % (at your option) any later version.
0054 %
0055 % Dynare is distributed in the hope that it will be useful,
0056 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0057 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0058 % GNU General Public License for more details.
0059 %
0060 % You should have received a copy of the GNU General Public License
0061 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0062 AutoregressiveParameters = NaN(p,1);
0063 InnovationVariance = NaN;
0064 switch p
0065   case 1
0066     AutoregressiveParameters = Rho(1);
0067   case 2
0068     tmp = (Rho(2)-1)/(Rho(1)*Rho(1)-1);
0069     AutoregressiveParameters(1) = Rho(1)*tmp;
0070     AutoregressiveParameters(2) = 1-tmp;
0071   case 3
0072     t1 = 1/(Rho(2)-2*Rho(1)*Rho(1)+1);
0073     t2 = (1.5*Rho(1)-2*Rho(1)*Rho(1)*Rho(1)+.5*Rho(3))*t1;
0074     t3 = .5*(Rho(1)- Rho(3))/(Rho(2)-1);
0075     AutoregressiveParameters(1) = t2-t3-Rho(1);
0076     AutoregressiveParameters(2) = (Rho(2)*Rho(2)-Rho(3)*Rho(1)-Rho(1)*Rho(1)+Rho(2))*t1 ;
0077     AutoregressiveParameters(3) = t3-Rho(1)+t2;
0078   otherwise
0079     AutocorrelationMatrix = eye(p);
0080     for i=1:p-1
0081         AutocorrelationMatrix = AutocorrelationMatrix + diag(Rho(i)*ones(p-i,1),i);
0082         AutocorrelationMatrix = AutocorrelationMatrix + diag(Rho(i)*ones(p-i,1),-i);
0083     end
0084     AutoregressiveParameters = AutocorrelationMatrix\Rho;
0085 end
0086 InnovationVariance = Variance * (1-AutoregressiveParameters'*Rho);

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005