# MTTH - how does it work exactly?

#### lila-laune-bär

##### Captain
I think the new system of "mean time to happen" is a very interesting concept. So I'm interested in how it works exactly. As I understand it, it's basically a concept of probability, and MTTH is the expected time time wait for an event to fire. Speaking of probabilty, we name it "mean".

That's nice and all, but that's only half the information. It's even more important what type of probabilty distribution we've got and what's the statistical dispersion. Is there any more information about the system available? If not, one could run write an event, which should fire very often, note when it fires and thus estimate the dispersion, which would be quite handy for modders, I believe.

My first guess would be that the game uses a normal distribution.

Last edited:
• 1

#### Zakath

##### General
I believe MTTH is a lot simpler than that. Basically if MTTH = 300, then there's 1/300'th chance of it happening each month.

Can't give you a quote for this, but I think I saw it in the wiki somewhere.

#### esbenmf

##### Eltit Motsuc
1/MTTH is the probability of said event happening each month independently of other months. We are thus working with an exponential distribution with parameter MTTH.

Esben

• 1

#### lila-laune-bär

##### Captain
Zakath said:
I believe MTTH is a lot simpler than that. Basically if MTTH = 300, then there's 1/300'th chance of it happening each month.

Can't give you a quote for this, but I think I saw it in the wiki somewhere.
esbenmf said:
1/MTTH is the probability of said event happening each month independently of other months. We are thus working with an exponential distribution with parameter MTTH.

Esben
It's as simple as that? Gosh, I thought paradox would have used a more elaborated model.

So thanks, case closed.

edit: But that's no exponential distribution, but a geometric distribution, if I'm not mistaken.
http://en.wikipedia.org/wiki/Geometric_distribution

#### esbenmf

##### Eltit Motsuc
It is the descrete version of an exponential distribution, yes.

Esben

#### Hakkapeliitta

##### ∇X(ω)
Zakath said:
I believe MTTH is a lot simpler than that. Basically if MTTH = 300, then there's 1/300'th chance of it happening each month.

Can't give you a quote for this, but I think I saw it in the wiki somewhere.
I remember seeing the same. Thus the MTTH value of k time units maps one-to-one to the fixed probability per time unit p that has the property that

expected number of the event triggering = 1 for k time units...

[my probability math is a bit rusty but i AFAIK it's basicly a poisson process
with the intensity of p*t. Which would mean that more generally the probablity of the event triggering exactly k times in a time of t would be

P(# of triggering = k) = exp(-p*t)*((p*t)^k/k!)

]

#### Johan

Super Moderator
Moderator
MeanTimeToHappen = the value given after modifiers..
noOfDays = basically, how many days are between checks.. (currently 1)

Code:
``````		float daylyChance = float(1.0f - exp( log(0.5f) / MeanTimeToHappen ));
float chance = float(1 - exp( noOfDays * log(1 - daylyChance)) );
return chance;  //0-1% chance of event happening that day``````

#### Hive

##### Lex Superior
Johan said:
noOfDays = basically, how many days are between checks.. (currently 1)
Is this hardcoded, or can it be defined in an event? Would be useful to have the game check for triggers in certain events with intervals. I assume it would also help on game performance if it doesn't have to check all events every day.

#### Darkrenown

##### Star marshal
That's source code (C++ maybe) in the box, so it's hardcoded

#### Hive

##### Lex Superior
Darkrenown said:
That's source code (C++ maybe) in the box, so it's hardcoded
Yeah I'm aware that the content Johan posted is from the code, but perhaps there was some sort of equalent to the EU2 'offset'.

#### Darkrenown

##### Star marshal
Nope, MTTH and modifiers is all we have.

#### Hakkapeliitta

##### ∇X(ω)
Johan said:
MeanTimeToHappen = the value given after modifiers..
noOfDays = basically, how many days are between checks.. (currently 1)

Code:
``````		float daylyChance = float(1.0f - exp( log(0.5f) / MeanTimeToHappen ));
float chance = float(1 - exp( noOfDays * log(1 - daylyChance)) );
return chance;  //0-1% chance of event happening that day``````
Thank you Johan (God of Thunder etc.)!

So it isn't simple 1/MTTH chance per time unit after all.

The above definition leads to probability p (chance_per_day) that, when checked for a time period of MTTH will result in a 0.5 (=50%) chance of the event firing at least once. So currently the wiki is wrong on this.

Let's have a concrete example: an event with a modified MTTH of 3 months. 3 months = 90 days. Log is the natural logarithm in C++.

chance per day p:
Code:
``````P =1-exp(log(0.5)/90)
=1-exp(log(0.5))^(1/90)
=1-(0.5)^(1/90)``````
i.e. aproximately p=0.007672053737056518974464631174 chance per day.

Since currently noOfDays=1 then chance per check is the same as daily chance.

With the above daily chance p the following holds:

1) The expected value for the number of times that the event triggers during 3 months is not 1 (as it would be if the wiki was right), but 90*p, i.e. aproximately 0.69.

