Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the "peak" of a set of data

I have a set of data, for which I'd like to find an average peak. I've done some testing in Numbers.app to see what I'm after and if I make a chart of the dataset it has a feature it calls "polynomial trendline" which draws a curve of the data and the peak of that curve looks exactly like the point/value I'm after.

So how could I programmatically calculate that curve and find that tangent on the curve?

I've been looking around on wikipedia and found topics like "Normal distribution" and "Polynomial regression" which seems very much related, but I've always found it hard to follow the equations on wikipedia so I'm hoping maybe someone here could give me a programatic example.

Here's a couple of charts to illustrate what I'm after. The green dots are the data points and the blue line is the "polynomial trendline" (of order 6). The "peak" of that trendline is what I'm after.

Example with even datasetExample with uneven dataset

Updated question:

After some answers I realize my question need to be rephrased as the problem is not really how to find the peak of the curve but more of how to generate that blue curve from the green points so I can find where in the dataset the "weight" lies. The goal is to get a sort of 'average maximum'.

I guess another question would be "what is this particular problem actually called?" ;)

like image 363
Robert Sköld Avatar asked Aug 18 '10 12:08

Robert Sköld


2 Answers

Although the data looks like that you're not necessarily after a normal distribution.

The topic of distribution fitting is quite complex and, unless you have some clear a priori assumptions of what your data distribution is, I would not venture there. In case you have assumptions on the type of distribution, have a look at least squares or maximum likelihood extimation methods.

However, I would suggest you should rather use a bezier-spline or LOESS to "smooth" your data and then just find the maximum of the computed curve.

I doubt that an approach using the derivative would work here.

like image 171
nico Avatar answered Oct 07 '22 04:10

nico


As you speak of normal distributions, and seem to be able to fit data to a function, you should fit to a normal distribution, which jas parameters µ and σ, which are respectively the mean and standard deviation of the distribution (see wiki first formula).

Fit this function to your data, and the peak will be at the mean value, given by µ.

like image 27
rubenvb Avatar answered Oct 07 '22 05:10

rubenvb