Rain forecast model and least squares

102 Views Asked by At

Good evening everyone,

I'm trying to create a rain forecast model, I have about 720 data, which correspond to monthly rainfall in 60 years during the 12 months of the year.

I have a matrix $M_{60\times12}(\mathbb{R})$ where each column is the rain of each month.

The model takes as parameters the month which you want to estimate the amount of rainfall and the amount of rain the three months prior to this.

What I did was t=linspace(1,12,180) and use as $y$ the precipitation in the three months prior to the desired then I just make polyfit(t,y,1)

However it is not giving me good results, but I have two observations that can be the problem

-I thought of creating twelve different models specific for each month chosen, but in this case it makes no sense to divide t in the range 1-12.

If anyone can give me some idea thank.

1

There are 1 best solutions below

0
On BEST ANSWER

I guess you are looking for autoregressive model such as

$$X(t)=a_1 X(t-1)+a_2 X(t-2)+a_3 X(t-3)$$

What you can do is to use ordinary least squares method to solve

$$Y = \begin{bmatrix} X_4 \\ X_5 \\ ... \\ X_{60} \\ \end{bmatrix} = \begin{bmatrix} X_1 & X_2 & X_3 \\ X_2 & X_3 & X_4 \\ . & . & . \\ X_{57} & X_{58} & X_{58} \end{bmatrix} \begin{bmatrix} a_1 \\ a_2 \\ a_3 \end{bmatrix}$$

which has the solution for estimators $$ A= (X^T X)^{-1} X^T Y$$

To transform your data and to solve for estimators you may use following code

For i=1:12
For j=1:60
A(5*(j-1)+i)=M(j,i);
End
End
For j=4:60
Y(j-3,1)=A(j);
X(j-3,:)=A(j-3:j-1);
End
A=inv(X'X)*X'*Y