11# File src/library/stats/R/arma0.R
22# Part of the R package, https://www.R-project.org
33#
4- # Copyright (C) 1999-2019 The R Core Team
4+ # Copyright (C) 1999-2025 The R Core Team
55#
66# This program is free software; you can redistribute it and/or modify
77# it under the terms of the GNU General Public License as published by
1616# A copy of the GNU General Public License is available at
1717# https://www.R-project.org/Licenses/
1818
19- arima0 <- function (x , order = c(0 , 0 , 0 ),
20- seasonal = list (order = c(0 , 0 , 0 ), period = NA ),
19+ arima0 <- function (x , order = c(0L , 0L , 0L ),
20+ seasonal = list (order = c(0L , 0L , 0L ), period = NA ),
2121 xreg = NULL , include.mean = TRUE , delta = 0.01 ,
2222 transform.pars = TRUE , fixed = NULL , init = NULL ,
2323 method = c(" ML" , " CSS" ), n.cond ,
@@ -41,7 +41,7 @@ arima0 <- function(x, order = c(0, 0, 0),
4141 {
4242 # # polyroot can't cope with leading zero.
4343 q <- length(ma )
44- q0 <- max(which(c(1 ,ma ) != 0 )) - 1
44+ q0 <- max(which(c(1 ,ma ) != 0 )) - 1L
4545 if (! q0 ) return (ma )
4646 roots <- polyroot(c(1 , ma [1L : q0 ]))
4747 ind <- Mod(roots ) < 1
@@ -55,9 +55,10 @@ arima0 <- function(x, order = c(0, 0, 0),
5555 }
5656
5757 series <- deparse1(substitute(x ))
58- if (NCOL(x ) > 1 )
58+ if (NCOL(x ) > 1L )
5959 stop(" only implemented for univariate time series" )
6060 method <- match.arg(method )
61+
6162 x <- as.ts(x )
6263 if (! is.numeric(x ))
6364 stop(" 'x' must be numeric" )
@@ -72,12 +73,13 @@ arima0 <- function(x, order = c(0, 0, 0),
7273 if (is.null(seasonal $ order ))
7374 stop(" 'seasonal' must be a list with component 'order'" )
7475 if (! is.numeric(seasonal $ order ) || length(seasonal $ order ) != 3L
75- || any(seasonal $ order < 0 ))
76+ || any(seasonal $ order < 0L ))
7677 stop(" 'seasonal$order' must be a non-negative numeric vector of length 3" )
77- } else if (is.numeric(order )) {
78- if (length(order ) == 3 ) seasonal <- list (order = seasonal )
79- else (" 'seasonal' is of the wrong length" )
80- } else stop(" 'seasonal' must be a list with component 'order'" )
78+ } else if (is.numeric(seasonal )) { # meant to be seasonal$order
79+ if (length(seasonal ) != 3L || any(seasonal < 0 ))
80+ stop(" if not a list, 'seasonal' must be a non-negative numeric vector of length 3" )
81+ seasonal <- list (order = seasonal )
82+ } else stop(" 'seasonal' is neither a list with component 'order' nor a numeric vector of length 3" )
8183
8284 if (is.null(seasonal $ period ) || is.na(seasonal $ period )
8385 || seasonal $ period == 0 ) seasonal $ period <- frequency(x )
@@ -167,15 +169,15 @@ arima0 <- function(x, order = c(0, 0, 0),
167169 if (! arCheck(init [1L : arma [1L ]]))
168170 stop(" non-stationary AR part" )
169171 if (arma [3L ] > 0 )
170- if (! arCheck(init [sum(arma [1L : 2 ]) + 1L : arma [3L ]]))
172+ if (! arCheck(init [sum(arma [1L : 2L ]) + 1L : arma [3L ]]))
171173 stop(" non-stationary seasonal AR part" )
172174 # # enforce invertibility
173175 if (arma [2L ] > 0 ) {
174176 ind <- arma [1L ] + 1L : arma [2L ]
175177 init [ind ] <- maInvert(init [ind ])
176178 }
177179 if (arma [4L ] > 0 ) {
178- ind <- sum(arma [1L : 3 ]) + 1L : arma [4L ]
180+ ind <- sum(arma [1L : 3L ]) + 1L : arma [4L ]
179181 init [ind ] <- maInvert(init [ind ])
180182 }
181183 init <- .Call(C_Invtrans , G , as.double(init ))
@@ -210,12 +212,12 @@ arima0 <- function(x, order = c(0, 0, 0),
210212 class(resid ) <- " ts"
211213 n.used <- sum(! is.na(resid ))
212214 nm <- NULL
213- if (arma [1L ] > 0 ) nm <- c(nm , paste0(" ar" , 1L : arma [1L ]))
214- if (arma [2L ] > 0 ) nm <- c(nm , paste0(" ma" , 1L : arma [2L ]))
215- if (arma [3L ] > 0 ) nm <- c(nm , paste0(" sar" , 1L : arma [3L ]))
216- if (arma [4L ] > 0 ) nm <- c(nm , paste0(" sma" , 1L : arma [4L ]))
215+ if (arma [1L ] > 0L ) nm <- c(nm , paste0(" ar" , 1L : arma [1L ]))
216+ if (arma [2L ] > 0L ) nm <- c(nm , paste0(" ma" , 1L : arma [2L ]))
217+ if (arma [3L ] > 0L ) nm <- c(nm , paste0(" sar" , 1L : arma [3L ]))
218+ if (arma [4L ] > 0L ) nm <- c(nm , paste0(" sma" , 1L : arma [4L ]))
217219 fixed [mask ] <- coef
218- if (ncxreg > 0 ) {
220+ if (ncxreg > 0L ) {
219221 nm <- c(nm , cn )
220222 if (! orig.xreg ) {
221223 ind <- narma + 1L : ncxreg
@@ -255,11 +257,9 @@ print.arima0 <- function(x, digits = max(3L, getOption("digits") - 3L),
255257 print.default(coef , print.gap = 2 )
256258 cm <- x $ call $ method
257259 if (is.null(cm ) || cm != " CSS" )
258- cat(" \n sigma^2 estimated as " ,
259- format(x $ sigma2 , digits = digits ),
260- " : log likelihood = " , format(round(x $ loglik ,2 )),
261- " , aic = " , format(round(x $ aic ,2 )),
262- " \n " , sep = " " )
260+ cat(" \n sigma^2 estimated as " , format(x $ sigma2 , digits = digits ),
261+ " : log likelihood = " , format(round(x $ loglik , 2L )),
262+ " , aic = " , format(round(x $ aic , 2L )), " \n " , sep = " " )
263263 else
264264 cat(" \n sigma^2 estimated as " ,
265265 format(x $ sigma2 , digits = digits ),
@@ -294,12 +294,12 @@ predict.arima0 <-
294294 xm <- drop(as.matrix(newxreg ) %*% coefs [- (1L : narma )])
295295 } else xm <- 0
296296 # # check invertibility of MA part(s)
297- if (arma [2L ] > 0 ) {
297+ if (arma [2L ] > 0L ) {
298298 ma <- coefs [arma [1L ] + 1L : arma [2L ]]
299299 if (any(Mod(polyroot(c(1 , ma ))) < 1 ))
300300 warning(" MA part of model is not invertible" )
301301 }
302- if (arma [4L ] > 0 ) {
302+ if (arma [4L ] > 0L ) {
303303 ma <- coefs [sum(arma [1L : 3L ]) + 1L : arma [4L ]]
304304 if (any(Mod(polyroot(c(1 , ma ))) < 1 ))
305305 warning(" seasonal MA part of model is not invertible" )
0 commit comments