[R] R 3.1.2 : arima.sim(model=list(ma=0.5), n=250, innov=rnorm(250, mean=0, sd=0.1)) versus arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1) => only the first element is not identical !

Mark Leeds markleeds2 at gmail.com
Sat Jul 11 17:38:56 CEST 2015


Hi Fabian: I think one would say that that is not a bug. I looked at the
details of arima.sim ( using debug(arima.sim) )
 and there are two different series that are created inside the function.
one is called innov and the other is start.innov. start.innov is
used to create a burn in period for the constructed series.

in your test1 call, you are not  supplying arguments for what should be
used for the innovations associated with start.innov which is used for the
burn in period. So, arima.sim  uses the defaults of mean = 0 and sd = 1.0.
For your test2 call, you do provide them ( so they are used for both innov
and start.innov )  and you use  sd = 0.1 So, for test2,  the values  for
the burn in period end up being different from the ones in test1.

Below, I made a test3 that can be used to get the same values as test2. In
short, by specifiying the innov call EXACTLY in test1, you're letting
arima.sim use the default arguments for the start.innov call so that's why
they're different.


#====================================================================================================================
 ##undebug(arima.sim)

set.seed(123);
test1 <- arima.sim(model=list(ma=0.5), n =
250,innov=rnorm(250,mean=0,sd=0.1))
print(head(test1))

set.seed(123);
test2 <- arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1)
print(head(test2))

set.seed(123);
test3 <- arima.sim(model=list(ma=0.5), innov = rnorm(250,mean=0, sd=0.1), n
= 250, mean=0, sd=0.1)
print(head(test3))

On Sat, Jul 11, 2015 at 3:46 AM, Fabien Tarrade <fabien.tarrade at gmail.com>
wrote:

> Dear all,
>
> When doing a DataCamp tutorial with R I find the following observation
> that using 2 different syntax for "arima.sim" give different answer for the
> first element
>
> If I use the the function using the list of argument describe in the help
> manual :
> arima.sim(model=list(ma=0.5),n=250,innov=rnorm(250,mean=0,sd=0.1))
>
> or if I use the following syntax use in a DataCamp example :
>
> arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1) it is accepted by
> DataCamp
>
> I don't find exactly the same results. The reason is that even if the seed
> is the same in both cases the first element is not identical while it
> should be (it doesn't mean that the results is wrong, maybe for the first
> element the seed is not propagated correctly)
>
> here the results of the difference using the same seed (only the first
> element is different using the 2 different syntaxes) :
>
>   [1] -0.252214  0.000000  0.000000  0.000000  0.000000  0.000000
> 0.000000  0.000000  0.000000  0.000000
>  [11]  0.000000  0.000000  0.000000  0.000000  0.000000 0.000000
> 0.000000  0.000000  0.000000  0.000000
>
>
> here the code to reproduce this feature :
>
> set.seed(123);
> test1 <- 0.05 +
> arima.sim(model=list(ma=0.5),n=250,innov=rnorm(250,mean=0,sd=0.1))
> set.seed(123);
> test2 <- 0.05 + arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1)
>
> test1-test2
>
> I am using R 3.1.2 GUI 1.65 Mavericks build (6833) on Mac (I guess arima
> come with stats which is included in R (?))
> The DataCamp team ask me to report to you about this observation on this
> mailing list. If you want me to fill a bug report some R bug tracking
> system, let me know
>
> Please tell me if this is the wrong list and which other information do
> you need from R and how to get then (compiler, version of some R packages
> ...)
>
>
> Hope this help
> Thanks
> Cheers
> Fabien
> --
> Dr Fabien Tarrade
>
> Quantitative Analyst - Data Scientist - Researcher
>
> Senior data analyst specialised in the modelling, processing and
> statistical treatment of data.
> PhD in Physics, 10 years of experience as researcher at the forefront of
> international scientific research.
> Fascinated by finance and data modelling.
>
> Geneva, Switzerland
>
> Email : contact at fabien-tarrade.eu <mailto:contact at fabien-tarrade.eu>
> Phone : www.fabien-tarrade.eu <http://www.fabien-tarrade.eu>
> Phone : +33 (0)6 14 78 70 90
>
> LinkedIn <http://ch.linkedin.com/in/fabientarrade/> Twitter <
> https://twitter.com/fabtar> Google <
> https://plus.google.com/+FabienTarradeProfile/posts> Facebook <
> https://www.facebook.com/fabien.tarrade.eu> Google
> <skype:fabtarhiggs?call> Xing <https://www.xing.com/profile/Fabien_Tarrade
> >
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list