# How to simulate a system where “the failure probability per week is 3.5%”?

I have system described by a statement like "The failure probability per week at 20 Celsius degree is 3.5%", how can I simulate such a system?

The simulation I have in mind should answer to questions like "how many failure will happen in 13 days?"

The simulation should for example produce table like the following one:

timestamp,number of failures at the timestamp
2015-01-16T07:00:00Z,0
2015-01-17T07:00:00Z,0
2015-01-18T07:00:00Z,0
2015-01-19T07:00:00Z,1
2015-01-20T07:00:00Z,1
2015-01-21T07:00:00Z,1
2015-01-22T07:00:00Z,2


I would like to simulate such a system in R, maybe using a Poisson distribution, but I have no idea on how to start, I think it should be something quite simple but maybe I really miss some basic background, may you suggest an example or a tutorial?

• The Poisson process seems to be a good idea. Do you know what is it ? But do you really need all the failures during the time of observation, or only the total number of failures ? In the second case, there's no need of a Poisson process, just a Poisson distribution. – Stéphane Laurent Jan 16 '15 at 10:26
• I think I need the Poisson process, I am not familiar with it... I am not able to relate my probability expressed in percent to the Poisson's "lambda". – Alessandro Jacopson Jan 16 '15 at 11:10
• Let $T$ be the period of observations. Then if you use the Poisson distribution ${\cal P}(\lambda T)$, you can interpret $\lambda$ as the rate of failure. But I'm not sure to understand "failure probability". – Stéphane Laurent Jan 16 '15 at 11:32
• NB: in my previous comment, ${\cal P}(\lambda T)$ is a model for the total number of failures on the period of length $T$. – Stéphane Laurent Jan 16 '15 at 11:33
• Moreover I'm not sure to understand the real experiment you want to model. Is there a fixed number of "operations" per day, and these operations are subject to fail ? – Stéphane Laurent Jan 16 '15 at 19:07

First consider the case we have just one machine. We will have to make some assumptions, and one common and simple one is to model the failure time as exponentially distributed. This means that the failure rate is constant (the probability of failure between time t and t+1, given survival up to time t is constant for all t) (see wiki for more info).

The time to failure, let's denote it by $T \sim Exp(\lambda t)$ where t denotes time in days. We first need to find $\lambda$, and since we know the probability of failure in one week is 3.5%, we get: $P(T < 7) = 1-e^{-7 \lambda} = 0.035$. Working this out, we get $\lambda = 0.00221$.

Now to simulate the failures for $N$ machines as time progresses, we can draw $N$ samples from an Exponential distribution with $\lambda = 0.00221$. This will give you failure times of the $N$ machines in days.

• This also works well because of the forgetfulness property of the exponential: given you have survived this last, the probability you fail this next week is equal to that of last week, i.e. your survival is independent of how long you have survived for. (A consequence of a constant hazard rate). This means that if we start with $N$ machines, there will still always be 3.5% failure each week (on average). – Cam.Davidson.Pilon Feb 5 '15 at 4:51
• Can you check your math? I get lambda=-log(1-0.035)/7 and so lambda = 0.00509 – DWin Jul 18 '15 at 23:56

It seems like you don't need information more frequently than daily, so the most obvious approach would be to compute the distribution of the number of failures per day, and then simulate from that.

Alternatively, you can simulate the exponential inter-event times and go from that. This gives intra-day precision if you need information at that level.

"how many failure will happen in 13 days?"

You can work this out without simulation. To do it with the daily simulation, you could simulate sets of 13 days many times and keep the simulated distribution of values.

This is very easy in R.