Generation of error matrix from AR(1) model, issue
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ioannis Leivadiotis
am 14 Mär. 2022
Kommentiert: VBBV
am 30 Mär. 2022
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 Kommentare
Akzeptierte Antwort
VBBV
am 14 Mär. 2022
Bearbeitet: VBBV
am 14 Mär. 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!