Filter löschen
Filter löschen

Translation R code to Matlab

4 Ansichten (letzte 30 Tage)
Annalisa Schiavon
Annalisa Schiavon am 30 Jan. 2020
Beantwortet: Hans Scharler am 30 Jan. 2020
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
for i=1:size(CV,3)
if var1.Description~="AR-Stationary 4-Dimensional VAR(4) Model" & i>1
D = normalize(armafevd(var1.AR,[],"Method","generalized","NumObs",10,'InnovCov',EstMdl.Covariance),2, 'norm', 1);
CV(:,:,i)= D(10,:,:);
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!!

Antworten (1)

Hans Scharler
Hans Scharler am 30 Jan. 2020
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.


Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by