Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10347 > unrolled thread

Histogram ignores 'bspec' (bin spec) ??

Started byJames Stein <mathgroup@stein.org>
First post2012-06-04 08:21 +0000
Last post2012-06-05 08:55 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Histogram ignores 'bspec' (bin spec) ?? James Stein <mathgroup@stein.org> - 2012-06-04 08:21 +0000
    Re: Histogram ignores 'bspec' (bin spec) ?? "Chris Degnen" <degnen@cwgsy.net> - 2012-06-05 08:52 +0000
      Re: Histogram ignores 'bspec' (bin spec) ?? Chris Degnen <degnen@cwgsy.net> - 2012-06-07 09:22 +0000
    Re: Histogram ignores 'bspec' (bin spec) ?? "Nasser M. Abbasi" <nma@12000.org> - 2012-06-05 08:55 +0000

#10347 — Histogram ignores 'bspec' (bin spec) ??

FromJames Stein <mathgroup@stein.org>
Date2012-06-04 08:21 +0000
SubjectHistogram ignores 'bspec' (bin spec) ??
Message-ID<jqhr60$klr$1@smc.vnet.net>
I would like to plot a histogram with a fixed number of bars, e.g. ten bars.
Consider this code:

SeedRandom [ 1 ] ;
foo = RandomVariate [ NormalDistribution [ 0, 1], 1000 ] ;
baz = Table [ Histogram [ foo, k ], { k, 8, 15 } ] ;
1 == Length [ DeleteDuplicates [ baz ] ]

The last line prints 'True', confirmed by visual inspection of baz which
reveals eight identical histograms, each containing 13 bins. What do I fail
to understand here?

[toc] | [next] | [standalone]


#10349

From"Chris Degnen" <degnen@cwgsy.net>
Date2012-06-05 08:52 +0000
Message-ID<jqkhbk$4kf$1@smc.vnet.net>
In reply to#10347
The bin number specification is approximate, grouping to simple numbers.

The legacy version of Histogram had an option called ApproximateIntervals 
which would control "whether to adjust the interval boundaries to be simple 
numbers".  You can read this in the 'More information' section here:
 http://reference.wolfram.com/mathematica/Histograms/ref/Histogram.html

You can obtain a histogram with exactly 10 bins using the bin width 
specification, dx.

I.e. Histogram[foo, {(Max@foo - Min@foo)/(10 - 1)}]

So your code below would be:

SeedRandom[1];
foo = RandomVariate[NormalDistribution[0, 1], 1000];
{fmin, fmax} = #@foo & /@ {Min, Max};
baz = Table[Histogram[foo, {(fmax - fmin)/(k - 1)}], {k, 8, 15}]
1 == Length[DeleteDuplicates[baz]]



James Stein wrote:
>
> I would like to plot a histogram with a fixed number of bars, e.g. ten 
> bars.
> Consider this code:
>
> SeedRandom [ 1 ] ;
> foo = RandomVariate [ NormalDistribution [ 0, 1], 1000 ] ;
> baz = Table [ Histogram [ foo, k ], { k, 8, 15 } ] ;
> 1 == Length [ DeleteDuplicates [ baz ] ]
>
> The last line prints 'True', confirmed by visual inspection of baz which
> reveals eight identical histograms, each containing 13 bins. What do I 
> fail
> to understand here?
>
> 


[toc] | [prev] | [next] | [standalone]


#10376

FromChris Degnen <degnen@cwgsy.net>
Date2012-06-07 09:22 +0000
Message-ID<jqprs7$2fk$1@smc.vnet.net>
In reply to#10349
On Tuesday, June 5, 2012 9:52:04 AM UTC+1, I wrote:
> ... [So code] would be:
> 
> SeedRandom[1];
> foo = RandomVariate[NormalDistribution[0, 1], 1000];
> {fmin, fmax} = #@foo & /@ {Min, Max};
> ...

{fmin, fmax} = Through[{Min, Max}[foo]]

was what I meant.

[toc] | [prev] | [next] | [standalone]


#10355

From"Nasser M. Abbasi" <nma@12000.org>
Date2012-06-05 08:55 +0000
Message-ID<jqkhhb$4me$1@smc.vnet.net>
In reply to#10347
On 6/4/2012 3:21 AM, James Stein wrote:
> I would like to plot a histogram with a fixed number of bars, e.g. ten bars.
> Consider this code:
>
> SeedRandom [ 1 ] ;
> foo = RandomVariate [ NormalDistribution [ 0, 1], 1000 ] ;
> baz = Table [ Histogram [ foo, k ], { k, 8, 15 } ] ;
> 1 == Length [ DeleteDuplicates [ baz ] ]
>
> The last line prints 'True', confirmed by visual inspection of baz which
> reveals eight identical histograms, each containing 13 bins. What do I fail
> to understand here?
>
>

I am not sure why the same bins show up each time.

But the way I would do this, at least for now, is to
use {dx} and not n for bspec.  This way I know exactly
the bin width I want to use.  Something like this

-----------------------
SeedRandom[1];
foo = RandomVariate[NormalDistribution[0,1],1000];
max = Max[foo];
min = Min[foo];
wid = max-min;
baz = Table[Histogram[foo,{wid/(k-1)},"PDF"],{k,8,15}]
----------------------

I used PDF above just to get the total area =1 that is all.
It is not needed otherwise.

now

1 == Length[DeleteDuplicates[baz]]

gives False. Note that total width of the data is less
than 8 (99.9999% of the time, i.e. 4 standard deviations each
side gives 4. So data goes from -4 to 4 since you
used  NormalDistribution with zero mean and std=1).

Not sure if Mathematica has used '1' for the width of
each bin when using just 'n'.

So 8 bins or more will result in the same
data being binned into only first 8 bins (anything
over 8 bins will have zero elements, hence might not
show in the plot). This might explain why all plots
has 8 bins.

Not sure. But either way, using {dx} seems safer
until some expert here can explain this better.

--Nasser





[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web