[R] Probabilities in discrete event simulation model in R

Shah Alam dr@@|@m@o|@ng| @end|ng |rom gm@||@com
Thu Jul 16 19:14:15 CEST 2020


I am designing a programme in R to simulate two events that are 1. a person
gets cancer, or 2. die of other causes. I have data for the probability of
getting cancer by age and probability of death due to causes other than
cancer.

   1.

   My dataset has 3 columns 1) age 2) prob getting cancer 3) prob dying
   other causes. I generate random number using runif(1, min = 0, max = 1).
   2.

   This random number compares with all the values in the second column
   (prob getting cancer) and give the age which has the same value of
   probability as this random number. Then it compares with all the values in
   the 3rd column and gives the age at which women die because of causes other
   than cancer.

The problem is:

   1.

   I want an R code in which the random number compares in both the columns
   simultaneously (prob of getting cancer, and prob of death) step by step.
   for example, if the random number is 0.2, first the code checks the
   observation 1 in the column of getting cancer if it fails to get the same
   values. Then it checks the observation 1 in the column of death due to
   other causes. If it fails then move to 2nd observation of prob getting
   cancer............ The process should go on until it finds the age which
   has the same value of probability as this random number. Kindly help me on
   how to do this in R.

	[[alternative HTML version deleted]]



More information about the R-help mailing list