ST 321                                   Expectation and Variance                    March 12, 2004

 

Estimating E(X):

In one of the previous classes we discussed that one way to estimate the expectation E(X) of a random variable X is to first generate a large number of X’s and then estimate E(X) by their mean. The following R/Splus command can be used to estimate E(X) if X is an exponential random variable with rate 0.1:

 

> mean(rexp(10000, 0.1))

 

Run the above R/Splus command and compare the result to the true E(X)=10.

 

Expectation of a function of a random variable E{g(x)}:

The expected value of a function g of a discrete random variable X with probability density function p(x) is the sum of g(x)*p(x) over all possible values of x, provided this sum converges absolutely.  Similarly, the expected value of a function g of a continuous random variable X with probability density function f(x) is the integral of g(x)*f(x) over all possible values of x, provided this integral exists. In either case, the expected value can be approximated by the sample mean of n independent simulated values of g(X). This result is a version of the Law of Large Numbers.

 

Task 1.

(a). Estimate the expectation of 3+2*X where X is exponential with rate 2.  Does E(3+2*X)=3+2*E(X)?

(b). Estimate the expected value of |Z| where Z is standard normal. Does E(|Z|)=|E(Z)|?

(c). Estimate the expected value of Y^2 where Y is Poisson(3). Does E(Y^2)={E(Y)}^2?

(d). Estimate the expected value of 1/Z, where Z is standard normal.

 

Variance of a random variable X, Var(X)=E{X-E(X)}^2:

One function of a random variable of particular interest is g(X)={X-E(X)}^2.  The expectation of g(X) is called the variance of X, often denoted Var(X). If E(X) is known, the method in Task 1 can be used directly to approximate Var(X).  That is, compute the mean of n independent simulated values of g(X)={X-E(X)}^2.  If E(X) is not known, replace E(X) by the sample mean and use n-1 as the divisor instead of n.  The resulting quantity is the sample variance, s^2.  In R/Splus, the sample variance can be computed by the command var(x).  The following commands can be used to estimate Var(X) when X is exp(3) with rate 3. 

 

> x<-rexp(10000,3)

> sum((x-mean(x))^2)/(10000-1)  #or you can do...

> var(x)

 

Try the above commands.


 

Task 2.

(a). Let x<-rt(10000,df=2), a simulated t-distribution with 2 degrees of freedom.  What is the mean of X?  What is the variance of X?

(b). Use s^2 to approximate the variance of a Poisson for lambda=1,2,…,99.  What is the relationship between the variance and the mean? To study the relationship, you may want to use the following function to plot your approximated variances against the approximated means.

 

task2b<-function(N=10000) {

  meanarray<-seq(0,0,length=99) 

  vararray<-seq(0,0,length=99)

  for (i in 1:99) {

    x<-rpois(N, i)

    meanarray[i]<-mean(x)

    vararray[i]<-var(x)

  }

  plot(meanarray, vararray)

}

 

(c). Approximate the variance of a binomial with 10 trials for p=1/100, 2/100,…,99/100.

What is the relationship between the success probability and the variance?

(d). Approximate the variance of an exponential with rate lambda.  What is the relationship between lambda and the variance? 

(e). What is the variance of 3+2*X where X is exponential with rate 2?  In general, what is the variance of a+b*X where a and b are constants?