2

Is there a simple way to do this by hand?

I mostly want to do this for quick "straight face" testing to see if something works, so ideally I want (for example) a sequence with mean 1 and variance 2 with as many 0's as possible (for ease of calculation).

Is there an easy way of doing this?

soandos
  • 1,756
  • Is the given mean and variance the mean and variance of the distribution from which the values are drawn or simply the sample values? – Glen_b May 12 '14 at 04:06
  • Note that "as many 0's as possible" may not actually maximize ease of calculation (assuming you mean 'by hand', at least). If making the most 0's possible involves having a few really weird values, it might be better to have slightly fewer values but rounder numbers. What sample size were you looking for - is this prespecified or do you want to be able to take more values as you need them? "A sequence" might be any length - can I just give you three values and say "that's a sequence of values"? – Glen_b May 12 '14 at 04:19
  • @Glen_b the generated sequence can be any distribution. I hear your point about the 0's, but I'm sure what else to look for. The mean and variance are for the sequence – soandos May 12 '14 at 06:15
  • soandos - please note that there was a typographical error in the example (now corrected) where I typed a=1 (it's meant to be 3). All later values were based on the correct values of a=3. – Glen_b May 12 '14 at 08:41
  • @Glen_b, I figured it out, but thanks – soandos May 12 '14 at 09:02

1 Answers1

1

If the "as many 0's as possible" isn't an absolute requirement but more something to aim toward, consider a very simple sequence of $0$'s and $a$'s.

If you had an infinite random sequence of 0's and 1's and the proportion of 1's was $p$, then the mean would be $p$ and the variance would be $p(1-p)$.

If the sequence was multiplied by $a$ (i.e. consisted of $0$'s and $a$'s), then the mean would be $ap$ and the variance $a^2p(1-p)$.

Consequently to achieve mean $\mu$ and variance $\sigma^2$, note that the square of the coefficient of variation, $\sigma^2/\mu^2 = \frac{a^2p(1-p)}{a^2p^2}=(1-p)/p$.

Consequently $p = 1/(1+\sigma^2/\mu^2)$.

Once $p$ is known, you have $a=\mu/p$.

So in your example, $\sigma^2 = 2$ and $\mu=1$, whence $p = 1/3$ and $a=3$.

That is an infinite sequence of 0's and 3's where 2/3 of the values are 0 and 1/3 of the values are 3 has mean 1 and variance $9\cdot \frac{2}{3}\cdot\frac{1}{3} = 2$.

(If you have a finite sequence, note the distinction between the sample variance with Bessel's correction and the population variance. That aside, the basic principle is the same.)

This may not be the highest possible proportion of 0's, but it's pretty high, and is relatively easy to solve for.

Glen_b
  • 2,273