Problem with Mode

View previous topic View next topic Go down

Problem with Mode

Post  CharlieT on Mon Feb 20, 2012 1:32 pm

Hi, I am not getting the result I expected for the mode of some lognormal numbers using :

LOGNORMAL EXP 10000 1 0.50 logNorm
MODE logNorm resmode
print resmode

HISTOGRAM PERCENT binsize 0.05 logNorm

Any thoughts?

Thanks

Statistics101 Vers 2.1 on Win7 64

CharlieT

Posts : 2
Join date : 2012-02-20

View user profile

Back to top Go down

Problem with MODE

Post  John on Tue Feb 21, 2012 11:17 am

Charlie,

Very good question!

The reason you're not getting what you expect is that the LOGNORMAL distribution is a continuous distribution. The MODE command is designed for discrete distributions. The problem arises because the MODE command counts all multiples of each value and chooses the value with the most multiples. But a continuous distribution will seldom produce exact duplicates of any of its values. Therefore the MODE command will not produce the expected result.

To compute the mode for a continuous distribution, you need a command that will group the data into bins (like HISTOGRAM does) and then find the bin that has the most data. Here is a subroutine, MODE_CONTINUOUS that will do it:

Code:
'Computes the MODE of a vector containing random data
'from a continuous distribution. The mode is the most
'frequently occurring value in a distribution, but it
'cannot be reliably computed in the same way as it is
'for a discrete distribution. For continuous distribution
'the data must be sorted into bins and the bin with the
'most items becomes the mode.
'Inputs:
'  binsize: the size of the bins into which the data
'      is to be sorted.
'  vec: the vector containing the randomly selected data.
'Outputs:
'  mode: the value of the center of the bin containing
'      the most data.
NEWCMD MODE_CONTINUOUS binsize vec mode  @"statistics" ?"Computes mode of a continuous random variable."
  HISTOGRAMDATA binsize binsize vec binNum binStarts binCenters freqs
  MAX freqs maxFreq
  TAGS freqs = maxFreq modeTag
  TAKE binCenters modeTag mode
END

I'll consider adding this to the Statistics101 library for the next release, but meanwhile, you can add it to your library yourself.

Regards,

John


Last edited by John on Tue Feb 21, 2012 11:59 am; edited 1 time in total (Reason for editing : Added annotations to NEWCMD command.)

John

Posts : 11
Join date : 2011-09-06

View user profile

Back to top Go down

Re: Problem with Mode

Post  CharlieT on Tue Feb 28, 2012 3:49 pm

John, many thanks

I have it up and running:-)

Charlie

CharlieT

Posts : 2
Join date : 2012-02-20

View user profile

Back to top Go down

Re: Problem with Mode

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum