Author 
Message 
David Carson science forum beginner
Joined: 05 Jul 2006
Posts: 4

Posted: Thu Jul 06, 2006 11:58 pm Post subject:
Re: Death rate problem



On Thu, 06 Jul 2006 14:18:38 +0100, nigel <useweb@nospam.com> wrote:
Quote:  I'm not sure that adding extra detail to your death rates will be an
effective use of your time. As you subsequently point out, infant
mortality rates are higher than average, but so are geriatric mortality
rates etc. There are also conditions that cause spikes in death rates
across the whole population, for example flu epidemics or unusual
weather patterns. To model these would be more or less guesswork.
It might be helpful if we understood why you want to model the effects
of different death rates, then we might be able to make more relevant
suggestions for tuning your model.

The purpose of the model is to see what happens when factors such as the
ones you mentioned are introduced or changed. I can add as many different
factors as I want, but it's all for naught if it takes a half a day to run
the simulation. I can handle the model; I just needed some help with the
math, to make it run faster. The Poisson distribution Ray pointed me to
did the trick. 

Back to top 


Nigel science forum beginner
Joined: 03 Jun 2005
Posts: 37

Posted: Thu Jul 06, 2006 1:18 pm Post subject:
Re: Death rate problem



David Carson wrote:
Quote:  Hi, I am not a regular participant of this group, and only stopped in
to ask a question. I hope that's OK.
First, the context: I want to run some simulations to see what effects
different death rates have on a human population. To keep things
simple while I'm developing the code, I'm using a uniform death rate
of 8 per 1,000 per month (which is very high by modern standards, but
not by world historical standards). I'm keeping track of how many
people there are in each age group, and the age groups are broken down
by month. Ultimately, there will be different death rates for
different age groups, genders, etc., but a uniform death rate is
better for purposes of developing and testing the simulation code.
The simplest way to run the simulation would be to multiply the number
of people in each age group by .008, subtract them from the
population, and age the rest by one month. That would also, however,
be very unrealistic. In reality, you would never have exactly 8
deaths per 1,000 in each age group every month. In reality, 8 would
be the modal value, but you'd also get a lot of 7's and 9's, some 6's
and 10's, a few 5's, and 11's, etc. The real distribution would be a
normal probability curve with 8 as the peak.
My working solution uses RND, a random number from the system, where 0
= RND < 1. If, for a given person, RND is greater than or equal to
.992, the poor creature dies, and if it is less than .992, he or she
lives another month. This method gives a nice result where, on
average, the death rate tends to be 8 per 1000, but it varies
according to normal probability. The problem with this method is the
sheer number of RND fetches, comparisons, and iterations that have to
be performed. Aging a population of 20,000 by 12 months by this method
takes a few seconds. To apply it to a population of hundreds of
millions over 100 years would take hours, or even days.
Can anyone think of a way to run this simulation so that death rates
will result in a normal probability curve, but without iterating over
the entire population personbyperson every month? I will check back
here to see if there are any answers, and thanks in advance.
David Carson

I'm not sure that adding extra detail to your death rates will be an
effective use of your time. As you subsequently point out, infant
mortality rates are higher than average, but so are geriatric mortality
rates etc. There are also conditions that cause spikes in death rates
across the whole population, for example flu epidemics or unusual
weather patterns. To model these would be more or less guesswork.
It might be helpful if we understood why you want to model the effects
of different death rates, then we might be able to make more relevant
suggestions for tuning your model. 

Back to top 


Ray Koopman science forum Guru Wannabe
Joined: 25 Mar 2005
Posts: 216

Posted: Thu Jul 06, 2006 6:49 am Post subject:
Re: Death rate problem



David Carson wrote:
Quote:  On 5 Jul 2006 15:43:18 0700, "Ray Koopman" <koopman@sfu.ca> wrote:
A long as n (the number of people in the group) is large  say > 100
 and p (the proportion who are expected to die) is small  say
