SHARE
TWEET

Data Generating Process

mjaniec Aug 16th, 2012 212 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # see more: http://reakkt.cm
  2.  
  3. n <- 1000
  4.  
  5. mean.eq <- 0.001
  6. sd.eq   <- 0.02
  7.  
  8. contamination.ratio <- 0.01
  9.  
  10. contaminated.sd <- 6
  11.  
  12. cf1 <- 1
  13. cf2 <- 0.8
  14.  
  15. ###
  16.  
  17. x <- numeric(n)
  18.  
  19. contaminatedN <- round(n*contamination.ratio)
  20.  
  21. contaminated.idx <- sample(1:n,contaminatedN,replace=FALSE)
  22.  
  23. x[contaminated.idx] <- rnorm(contaminatedN,mean.eq,contaminated.sd)/100
  24.  
  25.  
  26. sd.d <- numeric(n)
  27.  
  28. for (i in 1:n) {
  29.  
  30.   if (is.na(match(i,contaminated.idx))) {
  31.    
  32.     sd.d[i] <- sum( (cf1/abs(i-contaminated.idx)^cf2) * abs(x[contaminated.idx]) )
  33.    
  34.     x[i]    <- rnorm( 1,0,sd.eq + ifelse(sd.d[i]>sd.eq,sd.d[i],0) )
  35.  
  36.   } else sd.d[i] <- sd.d[i-1]
  37.  
  38. }
  39.  
  40. par(mfrow=c(3,1))
  41. plot(cumsum(x),type="l")
  42. plot(x,type="l")
  43. plot(sd.d,type="l")
  44. abline(h=sd.eq,col="Red",lty="dotted")
  45. par(mfrow=c(1,1))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top