Below in code are two versions. I believe plot1 might be correct but not sure why its shifted to the left and how to fix it. plot2 is copied directly from the wolfman online documentation but using my own data. It doesn't look normalized and the continuous curve is almost flat. I know something is likely wrong with both of them. Please suggest edits.
Goal is to normalize histogram of probability density so that we have a mean at zero, standard deviation is 1, and total area under graph is 1. The graph should look similar to image:
raw = {1.32, 1.37, 1.43, 1.32, 1.36, 1.33, 1.38, 1.35, 1.48, 1.28,
1.31, 1.52, 1.51, 1.33, 1.32, 1.27, 1.35, 1.40, 1.27, 1.39, 1.50,
1.31, 1.34, 1.48, 1.36, 1.33, 1.40, 1.29, 1.35, 1.36, 1.33, 1.30,
1.28, 1.32, 1.34, 1.33, 1.29, 1.34, 1.34, 1.29, 1.35, 1.52, 1.29,
1.38, 1.40, 1.28, 1.36, 1.36, 1.32, 1.62, 1.36, 1.34, 1.33, 1.33,
1.30, 1.31, 1.33, 1.32, 1.36, 1.41};
(* plot1 almost looks correct except for shifting from mean *)
plotHistPDF[raw_, n_ : 3] :=
Block[{len, μ, σ, bin, hist, dist},
len = Length[raw];
μ = Mean[raw];
σ = StandardDeviation[raw];
hist = Histogram[raw, Automatic, "PDF"];
dist = Plot[
PDF[NormalDistribution[μ, σ], x], {x, μ - n σ, μ + n σ},
PlotRange -> All, Filling -> Axis];
Show[
hist, dist,
PlotLabel -> Style["Probabality Density Distribution", Bold, Orange],
AxesLabel -> {x, ρ}, ImageSize -> imgsize]
]
(* plot2 appears correctly placed but curve is flat. should be a bell shaped curve *)
Show[
Histogram[raw, Automatic, "PDF"],
Plot[PDF[NormalDistribution[0, 1], x], {x, -4, 4}]
]
NormalDistribution[0,1]
toNormalDistribution[Mean[raw], StandardDeviation[raw]]
and{x, -4, 4}
to{x, 1.2, 1.7}
. If that fixes things, then don't be surprised if this question is closed as I don't see it helping anyone in the future. $\endgroup$PlotRange->All
toShow
. The second one is apparently caused by the fact that your raw data isn't normal, with its mode a bit to the left of its mean. $\endgroup$