# Statistical parameters from distribution function

I have a number of distributions that I am adding to result in one summarized distribution, e.g.:

distSum={0.167467 E^(-(1/2) (-21.5 + x)^2), 0.160772 E^(-(1/2) (-19.7 + x)^2),
0.233762 E^(-(1/2) (-21.7 + x)^2),
0.0930353 E^(-(1/2) (-21.9 + x)^2),
0.373293 E^(-(1/2) (-22.4 + x)^2), 0.126876 E^(-(1/2) (-19. + x)^2),
0.348056 E^(-(1/2) (-22.7 + x)^2), 0.393082 E^(-(1/2) (-21.4 + x)^2),
0.35867 E^(-(1/2) (-20.9 + x)^2), 0.383496 E^(-(1/2) (-22.3 + x)^2)}


Now I would like to have some information and lists from the single distSum. E.g., what is the Mean/Median/etc of distSum? Also, I'd like to extract a sample from distSum, but I can't simply use RandomSample on distSum. I know how to apply these statistical parameters on lists, but as this is a function, and not a list, I don't know how to get these parameters.

• ...so a bunch of Gaussians? Commented Aug 5, 2016 at 16:36
• In this case yes, but is just an example. Could also be others. Commented Aug 5, 2016 at 16:38
• @Karsten7. No – but I just tried NExpectation, as I think that's what you were referring to. No result. If I could get a list from distSum, then I could basically apply what I need. But I don't know, how to transfer this distribution function in a list that would basically produce the same histogram as the function. Commented Aug 5, 2016 at 16:50
• None of these functions are probability distributions as none of them integrate to 1 and the integral of the sum isn't 1 either. So why do you call them distributions?
– JimB
Commented Aug 5, 2016 at 17:10
• Rather than asking for more precise statistical terms, I'd say we're really asking for more or clarifying information so that we can understand the question better and provide you with an appropriate answer.
– JimB
Commented Aug 6, 2016 at 5:11

You can define a MixtureDistribution thus

Integrate[distSum, {x, -∞, ∞}] // Chop
Integrate[x distSum, {x, -∞, ∞}] // Chop
means = %/%%
weights = %%%/Total[%%%]
dist = MixtureDistribution[weights, NormalDistribution[#, 1] & /@ means]


and apply most of the statistical functions to it

Through[{Mean, Variance, Median, RandomReal}[dist]]
(* {21.6074, 1.94362, 21.7081, 21.8625} *)


Here is how you can apply the same principles used in this answer to your problem:

distSum = {0.167467 E^(-(1/2) (-21.5 + x)^2), 0.160772 E^(-(1/2) (-19.7 + x)^2),
0.233762 E^(-(1/2) (-21.7 + x)^2), 0.0930353 E^(-(1/2) (-21.9 + x)^2),
0.373293 E^(-(1/2) (-22.4 + x)^2), 0.126876 E^(-(1/2) (-19. + x)^2),
0.348056 E^(-(1/2) (-22.7 + x)^2), 0.393082 E^(-(1/2) (-21.4 + x)^2),
0.35867 E^(-(1/2) (-20.9 + x)^2), 0.383496 E^(-(1/2) (-22.3 + x)^2)};

dist = ProbabilityDistribution[
Plus @@ distSum, {x, -Infinity, Infinity}, Method -> "Normalize"];

mean = NExpectation[x, x \[Distributed] dist]


$\$ 21.6074

variance = Expectation[(x - mean)^2, x \[Distributed] dist] // Chop


$\$ 1.94362

Plot[PDF[dist, x], {x, 12, 30}, PlotRange -> All]


RandomVariate[dist, 10]


$\$ {20.7231, 21.2831, 20.6987, 22.486, 22.7043, 25.5388, 21.5406, 21.9175, 20.5078, 21.9182}

• I see, thanks, Karsten. Commented Aug 6, 2016 at 5:35