mmse
Syntax
mmse(Y, X, window, [minPeriods])
Please see Moving Functions (m-functions) for the parameters and windowing logic.
Details
Return the coefficient estimates of X and mean square errors of an ordinary-least-squares regression of Y on X with intercept with a rolling window. The length of the window is given by the parameter window.
The mean square error (MSE) is calculated with the following formula:
\(MSE=\dfrac{1}{n} {\sum\limits_{i = 1}^{n} (Y_i - \hat{Y_i})^2}\)
The result is a tuple with 2 vectors. The first vector is the coefficient estimates and the second vector is the mean square errors. Each vector is of the same length as X and Y.
Examples
$ x=0.011 0.006 -0.008 0.012 -0.016 -0.023 0.018
$ y=0.016 0.009 -0.012 0.022 0.003 -0.056 0.002;
$ mmse(y, x, 5)[0];
[,,,,0.818182,1.692379,1.188532]
$ mmse(y, x, 5)[1];
[,,,,0.000055,0.000231,0.000332]
$ select y, x, mmse(y,x,5,3) as `mbeta`mmse from table(x,y);
y |
x |
mbeta |
mmse |
---|---|---|---|
0.016 |
0.011 |
||
0.009 |
0.006 |
||
-0.012 |
-0.008 |
1.479381 |
2.806415E-8 |
0.022 |
0.012 |
1.594701 |
0.000003 |
0.003 |
-0.016 |
0.818182 |
0.000055 |
-0.056 |
-0.023 |
1.692379 |
0.000231 |
0.002 |
0.018 |
1.188532 |
0.000332 |