>>>>> 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.
    >>>> I have found:
    >>>> 1. A missing stop() call at line 69:
    >>>>  if (length(order) == 3) seasonal <- list(order = seasonal) else
    >>>>    ("\'seasonal\' is of the wrong length")
    >>>> it should be rather:
    >>>> if (length(order) == 3) seasonal <- list(order = seasonal) else
    >>>> stop("\'seasonal\' is of the wrong length")
    >>> 
    >>> I think you're right about this one.

well, actually, the mishap is larger:

Reading the help page for arima,  'seasonal' is documented as

 seasonal: A specification of the seasonal part of the ARIMA model, plus
           the period (which defaults to ‘frequency(x)’).  This may be a
           list with components ‘order’ and ‘period’, or just a numeric
           vector of length 3 which specifies the seasonal ‘order’.  In
           the latter case the default period is used.

Note the
    or just a numeric vector of length 3 ... the seasonal 'order'
part.
If you look at the larger context of the

   else ("'seasonal...

part, it becomes clear that -- in order to fulfill the above
documented behavior, it's not length(order),
but length(seasonal) which should be 3   which leads to the
following change :

@@ -124,10 +124,11 @@
             if(!is.numeric(seasonal$order) || length(seasonal$order) != 3L
                || any(seasonal$order < 0L))
                 stop("'seasonal$order' must be a non-negative numeric vector 
of length 3")
-        } else if(is.numeric(order)) {
-            if(length(order) == 3L) seasonal <- list(order=seasonal)
-            else ("'seasonal' is of the wrong length")
-        } else stop("'seasonal' must be a list with component 'order'")
+        } else if(is.numeric(seasonal)) { # meant to be  seasonal$order
+            if(length(seasonal) != 3L || any(seasonal < 0))
+                stop("if not a list, 'seasonal' must be a non-negative numeric 
vector of length 3")
+            seasonal <- list(order=seasonal)
+        } else stop("'seasonal' must be a list with component 'order' or 
length-3 vector")
 

... I still plan to commit this, but it may well be that this
change will wake up arima() use that was buggy and never detected
till now.

Martin

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to