Re: [R] generating markov chain

From: Ingmar Visser <>
Date: Mon 06 Feb 2006 - 20:52:35 EST

You can use the following, with x your transition matrix y=numeric(100)
for(i in 2:100) {
y[i]=which(rmultinom(1, size = 1, prob = x[y[i-1], ])==1) }
hth, ingmar

-----Original Message-----
[]On Behalf Of Norman Goodacre Sent: maandag 6 februari 2006 5:26
Subject: [R] generating markov chain

Dear help group,   

    Just fyi a markov chain is a sequence of transitions between states (say A,T,G,C - on a gene) with a given probability for each transition. In this case there'd be 16 different kinds, each with a different weight.     Given a transition matrix (4x4) filled with all transition probabilities of course, how can I generate a random sequence of a given length, say 200?   

   -Norman Goodacre                    

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Mon Feb 06 21:18:29 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:24 EST