Docsity

Estimating Proportions and Expectations of Random Variables: The Law of Large Numbers, Study notes of Discrete Structures and Graph Theory

Toggle sidebar
bg1
I.I.D. Random Variables
Estimating the bias of a coin
Question: We want to estimate the proportion pof Democrats in the US population, by taking a small
random sample. How large does our sample have to be to guarantee that our estimate will be within (say)
10% (in relative terms) of the true value with probability at least 0.95?
This is perhaps the most basic statistical estimation problem, and shows up everywhere. We will develop
a simple solution that uses only Chebyshev’s inequality. More refined methods can be used to get sharper
results.
Let’s denote the size of our sample by n(to be determined), and the number of Democrats in it by the
random variable Sn. (The subscript njust reminds us that the r.v. depends on the size of the sample.) Then
our estimate will be the value An=1
nSn.
Now as has often been the case, we will find it helpful to write Sn=X1+X2+···+Xn, where Xi=
(1 if person iin sample is a Democrat;
0 otherwise.
Note that each Xican be viewed as a coin toss, with Heads probability p(though of course we do not know
the value of p: this is what we’re trying to estimate!). And the coin tosses are independent.1
What is the expectation of our estimate?
E(An) = E(1
nSn) = 1
nE(X1+X2+···+Xn) = 1
n×(np) = p.
So for any value of n, our estimate will always have the correct expectation p. [Such a r.v. is often called an
unbiased estimator of p.] Now presumably, as we increase our sample size n, our estimate should get more
and more accurate. This will show up in the fact that the variance decreases with n: i.e., as nincreases, the
probability that we are far from the mean pwill get smaller.
To see this, we need to compute Var(An). And since An=1
n∑n
i=1Xi, we need to figure out how to compute
the variance of a sum of random variables.
Theorem 20.1:For any random variable X and constant c, we have
Var(cX) = c2Var(X).
And for independent random variables X,Y, we have
Var(X+Y) = Var(X) + Var(Y).
1We are assuming here that the sampling is done “with replacement”; i.e., we select each person in the sample from the entire
population, including those we have already picked. So there is a small chance that we will pick the same person twice.
CS 70, Fall 2004, Lecture 20 1
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Estimating Proportions and Expectations of Random Variables: The Law of Large Numbers and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

I.I.D. Random Variables

Estimating the bias of a coin

Question: We want to estimate the proportion p of Democrats in the US population, by taking a small random sample. How large does our sample have to be to guarantee that our estimate will be within (say) 10% (in relative terms) of the true value with probability at least 0.95?

This is perhaps the most basic statistical estimation problem, and shows up everywhere. We will develop a simple solution that uses only Chebyshev’s inequality. More refined methods can be used to get sharper results.

Let’s denote the size of our sample by n (to be determined), and the number of Democrats in it by the random variable Sn. (The subscript n just reminds us that the r.v. depends on the size of the sample.) Then our estimate will be the value An = (^1) n Sn.

Now as has often been the case, we will find it helpful to write{ Sn = X 1 + X 2 + · · · + Xn , where Xi =

1 if person i in sample is a Democrat; 0 otherwise. Note that each Xi can be viewed as a coin toss, with Heads probability p (though of course we do not know the value of p : this is what we’re trying to estimate!). And the coin tosses are independent.^1

What is the expectation of our estimate?

E( An ) = E( (^1) n Sn ) = (^1) n E( X 1 + X 2 + · · · + Xn ) = (^1) n × ( np ) = p.

So for any value of n , our estimate will always have the correct expectation p. [Such a r.v. is often called an unbiased estimator of p .] Now presumably, as we increase our sample size n , our estimate should get more and more accurate. This will show up in the fact that the variance decreases with n : i.e., as n increases, the probability that we are far from the mean p will get smaller.

To see this, we need to compute Var( An ). And since An = (^1) n ∑ ni = 1 Xi , we need to figure out how to compute the variance of a sum of random variables.

Theorem 20.1 : For any random variable X and constant c, we have

Var( cX ) = c^2 Var( X ).

And for independent random variables X , Y , we have

Var( X + Y ) = Var( X ) + Var( Y ).

(^1) We are assuming here that the sampling is done “with replacement”; i.e., we select each person in the sample from the entire population, including those we have already picked. So there is a small chance that we will pick the same person twice.

CS 70, Fall 2004, Lecture 20 1

Proof : From the definition of variance, we have

Var( cX ) = E(( cX − E( cX ))^2 ) = E(( cX − c E( X ))^2 ) = E( c^2 ( X − E( X ))^2 ) = c^2 Var( X ).

The proof of the second claim is left as an exercise. Note that the second claim does not in general hold unless X and Y are independent. 2

Using Theorem 23.1, we can now compute Var( An ):

Var( An ) = Var( (^1) n

n

i = 1

Xi ) = ( (^1) n )^2 Var(

n

i = 1

Xi ) = ( (^1) n )^2

n

i = 1

Var( Xi ) =

σ 2 n

where we have written σ 2 for the variance of each of the Xi. So we see that the variance of An decreases linearly with n. This fact ensures that, as we take larger and larger sample sizes n , the probability that we deviate much from the expectation p gets smaller and smaller.

Let’s now use Chebyshev’s inequality to figure out how large n has to be to ensure a specified accuracy in our estimate of the proportion of Democrats p. A natural way to measure this is for us to specify two parameters, ε and δ , both in the range ( 0 , 1 ). The parameter ε controls the error we are prepared to tolerate in our estimate, and δ controls the confidence we want to have in our estimate. A more precise version of our original question is then the following:

Question: For the Democrat-estimation problem above, how large does the sample size n have to be in order to ensure that Pr[| An − p | ≥ ε p ] ≤ δ?

In our original question, we had ε = 0 .1 and δ = 0 .05. Notice that ε measures the relative error, i.e., the error as a ratio of the target value p. This seems like a more reasonable convention than the absolute error (based on Pr[| An − p | ≥ ε]). This is because a given absolute error (say, ± 0 .1) might be quite small in the context of measuring a large value like p = 0 .5, but very large when measuring a small value like p = 0 .05. In contrast, the relative error treats all values of p equally.

Let’s apply Chebyshev’s inequality to answer our more precise question above. Since we know Var( An ), this will be quite simple. From Chebyshev’s inequality, we have

Pr[| An − p | ≥ ε p ] ≤ Var( An ) ( ε p )^2

σ 2 np^2 ε^2

To make this less than the desired value δ , we need to set

n ≥ σ 2 p^2

×

ε^2 δ

Now recall that σ 2 = Var( Xi ) is the variance of a single sample Xi. So, since Xi is a 0/1-valued r.v., we have σ 2 = p ( 1 − p ), and inequality (1) becomes

n ≥

1 − p p

×

ε^2 δ

Plugging in ε = 0 .1 and δ = 0 .05, we see that a sample size of n = 2000 × 1 − p p is sufficient.

At this point you should be worried. Why? Because our formula for the sample size contains p , and this is precisely the quantity we are trying to estimate! But we can get around this as follows. We just pick a value p ′^ that we know for sure is less than p. (For example, in the Democrats problem we could certainly take p ′^ = 13 .) Then we use p ′^ in place of p in equation (2). Since p ′^ is less than p , this will always lead us to take at least enough samples (why?). In the Democrats example, with p ′^ = 13 , this means we would take a sample size of n = 2000 × 2 = 4000.

CS 70, Fall 2004, Lecture 20 2

We will not prove this theorem here. Notice that it says that the probability of any deviation α from the mean, however small, tends to zero as the number of observations n in our average tends to infinity. Thus by taking n large enough, we can make the probability of any given deviation as small as we like. [Note, however, that the Law of Large Numbers does not say anything about how large n has to be to achieve a certain accuracy. For that, we need Chebyshev’s inequality or some other quantitative tool.]

Actually we can say something much stronger than the Law of Large Numbers: namely, the distribution of the sample average An , for large enough n , looks like a bell-shaped curve centered about the mean μ. The width of this curve decreases with n , so it approaches a sharp spike at μ. This fact is known as the Central Limit Theorem.

To say this precisely, we need to define the “bell-shaped curve.” This is the so-called Normal distribution, and it is the first (and only) non-discrete distribution we will meet in this course. For random variables that take on continuous real values, it no longer makes sense to talk about Pr[ X = a ]. As an example, consider a r.v. X that has the uniform distribution on the continuous interval [ 0 , 1 ]. Then for any single point 0 ≤ a ≤ 1, we have Pr[ X = a ] = 0. However, clearly it is the case that, for example, Pr[ 14 ≤ X ≤ 34 ] = 12. So in place of point probabilities Pr[ X = a ], we need a different notion of “distribution” for continuous random variables.

Definition 20.1 (density function) : For a real-valued r.v. X , a real-valued function f ( x ) is called a (probability) density function for X if

Pr[ X ≤ a ] =

∫ (^) a

−∞

f ( x ) dx.

Thus we can think of f ( x ) as defining a curve, such that the area under the curve between points x = a and x = b is precisely Pr[ a ≤ X ≤ b ]. Note that we must always have

∫ (^) ∞ −∞ f^ ( x ) dx^ =^ 1. (Why?) As an example, for the uniform distribution on [ 0 , 1 ] the density would be

f ( x ) =

0 for x < 0; 1 for 0 ≤ x ≤ 1; 0 for x > 1.

[Check you agree with this. What would be the density for the uniform distribution on [− 1 , 1 ]?]

Expectations of continuous r.v.’s are computed in an analagous way to those for discrete r.v.’s. Thus

E( X ) =

∫ (^) ∞

−∞

x f ( x ) dx.

And also Var( X ) = E( X^2 ) − (E( X ))^2 , where E( X^2 ) =

∫ (^) ∞ −∞ x (^2) f ( x ) dx.

[You should check that, for the uniform distribution on [ 0 , 1 ], the expectation is 12 and the variance is 121 .]

Now we are in a position to define the Normal distribution.

Definition 20.2 (Normal distribution) : The Normal distribution with mean μ and variance σ 2 is the dis- tribution with density function

f ( x ) =

σ

2 π

e−( x −^ μ)

(^2) / 2 σ 2 .

CS 70, Fall 2004, Lecture 20 4

[The reason for the constant factor (^) σ √^12 π is that this is the value of the integral of the exponential function

e−( x −^ μ) (^2) / σ 2

. So we have to normalize by this value to get

∫ (^) ∞ −∞ f^ ( x ) dx^ =^ 1. If you enjoy calculus, you might like to do the integrals to check that the expectation

∫ x f ( x ) dx is indeed μ and that the variance is indeed σ 2 .]

If you plot the above density function f ( x ), you will see that it is a symmetrical bell-shaped curve centered around the mean μ. Its height at the mean is about 0.4, and its width is determined by the variance σ 2 , as follows: 50% of the mass is contained in the interval of width 0. 67 σ either side of the mean, and 99.7% in the interval of width 3 σ either side of the mean. (Note that, to get the correct scale, deviations are on the order of σ rather than σ 2 .)

Now we are in a position to state the Central Limit Theorem. Because our treatment of continuous distri- butions has been rather sketchy, we shall be content with a rather imprecise statement. This can be made completely rigorous without too much extra effort.

Theorem 20.3 : [Central Limit Theorem] Let X 1 , X 2 ,... , Xn be i.i.d. random variables with common expectation μ = E( Xi ) and variance σ 2 = Var( Xi ) (both assumed to be < ∞ ). Define An = (^1) n ∑ ni = 1 Xi. Then

as n → ∞ , the distribution of An approaches the Normal distribution with mean μ and variance^ σ^ 2 n.

Note that the variance is^ σ^ 2 n (as we would expect) so the width of the bell-shaped curve decreases by a factor of

n as n increases.

The Central Limit Theorem is actually a very striking fact. What it says is the following. If we take an average of n observations of any r.v. X , then the distribution of that average will be a bell-shaped curve centered at μ = E( X ). Thus all trace of the distribution of X disappears as n gets large: all distributions, no matter how complex,^2 look like the Normal distribution when they are averaged. The only effect of the original distribution is through the variance σ 2 , which determines the width of the curve for a given value of n , and hence the rate at which the curve shrinks to a spike.

In class, we saw how the distribution of An behaves for increasing values of n , when the Xi have the geometric distribution with parameter 16. As an exercise, try doing the same thing for several different r.v.’s Xi , all of which have the same mean but very different distributions. You should observe the appearance of the bell- shaped curve in all cases (with a width determined by the variance of the particular Xi ).

(^2) Strictly speaking, we do need to assume that the mean and variance of X are finite.

CS 70, Fall 2004, Lecture 20 5