# Using NSolve on an equation that involves Mean and TruncatedDistribution

What I would like to do is create a mixture distribution that has a specified mean by varying one parameter in the distribution. To do this I've written the following code;

dist := MixtureDistribution[{0.1,0.9}, {UniformDistribution[{39.3, 40.5}],
TruncatedDistribution[{40.5, 104}, NormalDistribution[a, 11.4]]}]

NSolve[Mean[dist] == 82.63344, a]


Which just returns a "PolynomialGCD::lrgexp" error.

What I ended up doing is putting values in using trial and error until it gave me the correct mean (so it does have a solution). Is there any way so solve this equation without resorting to trial and error?

I think the TruncatedDistribution / Mean combination is what is causing problems. When I remove the TruncatedDistribution NSolve quickly returns a solution. The following link discussed this issue;

Calculating the Mean of a Truncated Multinormal Distribution

When I replaced

 NSolve[Mean[dist] == 82.63344, a]


With

NSolve[NExpectation[x, x \[Distributed] dist2] == 82.63344, a]


All I got was an execution that seemed to go forever (I aborted after 10 mins).

Any advice on how to solve this equation efficiently would be greatly appreciated.

-
FindRoot seems to work fine. FindRoot[Mean[dist] == 82.63344, {a, 1}] – Andy Ross Jan 9 '13 at 23:41

The mean of a mixture of distributions is the mixture of their means, so simplify your life--and greatly speed up Mathematica--by precomputing the means of the mixture components separately:

d1 = Mean[UniformDistribution[{39.3, 40.5}]];
d2[a_] := Evaluate @ Mean[TruncatedDistribution[{40.5, 104}, NormalDistribution[a, 11.4]]]


A rough guess for the solution a is that it is close to the target mean. Use this as the initial value in FindRoot:

With[{target = 82.63344}, FindRoot[0.1 d1 + 0.9 d2[a] == target, {a, target}]]


$\{a\to 89.6922\}$

If you wish to check--to confirm my initial assertion about the mean of a mixture (in case I was wrong!)--go right ahead:

Mean[MixtureDistribution[{0.1, 0.9},
{UniformDistribution[{39.3, 40.5}],
TruncatedDistribution[{40.5, 104}, NormalDistribution[a, 11.4]]}
] /. %]


$82.6334$

-
Thanks whuber. Great answer. – Cam Jan 10 '13 at 22:06