So, I am working on an application using compass angles (in degrees). I was able to determine the calculation of the mean of the angles using the following (found at http://en.wikipedia.org/wiki/Directional_statistics#The_fundamental_difference_between_linear_and_circular_statistics ):
double calcMean(ArrayList<Double> angles){ double sin = 0; double cos = 0; for(int i = 0; i < angles.size(); i++){ sin += Math.sin(angles.get(i) * (Math.PI/180.0)); cos += Math.cos(angles.get(i) * (Math.PI/180.0)); } sin /= angles.size(); cos /= angles.size(); double result =Math.atan2(sin,cos)*(180/Math.PI); if(cos > 0 && sin < 0) result += 360; else if(cos < 0) result += 180; return result; }
So, I am correctly evaluating averages / averages, but I cannot get the correct variance / stddev values. I am sure that I am not calculating my deviation correctly, but I can not come up with the right way to do this.
This is how I calculate the variance:
double calcVariance(ArrayList<Double> angles){
Although this is the correct way to calculate deviation, I am not what I should use. I guess I should use arctangent, but the standard deviation / variance values ββseem to be off. Help?
EDIT: Example. Entering values ββof 0,350,1,0,0,0,0,1,358,9,1 leads to an average angle of 0.0014 (since the angles are so close to zero), but if you just do a non-angular average, you will get 72 ... which long away. Since I do not know how to manipulate the individual values ββas they should be, the calculated variance is 25074, resulting in a standard deviation of 158 degrees, which is crazy !! (It should be only a few degrees). I think what I need to do is correctly normalize the individual values ββso that I can get the correct variance / stddev values.