0
$\begingroup$

I recently inherited some code that does bounds checking from a coworker no longer with the company. It has the following comment

//Currently, we use 3 sigma(standard deviation) as upper bound, where
// sigma = SQRT(mean * (1 - mean) / (sample size)).

And the following implementation is supposed to represent the upper bound to check against

MEAN + 3 * SQRT(MEAN * (1 - MEAN) / COUNT)

Does either the formula or the implementation seem correct? I'm not that familiar with Standard Deviation, but the Wiki article on the topic mentions a much different formula.

$\endgroup$
  • 1
    $\begingroup$ This works if the mean represents a proportion $\endgroup$ – Kamster Feb 6 '15 at 22:20
  • $\begingroup$ Could you go into further detail? $\endgroup$ – Kobaj Feb 6 '15 at 22:22
1
$\begingroup$

An analysis of this would require an undergraduate course in calculus-based probability.

Specifically, let $$\hat{p} = \dfrac{X}{n}$$ where $X$ follows a binomal distribution with the usual parameters $n$ (being the sample size), $p$. In general, if we have a statistic $\hat{\theta}$ which follows a normal distribution, $$\mathbb{E}[\hat{\theta}] \pm z_{\alpha /2} \cdot \sigma_{\hat{\theta}}$$ - where $\mathbb{E}$ is expectation (or mean) - is a $1-\alpha$ confidence interval centered around $\hat{\theta}$ for the parameter $\theta$. The upper bound would be $$\mathbb{E}[\hat{\theta}] + z_{\alpha / 2} \cdot \sigma_{\hat{\theta}}\text{.}$$ Now our task is to show that:

1) $\hat{p}$ follows a normal distribution

2) $\sigma_{\hat{p}} = \sqrt{\dfrac{\mathbb{E}[\hat{p}]\left(1-\mathbb{E}[\hat{p}]\right)}{n}}$

In the elementary statistics courses I was a teaching assistant in, 1) is usually tested by making sure that $$np(1-p) \geq 10\text{.}$$ Assuming 1) is satisfied, we have $$\begin{align} &\mathbb{E}[\hat{p}] = \dfrac{\mathbb{E}[X]}{n} = \dfrac{np}{n} = p \\ &\text{Var}[\hat{p}] = \dfrac{\text{Var}[X]}{n^2} = \dfrac{np(1-p)}{n^2} = \dfrac{n\cdot \mathbb{E}[\hat{p}](1-\mathbb{E}[\hat{p}])}{n^2} = \dfrac{\mathbb{E}[\hat{p}](1-\mathbb{E}[\hat{p}])}{n}\text{,}\end{align}$$ or, $$\sigma_{\hat{p}} = \sqrt{\text{Var}[\hat{p}]} = \sqrt{\dfrac{\mathbb{E}[\hat{p}](1-\mathbb{E}[\hat{p}])}{n}}$$ so that our upper bound is $$\mathbb{E}[\hat{p}] + z_{\alpha/2}\sqrt{\dfrac{\mathbb{E}[\hat{p}](1-\mathbb{E}[\hat{p}])}{n}}\text{.}$$ Take the above formula, and set $z_{\alpha/2} = 3$.

ETA: If I have time, I will try to write a more intuitive explanation.

$\endgroup$
0
$\begingroup$

I'll just explain the topic in a little bit more depth than needed but just so you understand fully.

First off for independent random variables, $X_1,...,X_n$ that are from same distribution (you can think of this as sample of data) where $\mu_X=E(X_i)$ and $Var(X_i)=\sigma_X^2$. Now, for the arithmetic average/mean $\overline{X}=\frac{1}{n}\sum_{i=1}^{n}X_i$. Now, one important theorem you should know is the Centeral Limit Theorem (CLT) (this says that sum of iid random variables has an approximate normal distribution for large $n$ ie sample size). Thus CLT asserts that $\overline{X}$ has a normal distribution where $\mu=\mu_X$ and $\sigma^2=\frac{\sigma_X^2}{n}$.

Now, I think the notion of upper bound that you are using is a little misleading. The bound you are using is a the upper bound of a 99% confidence interval (which should not be interpreted as an upper bound for $\overline{X}$. This bound is $$\mu+3\sigma=\mu_X+3\frac{\sigma_X}{\sqrt{n}}$$

Now this is were your problem lies. $\frac{\sigma_X}{\sqrt{n}}\approx \sqrt{\frac{(1-\overline{X})\overline{X}}{n}}$ is only true when $\overline{X}$ represents a proportion (this standard deviation for a Bernoulli random variable

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.