Dear Community,
I try to compute the variance of a MC integral where I know the
analytical solution.
The function is exp(-x) integrated on the interval (2,4). (Rizzo example)
The true value is exp(-2)-exp(-4)~.1170196
I have the following short code:
<code>
iter <- 10000
MCs <- numeric(iter)
n <- 5000
a <- 2; b <- 4
for (i in 1:iter){
x <- runif(n, a, b)
MCs[i] <- (b-a)*mean(exp(-x))
}
hist(MCs, freq=FALSE)
<\code>
Which shows a nice normal distribution around the theoretical value,
with a small variance.
On the 125. page of the book the author says that the
Var(theta_hat)=(b-a)^2/m*Var(g(X)).
I try to compare the theoretical normal distribution with the simulated
one, but the two normal distributions are far from each other.
I thought Var(g(X)) was 1, because g(x) is exponential with lambda 1,
but probably thats not true.
Any help is appreciated, thanks:
Daniel
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.