Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10355
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Histogram ignores 'bspec' (bin spec) ?? |
| Date | 2012-06-05 08:55 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jqkhhb$4me$1@smc.vnet.net> (permalink) |
| References | <jqhr60$klr$1@smc.vnet.net> |
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
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web