From: Ingmar Visser <I.Visser_at_uva.nl>

Date: Fri 24 Nov 2006 - 09:46:06 GMT

R-help@stat.math.ethz.ch 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. Received on Fri Nov 24 20:52:41 2006

Date: Fri 24 Nov 2006 - 09:46:06 GMT

Dear Rohan,

Why would you want to simulate these probabilities? As far as I can tell by
your description these are all solvable analytically, see eg Kemeney,
Mirkil, Snell & Thompson, 1958, Finite Mathematical Structures. There are
undoubtedly more recent publications that cover first passage times in
Markov models, which is what you are looking for.
Hth, Ingmar

*> From: Rohan Saldanha <rohansaldanh@hotmail.com>
**> Date: Thu, 23 Nov 2006 19:07:54 +0000
*

> To: <r-help@stat.math.ethz.ch>

*> Subject: [R] statistics help
**>
**> hi
**>
**> im a bioinformatics student as i have never had any previous programming
**> experience
**> i need help
**>
**> this is the question i need to answer:
**>
**> Random walk model
**>
**> we want to model a random walk where you take a step to the left with
**> probability p
**> and one to the right with probability 1-p. Now assume that there is a line
**> of 11 squares.
**> once you are in square 0 or in square 10 the walk ends. The aim of this
**> problem set is
**> to write a simulation for the random walk and analyse its dynamics
**>
**> 1. write a simulation for a random walk which allows you to calculate the
**> probability of ending
**> up in square 0 starting from any other square.
**>
**> 2. analyse the probability of ending up in square 0 starting from any other
**> square. Also calculate the mean time until you have reached square 1 for p=
**> 0.1,0.2,0.3,0.4 and 0.5. What is the probability of reaching square 10 for
**> these parameters
**> hint simulate each scenario 1000 times and plot on histogram
**>
**>
**> this is the code that i have come up with but its not working very well.
**>
**> rw<-function(sw,p,nrep){
**> Z=0
**> T=0
**> count=0
**> for (i in 1:nrep)
**> {
**> n<-0
**> s=sw
**>
**> while (s>0 & s<10)
**> {
**> x<-runif(1, min=0, max=1)
**> if (x<p) {s<-s-1}
**> else{s<-s+1}
**> print (s)
**> n<-n+1
**> }
**> count<-count+n
**> print (count)
**>
**> if (s==0) {Z<-Z+1}
**> else {T<-T+1}
**> }
**> PrZ=Z/nrep
**> print(c("PrZ",PrZ),quote=FALSE)
**> }
**>
**> if you could shed some light on this it woul be really helpful. please let
**> me know how much
**> you would like as payment aswell.
**>
**> thanks
**> rohan
**>
**> _________________________________________________________________
**> Eat well and eat right. Get tips on nutrition from Naini Setalvad
**>
**> ______________________________________________
**> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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. Received on Fri Nov 24 20:52:41 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Fri 24 Nov 2006 - 10:30:19 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*