steve_bank
Diabetic retinopathy and poor eyesight. Typos ...
This comes under the heading of stochastic systems.
When building statistical models of systems I simulated it. It is a good way to test what you are thinking. If you want to explore something like Bayes s' Theorem run a simulation.
This technique is called Monet Carlo simulation. It is simple and can make complicated problems a lot easier.
The problem:
You enter a room with three doors numbered 1,2,3. There is a box with balls labeled 1,2,3. You flip a coin. If tails you walk out. If heads you randomly pick a ball and go through the door with the number. What percentage of the times you enter the room do you go through one of the doors?
Create random vectors for each of the statistical variables and evaluate point by point.
A simulation – solution in Scilab script. A simple example that illustrates the method.
ht a random vector of 1s for heads and 0s for tails
d a random vector of numbers 1,2,3 for each of the three doors
y the point by point state of the simulation
For each value in ht if ht is 0 for trails enter 0 in the y array.
If heads put the next random door value into the y array.
Sum the tails and door counts, and calculate the percentages.
It does not have to be equal probability for all three doors. The door vector can be adjusted for different percentages
On one pass with 1e6 samples.
percent tails 50.0430, theoretic 50%
percent door 1 16.5940, theoretical 16.6666....
percent door 2 16.7020
percent door 3 16.6610
I will see if I can work up a Bayesian Theorem simulation.
When building statistical models of systems I simulated it. It is a good way to test what you are thinking. If you want to explore something like Bayes s' Theorem run a simulation.
This technique is called Monet Carlo simulation. It is simple and can make complicated problems a lot easier.
The problem:
You enter a room with three doors numbered 1,2,3. There is a box with balls labeled 1,2,3. You flip a coin. If tails you walk out. If heads you randomly pick a ball and go through the door with the number. What percentage of the times you enter the room do you go through one of the doors?
Create random vectors for each of the statistical variables and evaluate point by point.
A simulation – solution in Scilab script. A simple example that illustrates the method.
ht a random vector of 1s for heads and 0s for tails
d a random vector of numbers 1,2,3 for each of the three doors
y the point by point state of the simulation
For each value in ht if ht is 0 for trails enter 0 in the y array.
If heads put the next random door value into the y array.
Sum the tails and door counts, and calculate the percentages.
It does not have to be equal probability for all three doors. The door vector can be adjusted for different percentages
On one pass with 1e6 samples.
percent tails 50.0430, theoretic 50%
percent door 1 16.5940, theoretical 16.6666....
percent door 2 16.7020
percent door 3 16.6610
I will see if I can work up a Bayesian Theorem simulation.
Code:
clear
clc
rows = 100000
colum = 1
ht = grand(rows, colum, "uin", 0, 1) //heads tails random vector
d = grand(rows, colum, "uin", 1, 3) //door probabilities random vector
tails = 0
d1 = 0
d2 = 0
d3 = 0
k = 1
for i = 1:m
if ht(i) == 0 then y(i) = 0;end; // tails
if ht(i) == 1 then y(i) = d(k); k = k + 1;end; // heads
end
for i = 1:m
if y(i) == 0 then tails = tails +1;end;
if y(i) == 1 then d1 = d1 +1;end;
if y(i) == 2 then d2 = d2 +1;end;
if y(i) == 3 then d3 = d3 +1;end;
end
s = d1+d2+d3
pct = 100*tails/m
pc1 = 100*d1/m
pc2 = 100*d2/m
pc3 =100* d3/m
mprintf(" pc tails %2.4f pc d1 %2.4f pc d2 %2.4f pc d3 %2.4f\n",pct,pc1,pc2,pc3)
mprintf("m %d tails %d d1 %d d2 %d d3 %d s %d\n",m,tails,d1,d2,d3,s)