Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I've continuous distribution set of values.

For example:

0, 0.01, 0.012, 1.2, 5.33, 5.24, 5.38, 30.20, 30.21, 30.13, 30.12

I want to calculate most frequent value from this set. So I've found this question which says it's mode.

I've problem with spliting this set into clases.

I want to put in my algorithm some delta value and assign to one class values which fullfills x - delta < mean_class_value < x + delta. Of course I see the problem that I don't have a class and to create it I need it's mean value. Also solution which will make the same reasonable result will be ok.

Any solution in pseudocode will be great help.

My current solution its pseudocode mixed with c++ but hope understandable:

std::vector<std::pair<double, std::vector<elementtype> > > classes;
foreach(element)
{
    foreach(class in classes)
    {
        if(std::abs(element.value - class.first) //class first is value of class
        {
             //assign element to class here
             class.first = (class.first + element.value) / 2.0 //averaging class value
             break;
        }
        else
        {
             //create new class
        }

    }
}
share|improve this question
add comment

2 Answers 2

There are many estimators for the mode of a continuous distribution.

The answer here links to the documentation of an R package.

The advantage at looking at that R package is that one gets to learn about different mode estimators (with the appropriate reference in the pdf document).

Also, since you are interested in code, here is the source code link for all the routines in there.

share|improve this answer
    
I've found this answer. But seems to be too complicated for my problem. Look at my attached code it is very simple. I'm looking for some easy estimation. –  krzych Nov 9 '12 at 12:34
add comment

First of all you have discrete set of values . Depending on the purpose of your data analysis you can evaluate different statistics ( functions of the data). If you want to divide your data into classes you should calculate histogram. Assume $x_{(1)}=min_{i} x_i$ ( the smallest element) and $x_{(n)}=max_i x_i$ ( the largest element ), assume also that you want to divide your data set into $k$ disjoint classes. Proceed as follows: let $\delta=\frac{x_{(n)}-x_{(1)}}{k}$, $\forall i=0,...,k-1$ calculate amount of the elements in the interval $[x_{(1)}+i*\delta,x_{(1)} + (i+1)*\delta]$. This will be representation of your data as a histogram, nothing more. As for the most frequent value, I doubt that mode will be of any value ( if you have indeed continuous distribution it won't even have a meaning) instead you should calculate mean.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.