# Obtain Plot for Continuous Probability Density Function Approximation from Discrete Data

Observe the following code:

p = 0.5; n = 10^2;
XbarObservationSet = Mean[RandomVariate[GeometricDistribution[p], {n, n}]]
myplot1 = ?????
myplot2 = Plot[PDF[NormalDistribution[0, 1], x], {x, -3, 3}]
Show[myplot1, myplot2]


Suppose my goal is to take all of the data collected in XbarObservationSet and display an approximated, continuous probability density function corresponding to the observed data and then compare it to a typical normal distribution. In other words, I want to see the continuous PDF approximation of the 100 instances of the estimator Xbar that I have collected. How can I do this? How would I define myplot1?

• Would you elaborate as to why you use {n, n} rather than something like {n, 100n}? With just 100 simulations of the mean of 100 samples you're not going to get a very good estimate (let alone a good estimate from a secondary continuous approximation). With a much larger sample size (say '100 n = 10,000) then all 3 of the answers below will work fine and you'll see that the distribution of the mean of 100 samples is approximately normal (i.e., the Central Limit Theorem kicks in).
– JimB
Feb 17, 2018 at 5:17

p = 1/2; n = 10^2;
SeedRandom;
ObservationSet = RandomVariate[GeometricDistribution[p], {n, n}];
XbarObservationSet =
Mean[RandomVariate[GeometricDistribution[p], {n, n}]];


To find the NormalDistribution that best fits the data use EstimatedDistribution

dist = EstimatedDistribution[XbarObservationSet,
NormalDistribution[m, s]]

(* NormalDistribution[0.9936, 0.132087] *)

Show[
Histogram[XbarObservationSet, 10, "PDF"],
Plot[PDF[dist, x], {x, Min[XbarObservationSet],
Max[XbarObservationSet]}]] Show[Histogram[XbarObservationSet, 20],
Plot[PDF[
NormalDistribution[Mean[XbarObservationSet],
StandardDeviation[XbarObservationSet]], x], {x, 0, 1.5}]] (I don't know why you expect your sample would be well fit by a Gaussian centered on $0$.)

• To have Histogram match the PDF in the plot you should use Histogram[XbarObservationSet, 20, "PDF"]. Otherwise the vertical axis for Histogram is counts and probability density for the Plot.
– JimB
Feb 17, 2018 at 5:06

You can use SmoothKernelDistribution for that

p = 0.5; n = 10^2;
XbarObservationSet =
Mean[RandomVariate[GeometricDistribution[p], {n, n}]];

Plot[{PDF[SmoothKernelDistribution[XbarObservationSet], x],
PDF[NormalDistribution[0, 1], x]}, {x, -3, 3}, PlotRange -> All] Although I'm not sure if you rather would like to see something like this:

Plot[{PDF[SmoothKernelDistribution[XbarObservationSet], x],
PDF[NormalDistribution[Mean[XbarObservationSet],
StandardDeviation[XbarObservationSet]], x]}, {x, 0, 2},
PlotRange -> All]
` 