Generation of error matrix from AR(1) model, issue
1 次查看(过去 30 天)
显示 更早的评论
I want to generate a (t by n) matrix of errors (ε) , row by row, which are drawn from an AR(1) model ε_t = ρ*ε_t-1 + u_t. The problem I encountered is that from row t=3 until row t=T I get the same errors as is shown in the picture, which is odd. I get this for any t and n. Any help is appreciated! Thank you very much for your time! :)
t=5; n=10;
u_t = randn(1,n); %innovation term
epsilon = zeros(t,n); %preallocation
rho=0.5; %parameter ρ for the AR(1) model
epsilon(1,:) = randn(1,n)*sqrt(1/(1-rho^2)); %starting value of epsilon
%Draw epsilon in a vectorized way
T=2:t;
epsilon(T,:)=rho*epsilon(T-1,:) + u_t; %AR(1) model
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/926309/image.jpeg)
4 个评论
采纳的回答
VBBV
2022-3-14
编辑:VBBV
2022-3-14
t=5; n=10;
u_t = randn(1,n) %innovation term
epsilon = zeros(t,n); %preallocation
rho=0.5; %parameter ρ for the AR(1) model
epsilon(1,:) = randn(1,n)*sqrt(1/(1-rho^2)) %starting value of epsilon
%Draw epsilon in a vectorized way
for k = 2 :t
epsilon(k,:)=rho*epsilon(k-1,:) + u_t ;%AR(1) model
end
epsilon
% in vectorized way
T = 2:t;
epsilon(2:t,:) = rho*epsilon(T-1,:) + u_t
one approach is to use loop and test it ,
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!