Average length of a rainy period

364 Views Asked by At

Weather is modelled as a Markov chain(first row corresponds to state $0$ (sunny), second row to state $1$(rainy)):

$$ \begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix} $$

The problem is to find the average length of a rainy period. Now the hint given was to find: $$ \sum_{k=1}^\infty kP(X_{k}=0,X_{k-1}=1\dots,X_1=1|X_0=1) \\ =\sum_{k=1}^\infty k 0.4(0.6)^{k-1}\\ $$

I found this to be $2.5$. But I am not comfortable with that expression because it does not impose a restriction on the state of the chain before $X_0$. If the state were $1$, the length of this rainy period would be longer! So instead I evaluated this: $$ \sum_{k=1}^\infty kP(X_{k+1}=0,X_{k}=1\dots,X_1=1|X_0=0) \\ \sum_{k=1}^\infty k 0.4(0.6)^{k-1}0.2\\ $$ which is $0.5$.

But it cannot be 0.5 because the minimum length of rainy period is 1!

I simulated this process in MATLAB and the value seemed to be around $1.5$. (I will post my code if you think this is incorrect)

One other way to do this is to find the expected return time from state $0$ to $0$ and then subtract $1$. Because the return time is $\frac{1}{\frac{2}{3}} = 1.5$, this method gives me $0.5$.(see EDIT)

I am totally confused as to which is right and why the others are wrong.

Any help is greatly appreciated. Thanks.

EDIT: I just realised that the average return time method is wrong because going from state $0$ to $0$ is taken into account when calculating the average return time (in this case the return time is 1), but it should not appear in computing average rainy period as there is no rainy period in 2 consecutive sunny days.

EDIT: Here is the code I wrote to simulate the chain:


n = 10000;
P = [0.8 0.2;0.4 0.6];
mun = [0.9 0.1];
X = zeros(n+2,1);
for i=1:n
    t = rand;
    if t > mun(1)
        X(i+1) = 1;
    end
    mun = mun * P;
end
% find the starting and ending of rainy periods
A = find(diff(X));
% every even position in A has the end of a rainy period and every
% odd position has the start of a rainy period
rainyPeriods = A(2:2:end) - A(1:2:end);
mean(rainyPeriods)