# How to generate uncorrelated white noise sequence in R without using arima.sim?

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.

• just a few seconds quicker... – Christoph Hanck May 15 '15 at 10:24
• @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. – Glen_b May 15 '15 at 10:25
• mynamesJEFF -- I think it should survive on the basis that it requires statistical expertise to answer (just as you suggest) – Glen_b May 15 '15 at 10:27

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.

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)

• 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))). – whuber Jun 23 '18 at 22:57