na_kalman: possible convergence problem: 'optim' gave code = 52 and message 'ERROR: ABNORMAL_TERMINATION_IN_LNSRCH'
SteffenMoritz opened this issue · 0 comments
Sometime this warning appears:
possible convergence problem: 'optim' gave code = 52 and message 'ERROR: ABNORMAL_TERMINATION_IN_LNSRCH'
e.g. for:
x <- tsAirgap
x[1:2] <- NA
na_kalman(x)
This issue only arises for very specific inputs. It is an indication/warning, that fitting the structural time series model did not work out ideally.
As it is only a warning and still leads to resulting imputations ignoring this message is a possibility.
(in this case you should check very closely that the resulting imputations are reasonable)
.
The warning itself does not come from imputeTS directly, but from a package that is called within imputeTS.
(the function StructTS
from the package stats, which uses a call to optim
, where the warning is given)
This optim
function is used to fit a structural time series model, as fitting the best model is an optimization task.
For some inputs this optimization does not converge (sometimes also just not fast enough).
Best Workaround (in case the imputation results are poor) is probably to just use another imputation function.
An advanced fix would be trying to set parameters for optim - using parameter pass through in imputeTS to underlying functions.
StructTS
has an optim.control
parameter, which can be used to supply a list of control parameters to 'optim
'. This one can be used in the imputeTS call to adjust the optimization process (example see below).
E.g. it can be tried if the optimization converges with more iterations:
(a lot more optimization control parameters can be specified - see under Details in the optim
documentation https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/optim )
Example of advanced parameter pass through:
# create list with optim.control parameters
new_param <- list(maxit = 3000)
# Call na_kalman additionally supplying the specified list as optim.control variable
na_kalman(your_data, optim.control = new_param)
This parameter pass through will not always lead to the result that the message disappears and the convergence issues are solved, but sometimes it helps.