Skip to content

distribution_mode in somewhat complex cases #695

Description

@elinw

If you try some special cases of the mode, I think there are incorrect results.

> distribution_mode(c(1, 2, 3, 3, 4, 4, 5))
[1] 3
> distribution_mode(c(1, 2, 3, 4, 5))
[1] 1
> distribution_mode(c(1, 2, 3, 3, 4, 4, 5, 5))
[1] 3
> distribution_mode(c(1, 2, 3, 3, 4, 5, 5))
[1] 3

On a simple level the issue is what should happen if there are ties or if all of the frequencies are tied. The simplest thing would be to return NA in those cases.

This long Stack Overflow thread
http://stackoverflow.com/questions/2547402/standard-library-function-in-r-for-finding-the-mode

discusses some of the issues.

Update
Here is a link to what SASdoes.
https://documentation.sas.com/doc/en/pgmsascdc/v_073/procstat/procstat_univariate_examples02.htm
Basically, like the current function, when there are multiple modes in a set of statistics they return the lowest but including a note that indicates how many modes there are.
When there are multiple modes and the mode alone is selected they return a table with all of them. (When I made a mode function previously I returned a vector of modes.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions