[R] arima.sim

Chong Gu chong at stat.purdue.edu
Fri Sep 22 22:51:29 CEST 2000


   From: "Alvaro A. Novo" <novo at uiuc.edu>
   Organization: University of Illinois at Urbana-Champaign
   Date: Fri, 22 Sep 2000 14:49:38 -0500
   X-Mailer: KMail [version 1.1.94]
   Content-Type: text/plain
   MIME-Version: 1.0
   Content-Transfer-Encoding: 8bit
   Sender: owner-r-help at stat.math.ethz.ch
   Precedence: bulk

   Hi,

   Before I re-invent the wheel, is there a function in R similar to S+'s 
   arima.sim, i.e., a function that simulates arima processes.

   ts and tseries packages don't seem to have such function, but I may have 
   overlooked it.

   Thank you for your time,

   Alvaro Novo
   R Version 1.1.1
   SuSE 6.4 Linux
   KDE 2.0 Beta 5
   -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
   r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
   Send "info", "help", or "[un]subscribe"
   (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
   _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Here is one I wrote for teaching last Spring.  Use it at you own risk,
and if you do use it, let me know any problems if you find any.  The
MA coefficients follow the "usual" convention as in Box&Jenkins, which
have opposite signs compared to the ones in the ts package.

Chong Gu


sim.arima <- function(n=100,ar=NULL,ma=NULL,ndiff=NULL,burn=100)
{
    d <- ndiff
    if (is.null(d)) d <- 0
    p <- length(ar)
    q <- length(ma)
    nn <- n+burn+p
    wn <- rnorm(nn+q)
    if (q>0) {
      ind <- 1:nn
      wk <- wn[ind+q]
      for (i in q:1) wk <- wk - ma[i]*wn[ind+q-i]
    }
    else  wk <- wn
    if (p>0) {
      xx <- wk[1:p]
      for (i in 1:(n+burn)) {
        xx.wk <- wk[i+p]
        for (j in 1:p) xx.wk <- xx.wk + ar[j]*xx[i+p-j]
        xx <- c(xx,xx.wk)
      }
    }
    else  xx <- wk
    if (d>0) {
      xx <- c(rep(0,d),xx)
      for (i in 1:d) {
        xx <- cumsum(xx)
      }
    }
    ts(xx[burn+d+(1:n)])
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list