set.seed(1974) N <- 10000 x <- rexp(N) h <- function(x) 1+x^2+sin(x)*abs(x) thetahat <- mean(h(x)) tauhat <- var(h(x)) sqrt(tauhat/N) c(thetahat-sqrt(tauhat/N)*qnorm(0.975),thetahat+sqrt(tauhat/N)*qnorm(0.975)) z <- function(x) h(x)*exp(-x) curve(z,0,20) integrate(z,0,20) N <- 10000 thetahat <- rep(0,1000) for (j in 1:1000) { x <- rexp(N) thetahat[j] <- mean(h(x)) } hist(thetahat,nclass=20,prob=TRUE) curve(dnorm(x,3.5,0.04),from=0,to=12,n=1000,add=TRUE,col="red") luglu <- cumsum(h(x))/(1:N) plot(1:N,luglu,type="l")