The geometric mean is similar to the arithmetic mean in that it is a type of average for the data, except it has a rather different way of calculating it.

The geometric mean is defined as the n-th root of the product of each value in the data set, where n is the number of data points in the set. This makes it useful for describing things such as percentage growth.

		public static double GeometricMean(double[] data, int items)
		{
			int i;
			double GMean, prod;

			prod = 1.0;

			for (i = 0; i < items; i++)
			{
				prod  *= data[i];
			}
			GMean =  Math.Pow(prod, (1.0 / (double)items));
			return GMean;
		}
  • Share/Bookmark

Related posts:

  1. Maths algorithms in C#: The median The median is defined as the data point that falls...
  2. Maths algorithms in C#: The Arithmetic mean The arithmetic mean is defined as the average of a...
  3. Maths algorithms in C#: Standard deviation Standard deviation is a very common calculation in statistical analysis,...
  4. Maths algorithms in C#: Variance I talked a bit about variance in the post on...
  5. Maths algorithms in C#: Linear least squares fit When analysing data it is often useful to find an...

Related posts brought to you by Yet Another Related Posts Plugin.