Hi Kehl, Thank you for your reply.
Indeed, there are many ways to simulate a markov chain sequence. For instance, if I assume that n=20, rnd_occ1<-c(0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1) and rnd_occ2<-c(0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0) are two markov chain sequences having the transition matrix TransitionMatrix<- matrix(c(0.7, 0.3, 0.4, 0.6),byrow=TRUE, nrow=2) For the first sequence the state "1" has 9 occurences while for the second sequence, the state "1" has 6 occurences. What I'm looking for it is an algorithm or a library to simulate efficiently such a markov chain sequence with for instance 12 ooccurences of the state '1' Thanks Armel ________________________________________ From: Kehl Dániel [ke...@ktk.pte.hu] Sent: Tuesday, January 28, 2014 8:00 AM To: Kaptue Tchuente, Armel; R-help@r-project.org Subject: RE: [R] Markov chain simulation Hi, see inline ________________________________________ Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; meghatalmazó: Armel KAPTUE [armel.kap...@sdstate.edu] Küldve: 2014. január 28. 8:16 To: R-help@r-project.org Tárgy: [R] Markov chain simulation Hi there, I'm wonder if in R there is a way to simulate a discrete Markov chains with a specific number of occurence of state knowing the transition matrixway. Indeed there are many ways to do that in R! For example, how to simualte a markov chain of length n with p occurences (p<n) of the sate '0' for a transition matrix defined by: I am not sure what you mean here?! If you give the length of the chain, depending on the transition matrix you are going to get some occurences of state '0', I do not think you can specify n, p and the transition matrix all at once! TransitionMatrix<- matrix(c(0.7, 0.3, 0.4, 0.6),byrow=TRUE, nrow=2) colnames(TransitionMatrix) <- c('0','1') row.names(TransitionMatrix) <- c('0','1') Please try googling first, there are a lot of good examples on your problem, among the first ones: http://stackoverflow.com/questions/2754469/r-library-for-discrete-markov-chain-simulation Best daniel Thanks, -- Armel [[alternative HTML version deleted]] ______________________________________________ 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. ______________________________________________ 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.