.10  take your numbers from a Poisson distribution with mean = m =
n*p. Otherwise revert to your original method.
Here is some pseudocode for generating a Poisson variable with mean m:
u = rnd()*exp(m); x = 0; t = 1; s = 1;
while s < u: (x = x+1, t = t*m/x, s = s+t);
use x
Interesting. I found some code for a BoxMuller transformation today, but
I like this better, because it gives me a result I can use without any
further manipulation.
By iterating over each member of the population every month, it took 65
seconds on my PC to age a population of 100,000 by 10 years. Using this
Poisson distribution, the same calculation was instantaneous, and aging a
population of 100,000 by 100 years took under 2 seconds. This will work
fine.
One question  at what proportion of deaths in the population group does
this method start to break down? I can see, in some high infant mortality
scenarios, needing to apply a death rate of, say, 8 out of 80. Will that
be a problem? I can revert to the iterative method if necessary, but it
would help to know if and when I have to make the switch, and of course it
would be preferable to have only one method to worry about.
Thanks for your help, Ray.
David Carson

The Poisson variable is serving as an approximation to a Binomial
variable, which is what your original loop over n gives. There is no
precise general rule that says when the approximation is good enough.
The following recommendation is from
http://www.itl.nist.gov/div898/handbook/pmc/section3/pmc331.htm :
"The sample size n should be equal to or larger than 20 and the
probability of a single success, p, should be smaller than or equal to
..05. If n >= 100, the approximation is excellent if np is also <= 10." 

Back to top 


David Carson science forum beginner
Joined: 05 Jul 2006
Posts: 4

Posted: Thu Jul 06, 2006 3:53 am Post subject:
Re: Death rate problem



On 5 Jul 2006 15:43:18 0700, "Ray Koopman" <koopman@sfu.ca> wrote:
Quote:  A long as n (the number of people in the group) is large  say > 100
 and p (the proportion who are expected to die) is small  say
.10  take your numbers from a Poisson distribution with mean = m =
n*p. Otherwise revert to your original method.
Here is some pseudocode for generating a Poisson variable with mean m:
u = rnd()*exp(m); x = 0; t = 1; s = 1;
while s < u: (x = x+1, t = t*m/x, s = s+t);
use x

Interesting. I found some code for a BoxMuller transformation today, but
I like this better, because it gives me a result I can use without any
further manipulation.
By iterating over each member of the population every month, it took 65
seconds on my PC to age a population of 100,000 by 10 years. Using this
Poisson distribution, the same calculation was instantaneous, and aging a
population of 100,000 by 100 years took under 2 seconds. This will work
fine.
One question  at what proportion of deaths in the population group does
this method start to break down? I can see, in some high infant mortality
scenarios, needing to apply a death rate of, say, 8 out of 80. Will that
be a problem? I can revert to the iterative method if necessary, but it
would help to know if and when I have to make the switch, and of course it
would be preferable to have only one method to worry about.
Thanks for your help, Ray.
David Carson 

Back to top 


Ray Koopman science forum Guru Wannabe
Joined: 25 Mar 2005
Posts: 216

Posted: Wed Jul 05, 2006 10:43 pm Post subject:
Re: Death rate problem



A long as n (the number of people in the group) is large  say > 100
 and p (the proportion who are expected to die) is small  say <
..10  take your numbers from a Poisson distribution with mean = m =
n*p. Otherwise revert to your original method.
Here is some pseudocode for generating a Poisson variable with mean m:
u = rnd()*exp(m); x = 0; t = 1; s = 1;
while s < u: (x = x+1, t = t*m/x, s = s+t);
use x
David Carson wrote:
Quote:  On 5 Jul 2006 13:26:01 0700, "Ray Koopman" <koopman@sfu.ca> wrote:
There are several ways to do what you want. From what distributions
other than Uniform(0,1) will your system generate random numbers?
None ... that's the only one. I'm just using a PC and VBScript.
If there were a way to fetch a number randomly generated from a normal
distribution, all I would have to do is fetch a value for each age
group. I guess another way of phrasing my question would be, is there
a way to randomly generate numbers from a normal distribution, when
your system only generates random numbers from a uniform distribution
and only has the basic arithmetic, logarithmic, and trigonometric
functions built in?
David Carson 


Back to top 


David Carson science forum beginner
Joined: 05 Jul 2006
Posts: 4

Posted: Wed Jul 05, 2006 9:52 pm Post subject:
Re: Death rate problem



On 5 Jul 2006 13:26:01 0700, "Ray Koopman" <koopman@sfu.ca> wrote:
Quote:  There are several ways to do what you want. From what distributions
other than Uniform(0,1) will your system generate random numbers?

