9
$\begingroup$

I want to know how to generate uncorrelated white noise sequence $WN(0,\sigma^2)$ in R **without using ** arima.sim(list(order=c(0,0,0)),200) ?

The reason I post this in here instead of stackoverflow is because I feel like this requires understanding the mathematical structure of a white noise such that we can build a program about it. If viewers feel that this question really belong to stackoverflow, please do not downvote this question. Just let me know, then I will migrate it to stackoverflow.

$\endgroup$
3
  • $\begingroup$ just a few seconds quicker... $\endgroup$ May 15, 2015 at 10:24
  • $\begingroup$ @ChristophHanck Yours has the virtue of being an answer (and +1 for it). I couldn't see how to make it one, but you made several good additional points there. $\endgroup$
    – Glen_b
    May 15, 2015 at 10:25
  • $\begingroup$ mynamesJEFF -- I think it should survive on the basis that it requires statistical expertise to answer (just as you suggest) $\endgroup$
    – Glen_b
    May 15, 2015 at 10:27

2 Answers 2

3
$\begingroup$

You will have to specify some distribution, but if you are happy to go with the default choice of a normal distribution (as, in fact, does arima.sim, unless you override the default with some other choice of its rand.gen argument), then rnorm(200) will do the trick: it yields a series of uncorrelated (in fact, even independent) and identically distributed r.v.s.

$\endgroup$
0
$\begingroup$

White noise is simply a sequence of i.i.d random variables. Due to that, you could just use:

rnorm(n, mean = 0, sd = 1)

To give you a little more insight, here's how I would use it to generate a random walk:

set.seed(15) 
x=NULL
x[1]=0
for (i in 2:100) {
   x[i] = x[i-1] + rnorm(1,0,1)
}
ts.plot(x, main = 'Random walk 1(Xt)', xlab = 'Time', ylab = '', col='blue', lwd = 2)
$\endgroup$
1
  • 1
    $\begingroup$ This is the same solution posted over three years ago. If your objective is to show good R code for generating the random walk, then please consider using cumsum: it's built-in, clearer, and more efficient. An example is ts.plot(cumsum(rnorm(100))). $\endgroup$
    – whuber
    Jun 23, 2018 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.