2) The amount of days k that one has to wait for the event to have had a 50-50 chance of triggering (at least once) is 90 days (i.e. exactly the MTTH):

Code:
``````(1-p)^k=0.5
k*log(1-p) = log(0.5)
k=log(0.5)/log(1-p)
k=90``````

Last edited:

#### dharper

##### Dei Gratia author

I have been hoping for some time that a Paradox staffer would post the math behind the MTTH. Thank you for this thread!

#### unmerged(47003)

##### Captain
Damn you. Making me dust off my calculator! It's been years since I've done any math.

The code may as well be Gree... well Swedish to me, so thank you for the little writeup Hakkapeliitta.

It looks as though that .69 probability of the event occurring once in the MTTH is constant--it doesn't matter what the MTTH is, it will always be .69. (I know there's probably a simple way to do this algebraically, but hooray for arithmetic trial and error!)

Then for the chance for the event to occur exactly once, it would just be 1/0.69=1.45.

So the wiki could just be changed to saying "The event will probably occur once by 1.45*MTTH." (As well, of course, as the code itself.)

This 1.45*MTTH is the value I suspect most players will care about.

This goes a fair bit to explaining why I only had 2 of my 5 possible Yemeni great men fire, despite the fact that they were all in office for 25+ years. (Great Men MTTH = 25 years) They would have to be in office for 36.25 years to probably fire. (And the MTTH was actually a bit higher than 25 years, since I had a couple of *1.1 penalties for narrowminded and the like.)

...

Isn't there a way to tell when an event has a 95% likelihood that it will fire within a certain period? Something with standard deviations or something like that.

So you could say "an event will fire probably once in 1.45*MTTH, but by x*MTTH, there is a 95% chance that the event will have fired." Then you could set hard end dates on when events will fire by and rely upon those in a game or mod.

#### Hakkapeliitta

##### ∇X(ω)
Primus Inter Pa said:
Damn you. Making me dust off my calculator! It's been years since I've done any math.

The code may as well be Gree... well Swedish to me, so thank you for the little writeup Hakkapeliitta.

It looks as though that .69 probability of the event occurring once in the MTTH is constant--it doesn't matter what the MTTH is, it will always be .69. (I know there's probably a simple way to do this algebraically, but hooray for arithmetic trial and error!)
The expected number of the event triggering during a time period of MTTH length is

Code:
``MTTH*(1-(0.5)^(1/MTTH))``
which is not a constant (easy example MTTH=1 day), but in practical cases usually hangs around 0.69. One needs to bear in mind that it isn't the "chance of event happening once" but the expected value, i.e. if you tried it out 1000 times, and counted how many times the event triggered during the MTTH it would sometimes not trigger at all, sometimes many times, but the mean "number of event triggering" would be the expected value.

Isn't there a way to tell when an event has a 95% likelihood that it will fire within a certain period? Something with standard deviations or something like that.
Sure. Let's again assume that the checks are made daily. The number of checks needed for the "event having triggered at least once has 95% probability" is the same as for "the event hasn't triggered even once has 5% probability"

Code:
``````(1-p)^k=0.05
k=log(0.05)/log(1-p)
k=log(0.05)/log(exp(log(0.5)/MTTH))
k=(log(0.05)/log(0.5))*MTTH``````
log(0.05)/log(0.5) is aproximately 4.32. So the rule of thumb would be that in a period of MTTH*4.32 the event has a 95% chance of firing at least once.

Last edited:

#### unmerged(53922)

##### Lt. General
So I understand that chances to event be fired are growing from day to day. What's about game reloading ? Is it enough information in save file, to not start counting from day one ? I am just waiting for Westernization and after 12 years of waiting I saved my game .... I was fulfilled all conditions but after 20 years (240 months) of waiting I still have no luck. Mayby game reloading is my problem ?

Last edited:

#### lenny

##### Field Marshal
Kristof73 said:
So I understand that chances to event be fired are growing from day to day. What's about game reloading ? Is it enough information in save file, to not start counting from day one ? I am just waiting for Westernization and after 12 years of waiting I saved my game .... I was fulfilled all conditions but after 20 years (240 months) of waiting I still have no luck. Mayby game reloading is my problem ?
Given that the modifiers to MTTH do not change, the daily chance of an event firing remains constant over time. No information has to be saved what so ever, and saving/reloading does not change your "luck".

#### unmerged(53922)

##### Lt. General
lenny said:
Given that the modifiers to MTTH do not change, the daily chance of an event firing remains constant over time. No information has to be saved what so ever, and saving/reloading does not change your "luck".
So with huge luck any event could fire after even one day of waiting or teoretically never ....