Maxima Function
lsquares_mse (D, x, e)
Returns the mean square error (MSE), a summation expression, for the equation e in the variables x, with data D.
The MSE is defined as:
n ==== \ 2 > (lhs(e ) - rhs(e )) / i i ==== i = 1 -------------------------- n
where n is the number of data and e[i]
is the equation e
evaluated with the variables in x assigned values from the i
-th datum, D[i]
.
load(lsquares)
loads this function.
Example:
(%i1) load (lsquares)$ (%i2) M : matrix ([1, 1, 1], [3/2, 1, 2], [9/4, 2, 1], [3, 2, 2], [2, 2, 1]); [ 1 1 1 ] [ ] [ 3 ] [ - 1 2 ] [ 2 ] [ ] (%o2) [ 9 ] [ - 2 1 ] [ 4 ] [ ] [ 3 2 2 ] [ ] [ 2 2 1 ] (%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C); 5 ==== \ 2 2 > ((D + M ) - C - M B - M A) / i, 1 i, 3 i, 2 ==== i = 1 (%o3) --------------------------------------------- 5 (%i4) diff (mse, D); 5 ==== \ 2 4 > (D + M ) ((D + M ) - C - M B - M A) / i, 1 i, 1 i, 3 i, 2 ==== i = 1 (%o4) ---------------------------------------------------------- 5 (%i5) ''mse, nouns; 2 2 9 2 2 (%o5) (((D + 3) - C - 2 B - 2 A) + ((D + -) - C - B - 2 A) 4 2 2 3 2 2 + ((D + 2) - C - B - 2 A) + ((D + -) - C - 2 B - A) 2 2 2 + ((D + 1) - C - B - A) )/5