# Independent probability

Oky maybe I found the answer...

I wrote a little simulation, the simulation is written in C++.

I read a publication and they told me that I have a number of ERC in a cell, and every generation 95% are retained in the old cell.

now the first program I wrote:

tot_ERC *= 0.95; //(1)


*Edit: I corrected the program, I forgot to convert a float, so now the graph look like this(which althogh is anyway different than using (2)):

then I have heard that every ERC has an independent probabilty of 95% to be retained:
so I changed the program like this:

int tot_ERC = cell.get_erc_count();
for (int erc = 0; erc < tot_ERC; ++erc){
if (get_random_number_between_0_1() > 0.95 && cell.erc_count > 0){
cell.erc_count -=1;//(2)
}
}


In the indipendent probability method, actually the real probability is different from the input. It can be seen in the second image were the real p6 (blue line, fig 2.) is way above the 0.6 that I gave as a input... I don't know the name of this behaviour but I hope is clear...

-
(1) is calculating the average population while (2) is simulating a concrete sample of how your population behaves. – Listing Nov 26 '11 at 15:53
yes I see... that's why I changed the program... – Pella86 Nov 26 '11 at 15:55
Still not a coherent question. Voting to close. – Ross Millikan Aug 6 '12 at 4:52

I assume for every cell in "tot_ERC" you want to keep it with a probability of 95%. The correct way to do this in a program would be

int temp = 0;
for (int erc = 0; erc < tot_ERC; ++erc){
if (get_random_number_between_0_1() > 0.95) temp = temp + 1;
}
tot_ERC = temp;


Your approach actually has a loop where it is not clear how long it will run, also you run it 1 step too long in any case.

-
yes, I edited with the right version... I saw and corrected the mistake before... And now I copied a old version of the code. thx for the answer anyway – Pella86 Nov 26 '11 at 16:08
Your loop is still running one time too much... – Listing Nov 26 '11 at 16:18
oh oky... yes I'll correct it :D thx – Pella86 Nov 26 '11 at 16:22
but I don't think is this the solution... – Pella86 Nov 26 '11 at 16:48
It is not clear what you want... – Listing Nov 26 '11 at 16:54