Translation R code to Matlab

조회 수: 5 (최근 30일)
Annalisa Schiavon
Annalisa Schiavon 2020년 1월 30일
답변: Hans Scharler 2020년 1월 30일
Hi, I am trying to translate an R code into Matlab, and with this piece of code i get different result and I don't understand the problem! This is the Matlab code
t=size(Y,1);
space=200;
nlag=4
CV=NaN(k,k,(t-space));
for i=1:size(CV,3)
var=varm(4,4);
var1=estimate(var,Y(i:(space+i-1),:));
if var1.Description~="AR-Stationary 4-Dimensional VAR(4) Model" & i>1
CV(:,:,i)=CV(:,:,(i-1));
else
D = normalize(armafevd(var1.AR,[],"Method","generalized","NumObs",10,'InnovCov',EstMdl.Covariance),2, 'norm', 1);
CV(:,:,i)= D(10,:,:);
end
end
and this is the R code
t = nrow(Y)
space = 200 # 200 days rolling window estimation
CV = array(NA, c(k, k, (t-space)))
colnames(CV) = rownames(CV) = colnames(Y)
for (i in 1:dim(CV)[3]) {
var1 = VAR(Y[i:(space+i-1),], p=nlag, type="const")
if(any(roots(var1)>1) & i>1){ # controls if the VAR process is stationary
CV[,,i] = CV[,,(i-1)]
} else {
CV[,,i] = gfevd(var1, n.ahead=nfore)$fevd
}
The VAR estimated coefficients are equal but the when it does the variance decomposition the results are different. So I guess it is a problem of how I do the loop. Can anyone spot the mistake? thanks!!

답변 (1개)

Hans Scharler
Hans Scharler 2020년 1월 30일
I don't have a direct answer, but you could use a COM-based interface to call your R function from within MATLAB. There is a project on File Exchange that might help if you are usign Windows.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by