Skip to content

Markov chain simulation

4 messages · Armel KAPTUE, Kehl Dániel, Kaptue Tchuente, Armel +1 more

#
Hi, see inline
________________________________________
Felad?: r-help-bounces at r-project.org [r-help-bounces at r-project.org] ; meghatalmazó: Armel KAPTUE [armel.kaptue at sdstate.edu]
K?ldve: 2014. janu?r 28. 8:16
To: R-help at 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


______________________________________________
R-help at 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.
#
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
#
On 28-01-2014, at 19:23, Kaptue Tchuente, Armel <armel.kaptue at sdstate.edu> wrote:

            
I used package sos to search for Markov  (using library(sos); findFn(?Markov?).
Amongst others this what I found which seem to be appropriate:

markovchain
MCMCpack
DTMCPack

and a lot more.
BTW: it?s no use asking me more about Markov. I am ignorant in that subject.

Good luck,

Berend