[R] Please help: Limit single row calculation

Jan Akko Eleveld eleveldjai at hotmail.com
Tue Aug 19 03:36:23 CEST 2008


Is there anyone who can help me with the following? It's hard to describe in a few words, but hope you'll understand.

I attempt to model refugee mortality over time using Monte Carlo. Before doing repetitive simulations, my function should go through only one survey/row at the time, but instead gives outcomes of all studies/rows, which is not correct, because it uses random numbers choosen from a range in study/row 1.

How can I limit y to only go through one row?

y<-0
rand<-runif(n=1,min=0,max=1)
prob<-((cmr-cmrlci)^2)/((cmruci-cmrlci)*(cmr-cmrlci))
if (rand<=prob) y<-sqrt(rand*(cmruci-cmrlci)*(cmr-cmrlci)) + cmrlci
if (rand>prob) y<-cmruci-sqrt((1-rand)*(cmruci-cmrlci)*(cmruci-cmr))

y<-round(y,digits=1)*10

Thank you in advance.

Akko Eleveld



More information about the R-help mailing list