Skip to content

arima() bug

6 messages · Ray Brownrigg, Antonio, Fabio Di Narzo, Simone Giannerini +2 more

#
I guess this is more r-devel than r-help.

Note, I am just the messenger - I have no idea what the user is trying to model here.

arima() crashes R (segfault) with Linux R-2.7.0, Solaris R-2.6.0:

 *** caught segfault ***
address 42400000, cause 'memory not mapped'

Traceback:
 1: .Call(R_getQ0, phi, theta)
 2: makeARIMA(trarma[[1]], trarma[[2]], Delta, kappa)
 3: arima(x, c(1, 0, 1), c(1, 0, 1))

Under rw-2.7.0 or R version 2.8.0 Under development (unstable) (2008-06-10 r45893)
it gets:
Error: cannot allocate vector of size 1010.9 Mb
In addition: Warning messages:
1: In makeARIMA(trarma[[1]], trarma[[2]], Delta, kappa) :
  Reached total allocation of 447Mb: see help(memory.size)
2: In makeARIMA(trarma[[1]], trarma[[2]], Delta, kappa) :
  Reached total allocation of 447Mb: see help(memory.size)
3: In makeARIMA(trarma[[1]], trarma[[2]], Delta, kappa) :
  Reached total allocation of 447Mb: see help(memory.size)
4: In makeARIMA(trarma[[1]], trarma[[2]], Delta, kappa) :
  Reached total allocation of 447Mb: see help(memory.size)

Reproduce by:

# 2 years of daily temperature data
set.seed(1); x <- ts(20*sin((1:731)*2*pi/365) + 10 + rnorm(731, 0, 4), freq=365)
arima(x, c(1, 0, 1), c(1, 0, 1))

Ray Brownrigg
#
No segfault with my r-patched version on linux-i686:
Errore: cannot allocate vector of size 1010.9 Mb

F.
_
platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status         Patched
major          2
minor          7.0
year           2008
month          05
day            29
svn rev        45820
language       R
version.string R version 2.7.0 Patched (2008-05-29 r45820)


2008/6/12 Ray Brownrigg <Ray.Brownrigg at mcs.vuw.ac.nz>:

  
    
#
On Thu, 12 Jun 2008, Antonio, Fabio Di Narzo wrote:

            
Yes, you need a lot of memory to reproduce it.  It's a nonsensical 
calculation but nevertheless we need to track down the cause.

  
    
#
On Thu, 12 Jun 2008, Ray Brownrigg wrote:

            
I put a breakpoint in Rf_allocVector when its length argument
was more than 10 million and it stopped when library/stats/src/arima.c:getQ0
asked for a vector of nrbar=132497980 doubles, a number proportional
to the 4th power of max(length(phi),length(theta)) from the R arima():upARIMA()
function:

SEXP getQ0(SEXP sPhi, SEXP sTheta)
{
    ...
    int  p = LENGTH(sPhi), q = LENGTH(sTheta);
    ...
    int r = max(p, q + 1), np = r * (r + 1) / 2, nrbar = np * (np - 1) / 2;
    ...
    rbar = (double *) R_alloc(nrbar, sizeof(double));

(gdb) print nrbar
$1 = 132497980
(gdb) print np
$2 = 67528
(gdb) print r
$3 = 367
(gdb)  print q
$4 = 366

Trying to recover from running out of memory probably
causes the crash.

rbar is a scratch array.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."
2 days later
#
On Thu, 12 Jun 2008, Prof Brian Ripley wrote:

            
Which is an integer overflow in an integer calculation of a dimension. 
The current code is only able to code with lags up to 350, and this is 
attempting a fit with lag 366.  I've added an explicit check.