# Problem with Mode

## Problem with Mode

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

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

## Problem with MODE

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:

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

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

## Re: Problem with Mode

John, many thanks

I have it up and running:-)

Charlie

I have it up and running:-)

Charlie

**CharlieT**- Posts : 2

Join date : 2012-02-20

Similar topics

» Mode of Pocurement

» Silverfish problem....

» Timeline for Shopping Mode of Procurement and Other Alternative Methods

» alternative mode of procurement

» PROFIT-SHARING ARRANGEMENT AS MODE OF PAYMENT

» Silverfish problem....

» Timeline for Shopping Mode of Procurement and Other Alternative Methods

» alternative mode of procurement

» PROFIT-SHARING ARRANGEMENT AS MODE OF PAYMENT

Page

**1**of**1****Permissions in this forum:**

**cannot**reply to topics in this forum