wn <- function(seed,n,dist=1) # # Generate a white noise time series of length n having distribution # specified by dist. seed is a nonnegative integer seed for the random # number generator (if seed=0, then the output seed from last call is used). # # dist = 1: normal (0,1) # dist = 2: unif (0,1) # dist = 3: exponential (1) # dist = 4: logistic (mean 0 and var pi^2/3) # dist = 5: Cauchy # dist = 6: Extreme value (log(exp(1)) # dist = 7: lognormal # dist = 8: double exponential # { if(seed!=0) set.seed(seed) if(dist==1) return(rnorm(n)) u <- runif(n) if(dist==2) return(u) if(dist==3) return(-log(1-u)) if(dist==4) return(log(u/(1-u))) if(dist==5) return(tan(pi*(u-.5))) if(dist==6) return(log(-log(1-u))) if(dist==7) return(exp(rnorm(n))) if(dist==8) { xx <- (1:n)[u>.5]; u[xx] <- 1-u[xx]; u <- log(2*u); u[xx] <- -u[xx]; return(u);} }