Skip to content

Mode value

6 messages · Carlos Morales, stephen sefick, milton ruser +3 more

#
Hello everyone,


I would like to know if there is any function to calculate the mode value, or I have to build one to do it.


Thanks so much
Carlos
#
look here:
http://www.nabble.com/how-to-calculate-the-mode-of-a-continuous-variable-td19214243.html#a19214243

On Sat, Sep 6, 2008 at 1:24 PM, Carlos Morales
<carlosmoralesdiego at yahoo.es> wrote:

  
    
#
On 09/06/08 17:24, Carlos Morales wrote:
I just did this the other day.  Funny you should ask.  It finds the
mode of each row of a matrix called Pbest.

Pbest.p <- apply(Pbest,1,function(x) 
 x[which.max(as.vector(table(x)))][1])

So to get the mode of a vector v1, the following should work (but I
haven't tried it):

v1[which.max(as.vector(table(v1)))][1]
#
Carlos Morales wrote:
Hi Carlos,
If you mean the mode of a sample from a discrete distribution, try Mode 
in the prettyR package.

Jim
3 days later
#
Others showed you how to find the mode in a dataset, I just want to point out that if your data is from a continuous distribution (or near continuous), then the mode of the data is more likely to be the result of a quirk of rounding than representative of anything useful.  If the data is discrete, then the mode of the data may be meaningful, but looking at the entire table of frequencies, or a plot of them, will give you the mode information along with additional information that may help determine if that mode value is meaningful.

If you really want to make inference about the mode of a continuous distribution then you should either use something like fitdistr (from the MASS package) to fit the data to a specific distribution, then use the theory/likelihood of that distribution to find the mode, or use the density function or the logspline package to fit a density to the data (less dependent upon assumptions about the distribution) and look at the mode(s) from those estimates.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111