Calculate average latitude / longitude I have the array of geographical coordinates (latitude & longitude).
What is the best way to calculate average latitude and longitude?
Thanks!
 A: This is a question of directional statistics. Similar issues arise with the average of circular quantities.
The conventional method is to convert latitudes ($\phi_i$) and longitudes ($\lambda_i$) into three dimensional points $(x_i,y_i,z_i)$ using
$$(R \cos \phi_i  \cos \lambda_i, R \cos \phi_i  \sin \lambda_i  , R \sin \phi_i )$$
then take the mean of these points $(\bar{x},\bar{y},\bar{z})$, generally giving you a point inside the sphere, and then converting this direction back to latitude and longitude, using something like
$$\bar{\phi} = \text{atan2}\left(\bar{y},\bar{x}\right) \text{ and } \bar{\lambda} = \text{atan2}\left(\bar{z},\sqrt{\bar{x}^2+\bar{y}^2}\right).   $$
Proportionately how far the mean point is inside the sphere, i.e. $\frac{\sqrt{\bar{x}^2+\bar{y}^2+\bar{z}^2}}{R}$, is an indicator of dispersion of the original points.
A: The variables you mention are points belonging to the manifold, which is the circle. Therefore, they cannot be treated as if they belonged to Euclidean space.
It should also be considered whether we calculate the mean longitude and mean latitude separately or the mean position on the surface of the sphere. It is not the same. There is, of course, an intrinsic mean on the sphere.
I recommend the material that I have prepared on this subject and today I am sharing it on YouTube:
Circular means - Introduction to directional statistics.
There are two main types of circular mean: extrinsic and intrinsic.
Extrinsic mean is simply the mean calculated as the centroid of the points in the plane projected onto the circle.
$$
\bar{\vec{x}}=\frac{1}{N}\sum_{j=1}^N \vec{x}_j=\frac{1}{N}\sum_{j=1}^N [x_j,y_j]=\frac{1}{N}\sum_{j=1}^N [\cos{\phi_j},\sin{\phi_j}]
$$
$$
\hat{\bar{x}}=\frac{\bar{\vec{x}}}{|\bar{x}|}
$$
$$
\DeclareMathOperator{\atantwo}{atan2}
\bar{\phi}_{ex}=\atantwo(\hat{\bar{x}})
$$
It is NOT a mean calculated using the natural metric along the circle itself.
Intrinsic mean, on the other hand, does have this property. This mean can be obtained by minimizing the Fréchet function.
$$
\DeclareMathOperator*{\argmin}{argmin}
\bar{\phi}_{in}=\argmin_{\phi_0\in C} \sum_{j=1}^N (\phi_j-\phi_0)^2
$$
For discrete data, you can also analytically determine the $N$ points suspected of being the mean and then compare them using the Fréchet function.
$$
\bar{\phi}_k=\arg \sqrt[N]{\prod_{j=1}^N e^{i\phi_j} }=\bar{\phi}_0+k\frac{2\pi}{N}
$$
Where the N-th root is a N-valued function with outputs indexed with $ k\in\{1,\dots,N\} $. They are distributed evenly on the circle. And $ \bar{\phi}_0 $ is a usual mean calculated in an arbitrary range of angle values of length of $2\pi$.
If somebody dislikes the complex numbers
$$
\bar{\phi}_k=\frac{1}{N} \left(\sum_{j=1}^N \phi_j+k2\pi\right)
$$
The result is, of course, the same.
Then you have to compare the points suspected of being the mean using the Fréchet function.
$$ 
\DeclareMathOperator*{\argmin}{argmin}
\bar{\phi}_{in}=\argmin_{k\in\{1,\dots,N\}} \sum_{j=1}^N (\phi_j-\bar{\phi}_k)^2
$$
Where the search for minimum runs over $N$ discreet indices.
