Hi all, I was hoping somebody may know of a function for simulating a large binary sequence (length >10 million) using a (1st order) markov model with known (2x2) transition matrix. It needs to be reasonably fast. I have tried the following;

mc<-function(sq,P){
 s<-c()
 x<-row.names(P)
 n<-length(sq)
 p1<-sum(sq)/n
 s[1] <- rbinom(1,1,p1);
 for ( i in 2:n){
    s[i] <- rbinom( 1, 1, P[s[i-1]+1] )
 }
 return(s)
}


P<-c(0.63,0.27)
x<-rbinom(500,1,0.5)
new<-mc(x,P)

thanks in advance!
Chris

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to