Question

In: Statistics and Probability

You know that the definition of the variance is Var[X] = 1 n − 1 Z...

You know that the definition of the variance is Var[X] = 1 n − 1 Z ∞ −∞ (Xi − µ) 2 dFX(x), so if we have a plug-in estimator S 2 = 1 n − 1 Xn i=1 (xi − X¯) 2 and we are interested in SES2 = p Var[S2] we can use the bootstrap to obtain it. Write a function in R called bootVarSE that computes a bootstrap estimate of the standard error of the sample variance estimator. Test your function using 100 standard random normal draws (that is, rnorm(100)) as data input.

Solutions

Expert Solution

###########################################
## Boostrap for the Normal distribution
## And compare with known distribution
###########################################
set.seed(1)
# X1, ..., Xn ~ N(mu, sigma^2)
# bar(X) ~ N(mu, sigma^2/n)
# Let's say distribution of bar(x) is not known


###########################################
## Nonparametric bootstrap
###########################################

# First small n and B
mu <- 5
sig2 <- 3
n <- 10

my.samp <- rnorm(n, mean = mu, sd = sqrt(sig2))

barx <- mean(my.samp)
var.x <- var(my.samp)

B <- 10
boot.np <- numeric(length = B)
boot.p <- numeric(length = B)

for(b in 1:B)
{
boot.samp.np <- sample(my.samp, replace = TRUE) # NP Bootstramp samples
boot.np[b] <- mean(boot.samp.np) # NP Bootstrap estimator
  
boot.samp.p <- rnorm(n, mean = barx, sd = sqrt(var.x))
boot.p[b] <- mean(boot.samp.p)
}

# 95% Boostratp confidence interval
quantile(boot.np, probs = c(.025, .975))
quantile(boot.p, probs = c(.025, .975))

# CI from known distribution
c( barx - qt(.975, df = n-1)*sqrt(var.x/n), barx + qt(.975, df = n-1)*sqrt(var.x/n) )

# CIs are close, but not great

###########################################
# Now n is same B is big


mu <- 5
sig2 <- 3
n <- 10

B <- 1e3
boot.np <- numeric(length = B)
boot.p <- numeric(length = B)

for(b in 1:B)
{
boot.samp.np <- sample(my.samp, replace = TRUE) # NP Bootstramp samples
boot.np[b] <- mean(boot.samp.np) # NP Bootstrap estimator
  
boot.samp.p <- rnorm(n, mean = barx, sd = sqrt(var.x))
boot.p[b] <- mean(boot.samp.p)
}

# 95% Boostratp confidence interval
quantile(boot.np, probs = c(.025, .975))
quantile(boot.p, probs = c(.025, .975))

# CI from known distribution
c( barx - qt(.975, df = n-1)*sqrt(var.x/n), barx + qt(.975, df = n-1)*sqrt(var.x/n) )

# CIs are closer!


###########################################
# Now n is big and B is big

mu <- 5
sig2 <- 3
n <- 100

my.samp <- rnorm(n, mean = mu, sd = sqrt(sig2))

barx <- mean(my.samp)
var.x <- var(my.samp)

B <- 1e3
boot.np <- numeric(length = B)
boot.p <- numeric(length = B)

for(b in 1:B)
{
boot.samp.np <- sample(my.samp, replace = TRUE) # NP Bootstramp samples
boot.np[b] <- mean(boot.samp.np) # NP Bootstrap estimator
  
boot.samp.p <- rnorm(n, mean = barx, sd = sqrt(var.x))
boot.p[b] <- mean(boot.samp.p)
}

# 95% Boostratp confidence interval
quantile(boot.np, probs = c(.025, .975))
quantile(boot.p, probs = c(.025, .975))

# CI from known distribution
c( barx - qt(.975, df = n-1)*sqrt(var.x/n), barx + qt(.975, df = n-1)*sqrt(var.x/n) )

# CIs are very close now!


Related Solutions

      Show that     Var(x-a/)=1/h^2 Var(x)
      Show that     Var(x-a/)=1/h^2 Var(x)
Prove Var(|X|) <= Var(X)
Prove Var(|X|) <= Var(X)
Let X be a Bin(n, p) random variable. Show that Var(X) = np(1 − p). Hint:...
Let X be a Bin(n, p) random variable. Show that Var(X) = np(1 − p). Hint: First compute E[X(X − 1)] and then use (c) and (d). (c) Var(X) = E(X^2 ) − (E X)^ 2 (d) E(X + Y ) = E X + E Y
QUESTION 1 Consider the following program: var x = 0; function sub1() {    var x =...
QUESTION 1 Consider the following program: var x = 0; function sub1() {    var x = 1;    function sub2() {       function sub3() {          print x;       }       sub3();    }    function sub4() {       var x = 2;       sub2();      }    sub4(); } sub1(); If this code uses static scoping, when it is executed what is printed? 0 1 2 QUESTION 2 Consider the following program: var x = 0; function sub1() {    var x = 1;    function sub2() {       function sub3() {          print...
Suppose that f(x)=x^n+a_(n-1) x^(n-1)+⋯+a_0∈Z[x]. If r is rational and x-r divides f(x), prove that r is...
Suppose that f(x)=x^n+a_(n-1) x^(n-1)+⋯+a_0∈Z[x]. If r is rational and x-r divides f(x), prove that r is an integer.
Consider a binomial experiment with n=5 and p=0.20 What is Var(x)?
Consider a binomial experiment with n=5 and p=0.20 What is Var(x)?
Given: E[x] = 4, E[y] = 6, Var(x) = 2, Var(y) = 1, and cov(x,y) =...
Given: E[x] = 4, E[y] = 6, Var(x) = 2, Var(y) = 1, and cov(x,y) = 0.2 Find a lower bound on (5 < x + y < 10). State the theorem used.
If Var(X) = 1, Var(Y) = 2 and Cov(X,Y) = 0, what is Cov(X-2Y, Y-X2)?
If Var(X) = 1, Var(Y) = 2 and Cov(X,Y) = 0, what is Cov(X-2Y, Y-X2)?
Use simulation to prove that when X ∼ N(0, 1), Z ∼ N(0, 1), Y =...
Use simulation to prove that when X ∼ N(0, 1), Z ∼ N(0, 1), Y = X3 + 10X +Z, we have V ar(X +Y ) = V ar(X) +V ar(Y ) + 2Cov(X, Y ) and V ar(X −Y ) = V ar(X) + V ar(Y ) − 2Cov(X, Y ).
2.48. Is it true that {ax + by + cz|x, y, z ∈ Z} = {n...
2.48. Is it true that {ax + by + cz|x, y, z ∈ Z} = {n · gcd(a, b, c)|n ∈ Z}? 2.49. What are all the integer values of e for which the Diophantine equation 18x + 14y + 63z = e has an integer solution. Find a solution for each such e. 2.50. For integers a, b and k > 0, is it true that a | b iff a^k | b^k ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT