2
$\begingroup$

I have two sets of bearing angle data, one is forecast and the other one is actual, i.e.

forecast = {80, 270, 355, 40, 58, 290, 5}
actual = {85, 5, 10, 90, 70, 10, 20}

How can I calculate the root mean square error between the two sets?

$\endgroup$
5
  • $\begingroup$ RootMeanSquare[forecast - actual] or Sqrt[Mean[(forecast - actual)^2]] $\endgroup$
    – Bob Hanlon
    Nov 23 '21 at 7:59
  • $\begingroup$ 80 compared to 85 makes sense but the other points are way off? Is this intentional? $\endgroup$
    – Syed
    Nov 23 '21 at 7:59
  • $\begingroup$ Not really, the forecast sometimes go wrong. As they are bearing angles, the calculation cannot not simply be "forecast - actual". For example, the 3rd pair of data {355, 10}, difference is 15 deg only instead of (355-10) = 345 deg. $\endgroup$
    – wkong
    Nov 23 '21 at 8:08
  • 1
    $\begingroup$ Please edit this "compass" information into the post instead of the comments. $\endgroup$
    – Syed
    Nov 23 '21 at 8:13
  • 4
    $\begingroup$ RootMeanSquare[Min[Mod[#, 360], Mod[-#, 360]] & /@ (forecast - actual)] gives 4 Sqrt[1159/7], about 51 degrees $\endgroup$
    – LouisB
    Nov 23 '21 at 8:22
2
$\begingroup$
forecast = {80, 270, 355, 40, 58, 290, 5} 
actual = {85, 5, 10, 90, 70, 10, 20}

Mathematica requires the symbol Degree to denote angles in degrees as trig functions use radians.


Define a utility function:

DegreesBW[x1_, x2_] := 
 VectorAngle[{Cos[x1], Sin[x1]}, {Cos[x2], Sin[x2]}]*180/\[Pi] // N

Typical usage:

DegreesBW[1, -1]  (* 114.592, or 2 radians *)

DegreesBW[1 Degree, -1 Degree]   (* 2. *)

Application

I have to multiply both of the input lists by Degree as shown below or else the given values will be treated as radians .

err = MapThread[DegreesBW, Degree {forecast, actual}]

{5., 95., 15., 50., 12., 80., 15.}

RootMeanSquare[err]

51.4698

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.