Skip to content

Commit

Permalink
fix PR#15068 and more
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@60904 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Oct 8, 2012
1 parent 95db153 commit eda9c0e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/NEWS.Rd
Expand Up @@ -980,6 +980,9 @@
\item The code for creating \code{coerce()} methods could
generate false notes about ambiguous selection; the notes have
been suppressed for this function.

\item \code{arima.sim()} could give too long an output in some
corner cases (in part, \PR{15068}).
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/library/stats/R/ts.R
Expand Up @@ -765,6 +765,7 @@ arima.sim <- function(model, n, rand.gen = rnorm,
start.innov = rand.gen(n.start, ...), ...)
{
if(!is.list(model)) stop("'model' must be list")
if(n <= 0L) stop("'n' must be strictly positive")
p <- length(model$ar)
if(p) {
minroots <- min(Mod(polyroot(c(1, -model$ar))))
Expand All @@ -788,13 +789,13 @@ arima.sim <- function(model, n, rand.gen = rnorm,
"'start.innov' is too short: need %d point",
"'start.innov' is too short: need %d points"),
n.start), domain = NA)
x <- ts(c(start.innov[1L:n.start], innov[1L:n]), start = 1 - n.start)
x <- ts(c(start.innov[seq_len(n.start)], innov[1L:n]), start = 1 - n.start)
if(length(model$ma)) {
x <- filter(x, c(1, model$ma), sides = 1L)
x[seq_along(model$ma)] <- 0 # rather than NA
}
if(length(model$ar)) x <- filter(x, model$ar, method = "recursive")
if(n.start > 0) x <- x[-(1L:n.start)]
if(n.start > 0) x <- x[-(seq_len(n.start))]
if(d > 0) x <- diffinv(x, differences = d)
as.ts(x)
}
7 changes: 4 additions & 3 deletions src/library/stats/man/arima.sim.Rd
@@ -1,6 +1,6 @@
% File src/library/stats/man/arima.sim.Rd
% Part of the R package, http://www.R-project.org
% Copyright 1995-2007 R Core Team
% Copyright 1995-2012 R Core Team
% Distributed under GPL 2 or later

\name{arima.sim}
Expand All @@ -18,9 +18,10 @@ arima.sim(model, n, rand.gen = rnorm, innov = rand.gen(n, \dots),
\arguments{
\item{model}{A list with component \code{ar} and/or \code{ma} giving
the AR and MA coefficients respectively. Optionally a component
\code{order} can be used. An empty list gives an ARIMA(0, 0, 0)
\code{order} can be used. An empty list gives an ARIMA(0, 0, 0)
model, that is white noise.}
\item{n}{length of output series, before un-differencing.}
\item{n}{length of output series, before un-differencing. A stricly
positive integer.}
\item{rand.gen}{optional: a function to generate the innovations.}
\item{innov}{an optional times series of innovations. If not
provided, \code{rand.gen} is used.}
Expand Down
10 changes: 10 additions & 0 deletions tests/reg-tests-1b.R
Expand Up @@ -1979,8 +1979,18 @@ if(is.na(z[2]) || is.na(z10[2])) {
} else stopifnot(z[2] > z10[2])
## Previous test ould be defeated by compiler optimization.


##
options(max.print=.Machine$integer.max)
1 ## segfaulted because of integer overflow
stopifnot(identical(.Machine$integer.max, getOption("max.print")))
##

## corner cases for arima.sim(), in part PR#15068
stopifnot(length(arima.sim(list(order = c(0,0,0)), n = 10)) == 10)
stopifnot(inherits(try(arima.sim(list(order = c(1,0,0), ar = 0.7), n = 0)),
"try-error"))
## one too long in R < 2.15.2


proc.time()

0 comments on commit eda9c0e

Please sign in to comment.