x <- c(rnorm(50,mean=1),rnorm(50,mean=-1),rnorm(100))
layout(1:2)
plot(x,type="h",ylim=c(-5,5))
## apply the approximated binomial with a single span
mb <- movbin(x,span=25,summarize=NULL)
lines(mb[1,])
## try a few different span ranges
mb <- movbin(x,span=c(10,25,50),summarize=NULL)
lines(mb[1,]) ## span of 10
lines(mb[2,]) ## span of 25
lines(mb[3,]) ## span of 50
## average the results from the different spans
plot(x,type="h",ylim=c(-5,5))
mb <- movbin(x,span=c(10,25,50),summarize=mean)
lines(mb,col="blue")
mb <- movbin(x,span=c(10,25,50),summarize=median)
lines(mb,col="red")
Run the code above in your browser using DataLab