# Root mean square error of bearings

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?

• RootMeanSquare[forecast - actual] or Sqrt[Mean[(forecast - actual)^2]] Nov 23, 2021 at 7:59
• 80 compared to 85 makes sense but the other points are way off? Is this intentional?
– Syed
Nov 23, 2021 at 7:59
• 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. Nov 23, 2021 at 8:08
– Syed
Nov 23, 2021 at 8:13
• RootMeanSquare[Min[Mod[#, 360], Mod[-#, 360]] & /@ (forecast - actual)] gives 4 Sqrt[1159/7], about 51 degrees Nov 23, 2021 at 8:22

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