Suppose that I have the following loop for estimating ARMA models on a 
series of log-returns. The loop varies both the p and the q orders 
between 0 and 10. The returned objects are the matrices of respectively 
the Akaike Information Criterion indicators for model goodness of fit, 
the model equation coefficients, the p-values of the Augmented Dickey 
Fuller test for stationarity of the residuals, the p-values of Box Ljung 
tests for serial uncorrelation and independence of the residuals and the 
p-values of the Jarque Bera test for normality of the residuals.

My questions are:

1)How do you tell R not to display the AIC, the model coefficients and 
all the tests p-values in the case the estimated ARMA model features 
convergence problems? That would probably require to specify an IF 
condition in the loop which I am not currently able to do.

2)Take a look at the “fit degrees of freedom” argument of the Box tests 
for serial uncorrelation and independence. There I need to tell R to fit 
a number of degrees of freedom which equals p+q (the sum of the orders 
of the estimated ARMA model). Is it correct to write fitdf=i+j+2 as I did?

3)How could I loop for a third variable which is 
“include.mean=TRUE/FALSE”? I tried to loop over a third, string-type 
variable z<-c(TRUE,FALSE) but always got the error message: “error no 
'dimnames' attribute for array”.

Please note that I am an R beginner. So any help from anybody is deeply 

Here follows the code.


armaaicmat=matrix(NA, 11, 11)


armaadftestmat=matrix(NA, 11, 11)

armaboxtestmat=matrix(NA, 11, 11)

armaboxtest2mat=matrix(NA, 11, 11)

armajarqueberamat=matrix(NA, 11, 11)


for(i in 0:10){

for(j in 0:10){


fit <- arima(USDlogreturns, order=c(i,0,j), include.mean=TRUE)

armaaicmat[i+1,j+1] = fit$aic

if(i>0) armacoefmat[k,c(1:i) ]=fit$coef[c(1 :i )]

if(j>0) armacoefmat[k,c(13:(12+j))]=fit$coef[c((i+1):(i+j))]



armaboxtestmat[i+1,j+1]=Box.test(fit$resid, fitdf=i+j+2, 

armaboxtest2mat[i+1,j+1]=Box.test(fit$resid^2, fitdf=i+j+2, 




Questa e-mail è stata controllata per individuare virus con Avast antivirus.

        [[alternative HTML version deleted]]

R-SIG-Finance@r-project.org mailing list
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should 

Reply via email to