Math 1180 - Mathematics for Life Scientists

advertisement
Math 1180 - Mathematics for Life Scientists
Lab 3 - Stochastic Dynamical Models
Due the week of February 19, 2007
Getting Started
Log in to your computer, and create a new directory for lab 3 by typing mkdir lab3. Open Maple and
type restart; to start fresh. Maple has several features for studying stochastic dynamical system. To
use these tools, rst load up the Maple (stats) library by typing
> with(stats):
In addition, you will need to download the .mapleinit le from the course webpage: www.math.utah.edu/
Save the le in your home directory (NOT in the lab3 directory!) and make sure that the le is not
saved with any extension (.txt, .html, and so on). This le is needed to study discrete dynamical
systems. After saving the le, load up the library by typing
> iread(iter):
Random Number Generators
Maple has various random number generators. For example, you can simulate rolling a die by telling
Maple to pick a random integer between 1 and 6,
> die:= rand(1..6):
> die();
By typing die(), you print out the actual number. (Maple note: typing a colon : instead of a semicolon
; simply suppresses the output. Since the output of the rst command doesn't tell you anything, we
suppress it.)
To get Maple to pick a random number betwen 0 and 1, use the commands,
> number := x -> stats[random,uniform[0,1]](1):
> number();
The rst command tells Maple to generate one ((1) at the end) random number from the uniform
distribution in [0,1]. The second command prints out the actual number for you.
Bernoulli Trials
Suppose you are ipping a coin where the probability of coming up heads is p and coming up tails is
1 p. Denote the outcome by c: when c = 1 then the coin comes up heads and when c = 0, it comes
up tails. Say the probability of getting heads is p = 0:3. You can simulate ipping this coin in Maple
by typing
davis/11
> iread(draw);
> bern(0.3);
bern(p) is a function of p that gives a result 1 with probability p and a result 0 with probability
1 p. Above, we use bern(0.3). Repeat the command 10 times. How many times do you get heads?
How many times do you get tails? Is the fraction of times (out of 10) that you got heads close to the
probability 0:3?
Now, try to simulate ipping a coin with equal likelihood of coming up head or tail. What should you
type?
Diusion of a Molecule
Consider a molecule that leaves a cell each minute with probability 0.25. Once the molecule leaves the
cell, it cannot reenter. Let M = 1 when the molecule is inside at time t and M = 0 when the molecule
is outside. In Maple terms,this means that you are considering the following discrete dynamical system:
t
t
M +1 = bern(0:75)M
t
t
where the function bern is as discussed above for coin ipping simulation. That is, Maple will output
either 0 (the case where the molecule is outside the cell) or 1 (inside). Dene the following function in
Maple that will update the state M , the location of the molecule:
> F:= M -> bern(0.75)*M;
Start your simulation by assuming that the molecule is inside the cell initially M0 = 1. Now, track the
movement of the molecule in the next ten minutes by typing
> iterplot(F,10,1);
The rst input of iterplot is the name of the update function of your system (F), the second input
is the time to end the simulation (10 minutes), and the third is the initial condition (M0 = 1). Maple
returns a plot. Explain what this plot means and write the label for each axis.
Simulate the movement of the ten individual molecules by using iterplot 10 times. Count up how
many times the molecule is still inside the cell after 5 minutes.
A similar discrete dynamical system describing the probability m that the molecule is inside the cell
at time t is
m +1 = 0:8m
Here, Maple outputs the probability that the molecule is still inside the cell at the given iteration. In
Maple, m has the following update function,
t
t
t
t
> f:= m -> 0.8*m;
Use iterplot again to plot m from t = 0 to t = 10. As before, assume m0 = 1. Estimate the value of
m at t = 5 from your plot. This corresponds to the probability that the molecule is inside the cell after
5 minutes. If there were instead 10 molecules, how many would still be inside the cell after 5 minutes?
Compare this result (for one molecule) to your previous simulations. Is your simulation result close to
the theoretical/probability result? What can you do to make the results closer?
t
t
Screening for Rare Disease
We can use Maple to simulate the rare disease example we discussed in class. Suppose a rare disease
is aecting a population of size N and the disease only infects 1% of the population. Pick some large
number of people, say N = 1000, by typing
> N:=1000;
To pick the sick people, type the following command,
> sick := seq(bern(0.01),i=1..N):
> nsick := sum(sick[i],i=1..N);
You have just gone through the entire population and assign several unlucky individuals with the
disease! The commands above make each person sick, independently, with probability 0.01, then add
up the number of sick people. How many people is sick in your simulation?
Now, get a health ocial to screen your entire population for the disease. Assume that the diagnostic
test always picks up the disease. However, it will also generate false positives and 5% of the population
will test positive. Use similar commands to the one you just use to assign infected individuals.
How many people tested positive in your simulation? What is the fraction of sick individuals among
those who tested positive? How close is this to the mathematical result of 16:8% that we obtained in
class?
Download