Poisson
Distribution
Using
the Poisson
distribution, this program calculates the probability
of an event occurring a given number of times. You must know
the
expected frequency of the event.
No special instruction or statistical toolboxes are
used, so you can adapt the code to any other programming language...
This is the code in Matlab:
%
Clears screen and deletes all the variables in the workspace
clc;
clear;
%
Asks the user for input
f =
input('Calculated
Frequency: ');
x =
input('Test
Frequency: ');
%
Computes probability
a =
log(factorial(x));
a =
exp(f + x*log(f)  a);
%
Displays result
str = ['Probability
of ' num2str(x) ' occurrences = ' num2str(a)];
disp(str)
The
instruction 'num2str'
(numbertostring) transforms a number
into a string, to be used along with the rest of the
output message, launched by instruction 'disp'.
Example
1:
Some
programs are downloaded into 2000 computers. The probability of any one
computer getting infected by a virus is 0.001 (nothing to do with
reality, ok?) Thus we can expect 2 computers will suffer a bad reaction
(0.001 x 2000 = 2). What is the probability that 4 computers will get
infected?
We launch
our code above and enter known data as input:
Calculated Frequency: 2
Test Frequency: 4
Matlab
answer is
Probability of 4 occurrences
= 0.090224
Example 2:
What is
the probability that only one computer will get infected?
We
relaunch our code and enter data:
Calculated Frequency: 2
Test
Frequency: 1
Matlab answer is
Probability
of 1 occurrences = 0.27067
Reference:
Poole, L.; Borchers, M.; Some Common Basic Programs;
Osborne/McGrawHill;
3rd. edition; Berkeley, CA; 1979.
From
'Poisson Distribution' to home
From
'Poisson Distribution' to 'Probability and Statistics'
