# How to solve the approximate value of this probability problem

It is known that X1, X2,...,Xn are random samples from the population X, where the probability of X taking 0 or 1 is equal, that is, $$P(X=0)=P(X=1)=\frac{1}{2}$$.

I want to find an approximation of $$P\left(\sum_{i=1}^{100} X_{i} \leq 55\right)$$ by means of the central limit theorem.

I use the following code to calculate this problem, but MMA keeps running and can't get the result:

NProbability[Sum[x[i], {i, 1, 100}] <= 55,
Table[x[i] \[Distributed]
EmpiricalDistribution[{0.5, 0.5} -> {0, 1.}], {i, 1, 100}]]


Is there any way to quickly find the approximate value of this problem?

Supplementary mathematical analysis process:

$$E\left(\sum_{i=1}^{100} X_{i}\right) X=100 E X=50 . \quad D\left(\sum_{i=1}^{100} X_{i}\right)=100 D X=25$$

\begin{aligned} &\text { According to the central limit theorem } \sum_{i=1}^{100} X_{i} \sim N(50,25)\\ &\therefore P\left\{\sum_{i=1}^{100} X_{i} \leq 55\right\}=P\left\{\frac{\sum_{i=1}^{100} X_{i}-55}{5} \leq \frac{55-50}{5}\right\}=\Phi(1) \end{aligned}

Count[Table[Total[RandomChoice[{0.5, 0.5} -> {0, 1}, 100]], 100000],
u_ /; u <= 55]/100000.
(*0.8655*)
Erf[1.]
(*0.84270079295*)

• This is basically like modelling the number of heads in a sequence of coin flips. It's a BinomialDistribution[100,1/2] and you're counting the number of successful trials: Probability[x <= 55, x \[Distributed] BinomialDistribution[100, 1/2]] which gives precisely 68482723177360620218041365161 / 79228162514264337593543950336 or roughly 0.864373 . If you want to demonstrate convergence to the normal distribution, then N@Probability[x <= 55 + .5, x \[Distributed] NormalDistribution[50, 5]] - the .5 is a correction, and stddev of binomial is Sqrt[n (1 - p) p] and mean is np for n=100,p=1/2 – flinty Aug 3 at 1:01
• @flinty If I change the title to read: NProbability[Sum[x[i], {i, 1, 100}] <= 55, Table[x[i] \[Distributed] EmpiricalDistribution[{0.25, 0.5, 0.25} -> {0, 1., 2.}], {i, 1, 100}]], what should you do? – A little mouse on the pampas Aug 3 at 1:05
• NProbability[Total[Array[x, 100]] <= 55, # \[Distributed] dist & /@ Array[x, 100]] will not complete for 100, but at that level I would just assume an almost-normal distribution anyway and use the limiting distribution: distapprox=NormalDistribution[Mean[dist]*100,StandardDeviation[dist]*Sqrt] then Probability[x<=55+0.5,x \[Distributed] distapprox]] which gives 1.55443*10^-10 - and that low probability makes sense because Total@RandomVariate[dist, 100] is normally very close to 100. – flinty Aug 3 at 1:19
• You can also do d2 = TransformedDistribution[ Total[Array[x, 100]], # \[Distributed] dist & /@ Array[x, 100]]; and get mu = Mean[d2] and sd = StandardDeviation[d2] then just plug mu*100 and sd*Sqrt into NormalDistribution later. – flinty Aug 3 at 1:21
• Yeah that will never work - don't use NProbability with a sum this big because it's like doing very high dimensional intergration - use the normal distribution approximation instead. – flinty Aug 3 at 1:36

Given a discrete distribution $$D$$ of finite variance, you only need the mean and standard deviation to apply the central limit theorem here:

dist = BinomialDistribution[100,1/2]
mu = Mean[dist];
sd = StandardDeviation[dist];

nclt = NormalDistribution[mu, sd];


It is important to apply a continuity correction, since we've gone from a discrete to continuous distribution, which is why I add 0.5 below:

Probability[x <= 55 + 0.5, x \[Distributed] nclt]
(* 0.864334 *)

Probability[x <= 55, x \[Distributed] BinomialDistribution[100, 1/2]]
(* 68482723177360620218041365161 / 79228162514264337593543950336 *)
(* approx 0.864373 *)


You can apply this reasoning for other distributions, but you must remember to scale the mean by a factor of $$n$$ and the standard deviation by a factor of $$\sqrt{n}$$:

dist2 = EmpiricalDistribution[{0.25, 0.5, 0.25} -> {0, 1, 2}];
mu2 = Mean[dist2];
sd2 = StandardDeviation[dist2];

nclt2 = NormalDistribution[mu2 * 100, sd2 * Sqrt];
Probability[x <= 55 + 0.5, x \[Distributed] nclt2]
(* 1.55443*10^-10 *)


I wonder if you went to the wrong solution because you used an inefficient approach to calculate the sum. Either of the following work almost instantaneously:

AbsoluteTiming[Sum[PDF[BinomialDistribution[100, 1/2], x], {x, 0, 55}]]
(* {0.0065887, 68482723177360620218041365161/79228162514264337593543950336} *)

AbsoluteTiming[CDF[BinomialDistribution[100, 1/2], 55]
(* {0.0001947, 68482723177360620218041365161/79228162514264337593543950336} *)


Direct method to do what the OP was trying to do, but faster:

NProbability[
Total[Array[x, 100]] <= 55,
Array[x, 100] \[Distributed] ProductDistribution[{BernoulliDistribution[1/2], 100}]
]


0.864673

This is still not a very scaleable method, though.