None ... that's the only one. I'm just using a PC and VBScript.
If there were a way to fetch a number randomly generated from a normal
distribution, all I would have to do is fetch a value for each age
group. I guess another way of phrasing my question would be, is there
a way to randomly generate numbers from a normal distribution, when
your system only generates random numbers from a uniform distribution
and only has the basic arithmetic, logarithmic, and trigonometric
functions built in?
David Carson 

Back to top 


Ray Koopman science forum Guru Wannabe
Joined: 25 Mar 2005
Posts: 216

Posted: Wed Jul 05, 2006 8:26 pm Post subject:
Re: Death rate problem



There are several ways to do what you want. From what distributions
other than Uniform(0,1) will your system generate random numbers?
David Carson wrote:
Quote:  Hi, I am not a regular participant of this group, and only stopped in
to ask a question. I hope that's OK.
First, the context: I want to run some simulations to see what effects
different death rates have on a human population. To keep things
simple while I'm developing the code, I'm using a uniform death rate
of 8 per 1,000 per month (which is very high by modern standards, but
not by world historical standards). I'm keeping track of how many
people there are in each age group, and the age groups are broken down
by month. Ultimately, there will be different death rates for
different age groups, genders, etc., but a uniform death rate is
better for purposes of developing and testing the simulation code.
The simplest way to run the simulation would be to multiply the number
of people in each age group by .008, subtract them from the
population, and age the rest by one month. That would also, however,
be very unrealistic. In reality, you would never have exactly 8
deaths per 1,000 in each age group every month. In reality, 8 would
be the modal value, but you'd also get a lot of 7's and 9's, some 6's
and 10's, a few 5's, and 11's, etc. The real distribution would be a
normal probability curve with 8 as the peak.
My working solution uses RND, a random number from the system, where 0
= RND < 1. If, for a given person, RND is greater than or equal to
.992, the poor creature dies, and if it is less than .992, he or she
lives another month. This method gives a nice result where, on
average, the death rate tends to be 8 per 1000, but it varies
according to normal probability. The problem with this method is the
sheer number of RND fetches, comparisons, and iterations that have to
be performed. Aging a population of 20,000 by 12 months by this method
takes a few seconds. To apply it to a population of hundreds of
millions over 100 years would take hours, or even days.
Can anyone think of a way to run this simulation so that death rates
will result in a normal probability curve, but without iterating over
the entire population personbyperson every month? I will check back
here to see if there are any answers, and thanks in advance.
David Carson 


Back to top 


David Carson science forum beginner
Joined: 05 Jul 2006
Posts: 4

Posted: Wed Jul 05, 2006 6:06 pm Post subject:
Death rate problem



Hi, I am not a regular participant of this group, and only stopped in
to ask a question. I hope that's OK.
First, the context: I want to run some simulations to see what effects
different death rates have on a human population. To keep things
simple while I'm developing the code, I'm using a uniform death rate
of 8 per 1,000 per month (which is very high by modern standards, but
not by world historical standards). I'm keeping track of how many
people there are in each age group, and the age groups are broken down
by month. Ultimately, there will be different death rates for
different age groups, genders, etc., but a uniform death rate is
better for purposes of developing and testing the simulation code.
The simplest way to run the simulation would be to multiply the number
of people in each age group by .008, subtract them from the
population, and age the rest by one month. That would also, however,
be very unrealistic. In reality, you would never have exactly 8
deaths per 1,000 in each age group every month. In reality, 8 would
be the modal value, but you'd also get a lot of 7's and 9's, some 6's
and 10's, a few 5's, and 11's, etc. The real distribution would be a
normal probability curve with 8 as the peak.
My working solution uses RND, a random number from the system, where 0
<= RND < 1. If, for a given person, RND is greater than or equal to
..992, the poor creature dies, and if it is less than .992, he or she
lives another month. This method gives a nice result where, on
average, the death rate tends to be 8 per 1000, but it varies
according to normal probability. The problem with this method is the
sheer number of RND fetches, comparisons, and iterations that have to
be performed. Aging a population of 20,000 by 12 months by this method
takes a few seconds. To apply it to a population of hundreds of
millions over 100 years would take hours, or even days.
Can anyone think of a way to run this simulation so that death rates
will result in a normal probability curve, but without iterating over
the entire population personbyperson every month? I will check back
here to see if there are any answers, and thanks in advance.
David Carson 

Back to top 


Google


Back to top 



The time now is Sat Jun 23, 2018 2:17 am  All times are GMT

