Flies in Houses

Another twitter science question. Morena Baccarin (@missmorenab) recently posted:

Flies always find a way INTO your house but never OUT. Ugh! (source)

to which Patrick McAvoy (aka @stamponbunnies) said:

That's because like Mac users, flies don't understand Windows. (source)

Let's put aside the funny for a moment. There is an element of truth here, I'd thought I'd simulate it.

Let's imagine a situation with 100 flies immediately outside the house, randomly hitting windows/doors etc, and no flies inside. Let's say that in each time interval, there is a 3% chance a fly will go from being an outside fly to an inside fly (or vice versa). As all the flies are outside and none inside, this means that a fly is more likely to fly in than out. As the number of flies inside grows, some start to leave. The number of flies stabilise when the number leaving is the same as the number arriving.

In the simple simulation, stability occurs when 50 flies are inside, and 50 outside - i.e. when the number of flies matches inside and out.

This simulation really refers to 'fly density' rather than number - and I've assumed a fly is just as likely to enter as to leave. In practice, flies may be more likely to fly toward light, or toward food etc, so this'd make the stable position different. Swatting will upset the balance for a while, but those flies will be replaced unless you shut the window.

In short, it matters not what the chance of a fly coming through your window is exactly, the number will stabilise - even if you swat them. If there are none inside, some will come in. If there are some inside, they will leave, but others arrive. It's not necessary to assume that the flies came in deliberately and can't leave, only that they are randomly moving. Of course, none of this proves that the flies aren't doing it on purpose....

Note, random fluctuations will happen - but it stabilises (in this simulation) at 50/50. Changing the probability affects how long it takes to stabilise (about 40-50 time periods for 3%), but not the values at which it stabilises.

The only probability which gives no flies inside is 0% - a hermetically sealed house.

Note, with real flies, if the probability of entering the house is low, then night may fall before the stable condition is reached, killing off the flies inside, thus giving fewer flies inside than average fly density would suggest.

Also, in reality it is often true that outsides are bigger than insides. Therefore the outside fly density won't drop in any significant way.

If you want to try this out yourself....

The number of flies entering or leaving was given by:

=INT(B6*A6*2*$B$2 +0.5)

This was in cell C6, a similar formula was in Column G. Column B was the random number (generated by rand() - not perfect, but good enough. Column A was the number of flies outside, $B$2 was probability of entering. The +0.5 and int were to round to the nearest fly (unless you're very cruel, you don't get half a fly). The *2 is because I wanted a random number of 0.5 to give the probability I entered. With 100 flies and 3% this means between 0 and 6 flies are chosen (averaging on 3).

Note, the details of the table will be different to the graph due to the vagaries of RAND()

Starting Number of flies outside 100
Probability of moving in or out 3%
Number outside Random number between 0 and 1 Random number of flies entering Number in House Random number between 0 and 1 Random number of flies leaving
100 0.912550927 5 0 0.31515573 0
95 0.129672467 1 5 0.469564386 0
94 0.133029865 1 6 0.682703659 0
93 0.467370586 3 7 0.292240215 0
90 0.442956033 2 10 0.078355506 0
88 0.950891806 5 12 0.293134229 0
83 0.774958192 4 17 0.487404577 0
79 0.897456544 4 21 0.146389431 0
75 0.303134239 1 25 0.642099887 1
75 0.897724062 4 25 0.32668641 0
71 0.107561794 0 29 0.528802473 1
72 0.881882184 4 28 0.678031399 1
69 0.419767676 2 31 0.563842549 1
68 0.598696409 2 32 0.185831748 0
66 0.881992268 3 34 0.580684087 1
64 0.415099731 2 36 0.225267782 0
62 0.267909168 1 38 0.132241841 0
61 0.207314464 1 39 0.18410092 0
60 0.001413044 0 40 0.682630424 2
..... etcetera