From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Fri Jan  3 17:22:34 2025
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Fri, 3 Jan 2025 17:22:34 +0100
Subject: [Rd] Possible issue in stats/arima.R package
In-Reply-To: <26486.60482.328642.701605@stat.math.ethz.ch>
References: <CAMUMQUSh5t2sazypdiAeOSJ2MQssNfb89jQJvvBwRbA1PwAqeA@mail.gmail.com>
 <822e67f1-5900-4355-b231-a09c8691d4ae@gmail.com>
 <e93186db-914d-41cf-b1df-46cbc90af3b6@gmail.com>
 <26486.60482.328642.701605@stat.math.ethz.ch>
Message-ID: <26488.3786.644216.114494@stat.math.ethz.ch>

>>>>> Martin Maechler on Thu, 2 Jan 2025 20:42:58 +0100 writes:
  >>>>> Duncan Murdoch on Thu, 2 Jan 2025 11:28:45 -0500 writes:

    >> On 2025-01-02 11:20 a.m., Duncan Murdoch wrote:
    >>> On 2025-01-02 9:04 a.m., Norbert Kuder wrote:
    >>>> Hello all,
    >>>> 
    >>>> I am running R version 4.4.2 (2024-10-31 ucrt) on Windows 10 x64, and
    >>>> noticed something that might be a minor bug (or at least inconsistent code)
    >>>> in the stats/arima.R package.

    ....................

    >>>> 2. An unused 'mod' variable assignment at line 190:
    >>>> 
    >>>> mod <- makeARIMA(trarma[[1]], trarma[[2]], Delta, kappa, SSinit)
    >>>> 
    >>>> I am trying to confirm whether this is intended behavior or possibly an
    >>>> overlooked detail. Could someone please clarify if the current logic is
    >>>> correct?

    >> Mystery solved:  code like this appears several times in that file.  In 
    >> the occurrence here:

    >> https://github.com/wch/r-source/blob/4a1ed749271c52e60a85e794e6f34b0831efb1ae/src/library/stats/R/arima.R#L293

    >> it does appear that the mod value isn't being used.

    >> Duncan Murdoch

    > Thank you, Norbert and Duncan.
    > A little bit (unfinished)  aRcheology showed that both parts
    > have been in the arima code since Dec 11 2003 (when the code, i.e., the
    > whole package 'ts') was moved / merged into package 'stats'.

    > I'll fix and quickly test the change, and then commit it.

and testing quickly revealed what is obvious in hindsight:
When minimizing the negative log likelihood, in

    optim(<p>, armafn, ...)

the armafn() is called of course and it *does* need the model,
i.e., `mod`.

==> the 2nd "inconsistency  was *not* a mistake at all: The

    mod <- makeARIMA(....)

line has clearly been necessary all along.

Martin



[Rd] Possible issue in stats/arima.R package
Martin Maechler