Making a histogram out of values from a table

208 views Asked by At

I have defined a Mixed distribution made out of two Normal Distributions, like this

MixDist[s_,n_]:=With[{Dist=MixtureDistribution[{.5,.5},{NormalDistribution[0,s],Normaldistribution[0.5s,s]}]},RandomVariate[Dist,n]]

For example, MixDist[1,1000] should generate 1000 numbers distributed with a mixed distribution made out of NormalDistribution1[0,1] and NormalDistribution2[0.5,1]. Now, I want to run this generator 100 times, and this is where I am stuck.

I tried doing this

dist1=Table[MixDist[1,1000],100]

to generate a table with 100 sets of 1000 random numbers, but when trying to plot a histogram with

histogram=Histogram[dist1,20,"ProbabilityDensity"]

it shows a blank coordinate system.

Can data from a table be included in a histogram? Or is there another way to do this (make a histogram of 100 sets of 1000 randomly generated numbers from the mixed distribution mentioned above).

Thank you!

1

There are 1 answers

0
Alexander Kazantsev On BEST ANSWER

Short answer

mixDist[s_, n_] := With[{
   dist = MixtureDistribution[
     {.5, .5},
     {NormalDistribution[0, s], NormalDistribution[0.5 s, s]}
     ]
   },
  
  RandomVariate[dist, n]
  ]
dist1 = Table[mixDist[1, 1000], 100];
histogram = Histogram[dist1, 20, "ProbabilityDensity"]

Details

  • The only mistake was that the second NormalDistribution was written as Normaldistribution
  • Improved code style. I am convinced that user-defined variables should start with a lowercase letter to be distinguishable from the system ones.