Skip to main content
replaced http://stats.stackexchange.com/ with https://stats.stackexchange.com/
Source Link

I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array or collection of numbers.

Example: taking integers to make it easier to explain, say the proportion of elements that we're looking for is 50% on this array:

[1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]

The mystery function would return something like ( 2, 4 ), meaning that the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). That little window contains 8 of the 16 values and it's only 2 units wide, the narrowest such window that contains half the number of values.

Note: the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.

I can code it...may take some time to get it nice. Hopefully somebody has run across it before. Does it have a name? Is there an existing method that somebody knows about?

I am interested in Python implementations.

UPDATE:

Thanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: Find probability density intervalsFind probability density intervals

I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array or collection of numbers.

Example: taking integers to make it easier to explain, say the proportion of elements that we're looking for is 50% on this array:

[1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]

The mystery function would return something like ( 2, 4 ), meaning that the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). That little window contains 8 of the 16 values and it's only 2 units wide, the narrowest such window that contains half the number of values.

Note: the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.

I can code it...may take some time to get it nice. Hopefully somebody has run across it before. Does it have a name? Is there an existing method that somebody knows about?

I am interested in Python implementations.

UPDATE:

Thanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: Find probability density intervals

I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array or collection of numbers.

Example: taking integers to make it easier to explain, say the proportion of elements that we're looking for is 50% on this array:

[1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]

The mystery function would return something like ( 2, 4 ), meaning that the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). That little window contains 8 of the 16 values and it's only 2 units wide, the narrowest such window that contains half the number of values.

Note: the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.

I can code it...may take some time to get it nice. Hopefully somebody has run across it before. Does it have a name? Is there an existing method that somebody knows about?

I am interested in Python implementations.

UPDATE:

Thanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: Find probability density intervals

edited tags
Link
Tim
  • 141.2k
  • 26
  • 270
  • 512
Notice removed Reward existing answer by whuber
Bounty Ended with Nick Cox's answer chosen by whuber
Tweeted twitter.com/#!/StackStats/status/403640233658687488
Notice added Reward existing answer by whuber
Bounty Started worth 50 reputation by whuber
tightened presentation, rephrased to reduce Python emphasis
Source Link
Nick Cox
  • 59.5k
  • 8
  • 136
  • 212

numpy/scipy method for retrieving Retrieving minimum width slice that contains N%specified fraction of all values. is there a name for this?

(I hope it's ok to put this on stats AND stackoverflow..I'll point to whatever post gets answered.)

I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array.(or or collection of numbers).

example...takingExample: taking integers to make it easier to explain., say the proportion of elements that we're looking for is 50% on this array:

[1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]

theThe mystery function would return something like ( 2, 4 )...meaning, meaning that the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). thatThat little window contains 8 of the 16 values and it's only 2 units wide...the most narrow, the narrowest such window that contains half of the number of values.

noteNote: the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.

I can code it...may take some time to get it nice. hopefullyHopefully somebody has run across it before. doesDoes it have a name? is Is there an existing method that somebody knows about?

thanks so much!I am interested in Python implementations.

UPDATE:

thanksThanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: Find probability density intervals

numpy/scipy method for retrieving minimum width slice that contains N% of all values. is there a name for this?

(I hope it's ok to put this on stats AND stackoverflow..I'll point to whatever post gets answered.)

I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array.(or collection of numbers)

example...taking integers to make it easier to explain. say the proportion of elements that we're looking for is 50% on this array:

[1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]

the mystery function would return something like ( 2, 4 )...meaning the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). that little window contains 8 of the 16 values and it's only 2 units wide...the most narrow such window that contains half of the number of values.

note the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.

I can code it...may take some time to get it nice. hopefully somebody has run across it before. does it have a name? is there an existing method that somebody knows about?

thanks so much!

UPDATE:

thanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: Find probability density intervals

Retrieving minimum width that contains specified fraction of all values

I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array or collection of numbers.

Example: taking integers to make it easier to explain, say the proportion of elements that we're looking for is 50% on this array:

[1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]

The mystery function would return something like ( 2, 4 ), meaning that the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). That little window contains 8 of the 16 values and it's only 2 units wide, the narrowest such window that contains half the number of values.

Note: the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.

I can code it...may take some time to get it nice. Hopefully somebody has run across it before. Does it have a name? Is there an existing method that somebody knows about?

I am interested in Python implementations.

UPDATE:

Thanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: Find probability density intervals

added 205 characters in body
Source Link
Loading
added 44 characters in body
Source Link
Loading
Source Link
Loading