[R] Counterintuitive Simulation Results
Spencer Graves
spencer.graves at pdf.com
Thu Aug 4 18:16:06 CEST 2005
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 at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list