[R] Simulation problem.
Greg Snow
Greg.Snow at imail.org
Wed Apr 14 18:55:04 CEST 2010
This looks like homework. If it is, you should really tell us along with what your teacher's policy is on getting help over the internet is (and note that many teachers monitor this list and can see if you are getting help).
You have done the first part yourself, much better than some who have tried to get us to do the whole thing for them, so a possible hint: the new problem really has 3 groups, never sick, currently sick, and healed. Just modify your current code to allow for people to move from the currently sick to the healed group.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Piotr Arendarski
> Sent: Tuesday, April 13, 2010 4:27 PM
> To: r-help at r-project.org
> Subject: [R] Simulation problem.
>
> Hi,
> I have problem with simulating.
> This is my task...
>
> Suppose that there are N persons some of whom are sick with influenza.
> The
> following assumptions are made:
> * when a sick person meets a healthy one, the chance is á that the
> latter
> will be infected
> * all encounters are between two persons
>
> Write a function which simulates this model for various values of
> N (say, 10 000) and á (say, between 0.001 and 0.1). Monitor the
> history of this process, assuming that one individual is infected at
> the beginning.
>
> The code is:
> *
> simulation <- function(number, prob){
> cumulative.time <- 0
> current.time <- 0
> number.sick <- 1
> while(number.sick<number){
> current.time <- current.time + 1
>
> meetings <- rhyper(nn=1, m=number.sick, n=number-number.sick, k=2)
>
> if(meetings==1){
> one.sick <- rbinom(n=1, size=1, prob)
> if(one.sick==1){
> cumulative.time <- c(cumulative.time, current.time)
> number.sick <- number.sick + 1
> }}}
> cumulative.time
> }
>
> number <- 1000
> prob <- .05
> model <- simulate(number, prob)*
>
> But than add the assumption that *each infected person has a 0.01
> chance
> of recovering at each time unit*.... Do you have idea how to modify the
> code
> ?
>
> Piotr Arendarski
>
> [[alternative HTML version deleted]]
More information about the R-help
mailing list