3

when I fit the ARMA model by using the function

fit<-arima(data,order = c(1,0,1),method="ML")

I got this message

possible convergence problem: optim gave code = 1

can anyone help me to solve this problem


An example: if I repeat this an number of times I receive convergence warnings

set.seed(2)
n <- 100
for(i in 1:1000) {
     sim <- arima.sim(list(ar=c(0.9,-0.4),ma=c(-1.2,0.3)),n=n) 
     fit <- arima(sim, order = c(1,0,1), method="ML")
}
user20650
  • 24,654
  • 5
  • 56
  • 91
Oday Dassi
  • 51
  • 1
  • 7
  • You should provide some sort of [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can recreate the problem and help you understand what's going on. – MrFlick May 28 '16 at 20:57
  • i generate the data by sim<-arima.sim(list(ar=0.7,ma=c(-0.7,0.15)),n=n) normal distribution with mean 0 and variance 1 and the number of observation is 100 – Oday Dassi May 28 '16 at 21:01
  • when i simulate this fitted model 10,000 times i got this message – Oday Dassi May 28 '16 at 21:03
  • Please take the time to read the link provided by MrFlick and edit your question accordingly. – lmo May 28 '16 at 21:05
  • An example is needed , but looking at `?optim` it would seem that a `1` indicates that the max number of iterations has been met. So looking at `?arima`, the next step would be to increase this by changing the iterations in the `optim.control` argument. – user20650 May 28 '16 at 21:26
  • libraray{forecast} n<-100 sim<-arima.sim(list(ar=c(1.1,-0.35)),n=n,innov=fun) fit<-arima(sim,order = c(1,0,1),method="ML") simulate 10,000 time I got this message possible convergence problem: optim gave code = 1 – Oday Dassi May 28 '16 at 21:31
  • first step simulate data by using this function sim<-arima.sim(list(ar=0.7,ma=c(-0.7,0.15)),n=n) – Oday Dassi May 28 '16 at 21:39
  • second fit model by using fit<-arima(sim,order = c(1,0,1),method="ML") – Oday Dassi May 28 '16 at 21:40
  • user20650 please can you use this example sim<-arima.sim(list(ar=c(0.9,-0.4),ma=c(-1.2,0.3)),n=n) – Oday Dassi May 28 '16 at 21:48
  • @OdayDassi; that runs okay for me. As you are using random generated numbers, you need to use set.seed to make it reproducible. So for example, `set.seed(1) ; sim <- arima.sim(...)` – user20650 May 28 '16 at 21:51
  • But from my previous comments, did you try and change the number of iterations. For example, `set.seed(1) ; sim <- arima.sim(list(ar=c(0.9,-0.4),ma=c(-1.2,0.3)),n=n) ; fit <- arima(sim, order = c(1,0,1), method="ML", optim.control = list(maxit=10))` throws the convergence warning that you get but by increasing the iterations manually it does not `fit <- arima(sim, order = c(1,0,1), method="ML", optim.control = list(maxit=100))` – user20650 May 28 '16 at 21:54
  • user20650; please could you tell me if you run this example 10,000 times or just one time, when i run this example in one time i dont have problem with it but with 10,000 time i got problem – Oday Dassi May 28 '16 at 21:55
  • user20650; i am running the example that you gave me sim <- arima.sim(list(ar=c(0.9,-0.4),ma=c(-1.2,0.3)),n=n) ; fit <- arima(sim, order = c(1,0,1), method="ML", optim.control = list(maxit=10)) with 10,000 simulation – Oday Dassi May 28 '16 at 21:59
  • okay, I edited your question with an example that gives a warning. Using the example that i added to your question, if you change the control to `fit <- arima(sim, order = c(1,0,1), method="ML", optim.control = list(maxit=200))` it should converge. (This is a common problem when using optimisation routines, and in a simulation you should expect some iterations not to converge) – user20650 May 28 '16 at 22:02
  • 2
    dear user20650; i run the example and i did not get any warning message many thanks for your help – Oday Dassi May 28 '16 at 22:18
  • Dear user20650; could you tell me please why i cannot fit another model by using the same method that you gave me it for example sim<-arima.sim(list(ar=c(1.3,-0.35)),n=n) ;;;fit <- arima(sim, order = c(1,0,1), method="ML", optim.control = list(maxit=200)), could you tell me please how i can fit the number of iterations for other model. is there any role for optim.control = list(maxit=200) – Oday Dassi May 29 '16 at 11:42
  • I dont know anything about time-series, so first you need to make sure that your simulations are reasonable. But going back to my previous comment above, convergence is not guaranteed. Anyway, I would try changing the number of iterations, and the optimisation algorithm to see if it helps (although the BFGS is the default for a reason). If not I would wrap `arima` in `try` so that when you are looping through the simulations, it continues if it throws an error. – user20650 May 29 '16 at 12:28
  • ps. if you use @user20650, I will be notified that you have left a comment – user20650 May 29 '16 at 12:37
  • Dear user20650; i have used this method sim<-arima.sim(list(ar=c(1.3,-0.35)),n=n) fit <- arima(sim, order = c(1,0,1), method="ML", include.mean = TRUE, transform.pars = TRUE,optim.method = "BFGS", optim.control = list(maxit=200)), but i still get the same problem – Oday Dassi May 29 '16 at 12:47
  • Well BFGS is the default - did you try other methods? Have a look at `?optim` to see other algorithms. Also `maxit` can also be greater than 200. But as I have commented, there is no guarantee of convergence. So you need to come up with a strategy to deal with this - which is why i suggested using `try`. – user20650 May 29 '16 at 12:51
  • Dear user20650; what do you mean by using try. is it a function in R. i have already increase the iterations but the same problem – Oday Dassi May 29 '16 at 13:05
  • It is. In the following example, an error is thrown in one of the iterations, that will stop the loop. You can use `try` to allow the loop to continue. `fit <- vector("list", length=1000) ; set.seed(2) ; for(i in 1:1000){ sim<-arima.sim(list(ar=c(1.3,-0.35)),n=n) ; fit[[i]] <- try(arima(sim, order = c(1,0,1), method="ML", optim.control = list(maxit=600))) }`. So you will still have an error (at `fit[[353]]`), but it allows the simulation to continue. Perhaps this is agood enough strategy for what you are doing. – user20650 May 29 '16 at 13:11
  • To see the iterations that throw the error, you can use `s <- sapply(fit, function(x) inherits(x, "try-error"))`, the number of errors `sum(s)`, and which iteration `which(s)`. (you can see it with `fit[which(s)]` – user20650 May 29 '16 at 13:17
  • so this is the function of fitted the number of iterations s <- sapply(fit, function(x) inherits(x, "try-error")) – Oday Dassi May 29 '16 at 13:24
  • `s` is a vector of length 1000 of `TRUE` and `FALSE` - `TRUE` if there was an error. (note: this will not catch convergence warnings!). The idea of using `try`, is just to allow the loop to go through all iterations, as otherwise it stops when there is an error. – user20650 May 29 '16 at 13:29
  • Dear user20650 finally i got the correct function and without any wearing error sim<-arima.sim(list(ar=c(1.3,-0.35)),n=n) , try<-try(arima(sim,order = c(1,0,1), method="CSS",optim.method = "BFGS", optim.control = list(maxit=350))) – Oday Dassi May 29 '16 at 14:10
  • Great stuff... got there in the end – user20650 May 29 '16 at 15:25

0 Answers0