Group Abstract Group Abstract

Message Boards Message Boards

Histogram of data with standard deviation at 10^-4

Hello, I am in the process of writing a report and wanting to create a histogram of my records I turned to Mathematica. As it turns out Mathematica has a problem with displaying a normal distribution plot where sigma is small, around 5*10^-4.

diamhisto = Histogram[DataD, {0.009}]
{dbins, dcounts} = HistogramList[DataD, {0.009}]
dcenters = MovingAverage[dbins, 2]
dCurvData = Transpose[{dcenters, dcounts}]
Show[diamhisto, ListPlot[dCurvData], Plot[9*Exp[((\[Minus]18857.1428571)*((x - 23.99916667)^2))], {x, 23.75, 24.25}, PlotStyle -> Red]]

The contents of DataD is imported as follows: {24, 24, 24, 24, 24, 24, 24.01, 24, 23.99, 23.99}

I have been unable to find a reliable way of getting the plot to work.

Attachment

POSTED BY: Jakub Rasała
9 Replies
Posted 2 years ago

The issue is that making a histogram with just 3 unique numbers is just plain silly.

POSTED BY: Jim Baldwin

I tried plotting just the normal curve with mean set to 0. This is what Mathematica came up with. I don't think it's working right.

Attachment

Attachments:
POSTED BY: Jakub Rasała
sig = 5*10^-4;
mn = 162.7;

dat = RandomReal[NormalDistribution[mn, sig], 1000];

Table[
 (*function of normal distribution*)
 fun = PDF[NormalDistribution[u, s]][x];
 mn = Mean[dat];
 std = StandardDeviation[dat];

 {bin, cnt} = HistogramList[dat, {d std}, "PDF"];
 cent = MovingAverage[bin, 2];
 cDat = Transpose[{cent, cnt}];

 (*find fit using the points*)
 sol = fun /. FindFit[cDat, fun, {{u, mn}, {s, std}}, x];

 (*use build in function*)
 dist = PDF[EstimatedDistribution[dat, NormalDistribution[u, s]]][x];

 Show[
  h = Histogram[dat, {(d std)}, "PDF"],
  ListPlot[cDat],
  (*use the range of the histogram for your plot*)
  {min, max} = Options[h, PlotRange][[1, 2, 1]];
  Plot[{sol, dist}, {x, min, max}]
  , ImageSize -> 500]
 , {d, .1, .5, .1}]
POSTED BY: Martijn Froeling

This generates random data with normal distribution, no? I'm looking for a solution with data I aquired during my "study" I'm writing the report on.

POSTED BY: Jakub Rasała
POSTED BY: Martijn Froeling
Posted 2 years ago
DataD // MinMax
(* {162.76, 162.79} *)

which does not match the range in the histogram, one of them is incorrect.

Plot[9*Exp[((-18857.1428571)*((x - 23.99916667)^2))], {x, 23.75, 24.25},
  PlotStyle -> Red,
  PlotRange -> {{23.95, 24.05}, All},
  AspectRatio -> Full]
POSTED BY: Rohit Namjoshi

Oh my, I made a mistake. I was making multiple histograms and I copied over the wrong data. I guess that is what hapens when you make a post late in the evening. I edited it to the right values.

POSTED BY: Jakub Rasała
Posted 2 years ago

With the corrected value for DataD and using the Plot I posted in an earlier answer (which I think is correct)

Show[diamhisto, ListPlot[dCurvData], 
 Plot[9*Exp[((-18857.1428571)*((x - 23.99916667)^2))], {x, 23.75, 24.25},
  PlotStyle -> Red,
  PlotRange -> {{23.95, 24.05}, All},
  AspectRatio -> Full]]

I get this

enter image description here

POSTED BY: Rohit Namjoshi

I am beyond words both in how thankful and disappointed in myself I am. For some reason the PlotRange fixes everything. Thank you so much.

POSTED BY: Jakub Rasała
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard