**Subject: **bug in arma.sim (PR#322)

*mgri@hal.stat.unipd.it*

**Date: **Mon 15 Nov 1999 - 03:17:09 EST

**Next message:**Prof Brian D Ripley: "Re: bug in arma.sim (PR#322)"**Previous message:**Albrecht Gebhardt: "patches for alpha"**Next in thread:**Prof Brian D Ripley: "Re: bug in arma.sim (PR#322)"

Message-Id: <199911141717.SAA26416@pubhealth.ku.dk>

Dear Sir,

I think I found a bug in the function arma.sim, which is defined in

the help page of the function filter:

arma.sim <- function(n, ar = NULL, ma = NULL, sigma = 1.0)

{

x <- ts(rnorm(n+100, 0, sigma^2), start = -99)

if(length(ma)) x <- filter(x, ma, sides=1)

if(length(ar)) x <- filter(x, ar, method="recursive")

as.ts(x[-(1:100)])

}

I am using R version 0.65.0 under Linux. If I understand correctly the

way the function arma.sim is supposed to work, the instruction

arma.sim(n=200, ar=0.5, ma=0.5, sigma=1.2)

should generate values from an ARMA(1,1) model. However, the values

generated seem to come from an AR(1) model. I think this is due to the

instruction x <- filter(x, ma, sides=1) in the definition of

arma.sim, which doesn't produce the desired result. The function

defined below gives the output that my understanding of the

procedures involved would make me expect.

arma.sim <- function(n, ar = NULL, ma = NULL, sigma = 1.0)

{

x <- ts(rnorm(n+100, 0, sigma^2), start = -99)

if(length(ma)) x <- filter(x, c(1,ma), sides=1)

if(length(ar)) x <- filter(x, ar, method="recursive")

as.ts(x[-(1:100)])

}

I simply changed

x <- filter(x, ma, sides=1)

to

x <- filter(x, c(1,ma), sides=1)

Also, I wonder whether it would be more appropriate to write

rnorm(n+100, 0, sigma)

instead of

rnorm(n+100, 0, sigma^2)

since rnorm requires the standard deviation rather than the variance.

Best regards,

Matteo Grigoletto

mgri@hal.stat.unipd.it

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

r-devel 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-devel-request@stat.math.ethz.ch

_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

**Next message:**Prof Brian D Ripley: "Re: bug in arma.sim (PR#322)"**Previous message:**Albrecht Gebhardt: "patches for alpha"**Next in thread:**Prof Brian D Ripley: "Re: bug in arma.sim (PR#322)"

*
This archive was generated by hypermail 2b25
: Tue 04 Jan 2000 - 14:16:10 EST
*