GaryBAYLOR / R-code

A collection of algorithms written by myself for solving statistical problems
0 stars 0 forks source link

Asymptotic simulation of delta method #23

Open GaryBAYLOR opened 8 years ago

GaryBAYLOR commented 8 years ago

The purpose is to do a simulation to see the performance of Delta method. Let X1, ..., Xn is i.i.d. from Poisson(theta), Yi = I(Xi = 0 ). Find the asymptotic distribution of 2 mean(Xn) + log (Yn). The solution by using CLT and multivariate delta method is N(theta, exp(theta)/n). The following is R simulation code. We showed that when n is large, the approximation is good.

a <- expression(
n <- 5e4, # we set n to be fairly large. When n is small, the performance is not good.
theta <- 5,
x <- rpois(n, theta),
y <- x == 0,
Z <- 2 * mean(x) + log(mean(y))
)

sim <- replicate(1e4,eval(a))

xlow <- theta - 3 * sqrt(exp(theta) / n)
xhigh <- theta + 3 * sqrt(exp(theta) / n)
xseq <- seq(xlow, xhigh, length = 100)
plot(density(sim))
lines(xseq, dnorm(xseq, theta, sqrt(exp(theta)/n)), col = "red")

The result is pretty good. image