# [R] Counterintuitive Simulation Results

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Fri 05 Aug 2005 - 02:16:06 EST

I wonder if someone can help me understand some counterintuitive simulation results. Below please find 12 lines of R code that theoretically, to the best of my understanding, should produce essentially a flat line with no discernable pattern. Instead, I see an initial dramatic drop followed by a slow rise to an asymptote.

The simulation computes the mean of 20,000 simulated trajectories of 400 observations each of a one-sided Cusum of independent normal increments with mean EZ[t] = (-0.1) and unit variance. Started with any initial value, the mean of the Cusum should approach an asymptote as the number of observations increases; when started at that asymptote, it should theoretically stay flat, unlike what we see here.

I would think this could be an artifact of the simulation methodology, but I've gotten essentially this image with several independently programmed simulations in S-Plus 6.1, with all six different random number generators in R 1.9.1 and 2.1.1 and with MS Excel. For modest changes in EZ[t] < 0, I get a different asymptote but pretty much the same image.

#################################################
simCus5 <- function(mu=-0.1, Qp0=4.5, maxTime=400, nSims=20000){

Qp.mean <- rep(NA, maxTime)
Qp.t <- rep(Qp0, nSims)
for(i in 1:maxTime){

```     z.t <- (mu + rnorm(nSims))
Qp.t <- pmax(0, Qp.t+z.t)
Qp.mean[i] <- mean(Qp.t)
```

}
Qp.mean
}
set.seed(1)
plot(simCus5(Qp0=4.5))
#################################################
```	  Thanks for your time in reading this.
Best Wishes,
Spencer Graves

```

Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves@pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915

R-help@stat.math.ethz.ch mailing list