Hi all, in order to verify some results I did the following test in R (2.4.1., windows system): X <- cumsum(rnorm(1000000)) for (i in 1:1000) { tmp <- seq(1,length(X),by=i) X.coarse <- X[tmp] X.return <- diff(X.coarse) X.scale.mean[i] <- mean(X.return) } plot(X.scale.mean,type="l") As X is a random walk with increments following a standard normal distribution, the mean of X should be 0. Further more, each "piece" of the random walk should also have zero mean - independent of its length. Why is it then, that the plot of X.scale.mean shows a clear linear trend? Is the generation of the random walk in some way biased or do I just miss some point? Thanks for any enlighting replies in advance Oliver
On 3/26/2007 2:48 PM, Oliver Faulhaber wrote:> Hi all, > > in order to verify some results I did the following test in R (2.4.1., > windows system): > > X <- cumsum(rnorm(1000000)) > for (i in 1:1000) { > tmp <- seq(1,length(X),by=i) > X.coarse <- X[tmp] > X.return <- diff(X.coarse) > X.scale.mean[i] <- mean(X.return) > } > plot(X.scale.mean,type="l") > > As X is a random walk with increments following a standard normal > distribution, the mean of X should be 0. Further more, each "piece" of > the random walk should also have zero mean - independent of its length. > > Why is it then, that the plot of X.scale.mean shows a clear linear trend?The points in your plot are all based on a single realization of a Brownian motion. What you are seeing is just that X[1000000] is non-zero. If you repeat the simulation you'll get a different linear trend.> Is the generation of the random walk in some way biased or do I just > miss some point?If it is biased, your plots don't show it. Try this plot instead (and wait a lot longer; it does a lot of memory allocations!): X.scale.mean <- numeric(1000) for (i in 1:1000) { X <- cumsum(rnorm(1000000)) tmp <- seq(1,length(X),by=i) X.coarse <- X[tmp] X.return <- diff(X.coarse) X.scale.mean[i] <- mean(X.return) } plot(X.scale.mean,type="l") Duncan Murdoch> > Thanks for any enlighting > replies in advance > Oliver > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > 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.
[Sorry, I need to correct a vital typo!!] On 26-Mar-07 18:48:50, Oliver Faulhaber wrote:> Hi all, > > in order to verify some results I did the following test in R (2.4.1., > windows system): > > X <- cumsum(rnorm(1000000)) > for (i in 1:1000) { > tmp <- seq(1,length(X),by=i) > X.coarse <- X[tmp] > X.return <- diff(X.coarse) > X.scale.mean[i] <- mean(X.return) > } > plot(X.scale.mean,type="l") > > As X is a random walk with increments following a standard normal > distribution, the mean of X should be 0. Further more, each "piece" of > the random walk should also have zero mean - independent of its length. > > Why is it then, that the plot of X.scale.mean shows a clear linear > trend? > > Is the generation of the random walk in some way biased or do I just > miss some point? > > Thanks for any enlighting replies in advance > OliverTry plot(X,type="l") and you will see why you get that result from plot(X.scale.mean). But that does not help to understand why plot(X) looks as it does. However, this behaviour is standard for a random walk. [XXXIf you think about it, var(X[n]) = 1 (in your case), so atXXX] If you think about it, var(X[n]( = n (in your case), so at the nth step you are (for instance) likely (P>1/2)to be at least 0.5*sqrt(n) on one side or other of the mean. So say n=10000: then you are likely to be at least 50 away from the mean; and you have to get there somehow, starting from 0. So there will be an overall trend! Similarly, for n=1000000, you are likely to be at least 500 from the mean. The same explanation accounts for the shorter segments of trend you will also observe over the graph of X, since from any point along the graph the above holds true on a smaller scale. Hoping that helps! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 26-Mar-07 Time: 20:27:57 ------------------------------ XFMail ------------------------------ -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 26-Mar-07 Time: 20:32:42 ------------------------------ XFMail ------------------------------
Oliver Faulhaber wrote:> Hi all, > > in order to verify some results I did the following test in R (2.4.1., > windows system): > > X <- cumsum(rnorm(1000000)) > for (i in 1:1000) { > tmp <- seq(1,length(X),by=i) > X.coarse <- X[tmp] > X.return <- diff(X.coarse) > X.scale.mean[i] <- mean(X.return) > } > plot(X.scale.mean,type="l") > > As X is a random walk with increments following a standard normal > distribution, the mean of X should be 0. Further more, each "piece" of > the random walk should also have zero mean - independent of its length. > > Why is it then, that the plot of X.scale.mean shows a clear linear trend? > > Is the generation of the random walk in some way biased or do I just > miss some point? > >The latter. If you think a little closer, you'll realize that sum(X.return) is going to be pretty close to X[1000000], except for the sum of at most 999 terms (at most 961, actually). You then proceed to calculate the mean by dividing by the number of terms which is essentially 1/i.> Thanks for any enlighting > replies in advance > Oliver > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > 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. >