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:> 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 > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Hi Carolos, I know that it is not a elegant soluction, but may work. Almost for integer values. Take care with float values. modevalue<-function(x) { x.freq<-data.frame(table(x)) x.freq.max<-max(x.freq$Freq) x.freq.selected<-subset(x.freq, x.freq$Freq==x.freq.max) return(c(unlist(x.freq.selected$x))) } x<-sample(x=0:10, size=200, replace=T) modevalue(x) On Sat, Sep 6, 2008 at 2:24 PM, Carlos Morales <carlosmoralesdiego@yahoo.es>wrote:> 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 > > > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On 09/06/08 17:24, Carlos Morales wrote:> 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.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] -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron
Carlos Morales wrote:> 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. > >Hi Carlos, If you mean the mode of a sample from a discrete distribution, try Mode in the prettyR package. Jim
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> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Carlos Morales > Sent: Saturday, September 06, 2008 11:24 AM > To: r-help at r-project.org > Subject: [R] Mode value > > 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 > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >