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]]

______________________________________________
R-help@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.

Reply via email to