VAR 模型将单变量自回归 (AR) 模型推广到多个时间序列。我想实现一个向量自回归模型,它根据时间 t 的观察概述了以下公式:
x(t) = c + (t-1)∑(i = t + T)* a(i)x(i) + €(t)
a(i) = 模型参数 €(t) = 高斯噪声
我使用的数据非常大,所以我不会发布它,但我需要帮助的一件事是输出任何合成数据的邻接矩阵。这就是我所拥有的:
function [ beta, adj,results ] = granger( id, t, X, lambda, lag, param )
%GRANGER Graphical Granger Modeling
% INPUTS: id = Column with n elements of unique subject identifiers used to indicate
% measurements from the same subjects.
% t = Column with n elements of measurement times corresponding to id.
% NB: AT THE MOMENT ASSUMING EQUISPACED DATA.
% X = n-by-(p+1) Matrix of covariates corresponding to id and t.
% lambda = tunning parameter for the penalty terms.
% param = Struct of any other parameters you want to pass to your
% code.
% lag = value of time lag to look backward from current time.
% OUTPUTS: bhat = estimated effects parameters corresponding to X.
% adj = adjacency matrix among the columns of X.
% results = Struct of any other results you want to send out
% from your code.
if nargin<5; param={}; end;
% if ~isfield(param,'maxIt'); param.maxIt = 1000; end %For example, set max iterations as 1000.
% if ~isfield(param,'tol'); param.tol = 0.00001; end; % Convergence tolerance;
a = ucf.x;
b = ucf.y;
end