[R] Non-Markovian Behaviour of a Cusum?

Spencer Graves spencer.graves at pdf.com
Sat Sep 4 18:05:20 CEST 2004


      Can someone help me understand simulations of a one-sided Cusum? 

      Consider the following: 

      Q[i] = max(0, Q[i-1]+z[i]), z[i] ~ N(offset, 1), with Q[0] = FIR 
(fast initial response). 

      With offset < 0, mean{Q[i] for fixed i averaged over many 
simulations} approaches an asymptote as i -> Inf.  In simulations with 
abs(offset) small and FIR close to the asymptote, Q[i] tends initially 
to drop dramatically before starting to climb again to the asymptote.  
Q[i] is not stationary, as I would naively expect. 

      A simple script follows.  I get similar behavior for different 
values of offset in the range (0.01, 0.15);  for larger offsets, Q[i] 
converges to the asymptote so quickly that this behavior can't be seen, 
while for smaller offsets, the convergence is so slow, 500 observations 
is too few to see the behavior.  I've seen this in both S-Plus 6.1 and R 
1.9.1 with apparently independently programmed versions of this with 
different seeds and different random number generators, and I got a hint 
of this behavior in a small sample test in Excel. 

      What am I missing? 
      Thanks,
      spencer graves
##SCRIPT: 
CusumSim <- function(offset=-0.1, FIR=4.5, maxTime=500, nSims=10000){
# Simulate nSims simultaneous Cusums of length maxTime
# Q[i] <- max(0, Q[i-1]+z[i]), z[i] ~ N(offset, 1),
# Q[0] = FIR
# Store only the mean of Q[i] for each i
  Qmean <- rep(NA, maxTime)
  Q <- rep(FIR, nSims)
  for(i in 1:maxTime){
    Q <- pmax(0, Q+rnorm(nSims, mean=offset))
    Qmean[i] <- mean(Q)
  }
  Qmean
}

set.seed(321)
Cus1 <- CusumSim()
plot(Cus1)
# Different simulation, essentially the same behavior
Cus2 <- CusumSim()
plot(Cus1, ylim=range(Cus1, Cus2))
lines(Cus2)

# Different random number generator, same behavior
RNGkind("Wichmann-Hill")
CusWH <- CusumSim()
plot(Cus1, ylim=range(Cus1, Cus2, CusWH))
lines(Cus2)
lines(CusWH, col=2, lty=2, lwd=2)

# Different values for offest, same behavior
Cus.01 <- CusumSim(-.01, FIR=25)
plot(Cus.01)
Cus.15 <- CusumSim(-.15, FIR=3)
plot(Cus.15)
#
-- 

Spencer Graves, PhD, Senior Development Engineer
O:  (408)938-4420;  mobile:  (408)655-4567




More information about the R-help mailing list