The exact value is:
\[ \theta = \int_{0}^{\frac{\pi}{3}} sin(x) \; dx\] \[ -cos(x) |_{0}^{\frac{\pi}{3}}\] \[ cos(0)-cos(\frac{\pi}{3}) \]
The estimate is \[ \hat{\theta} = \overline{g_{n}(X)} = \frac{1}{n}\sum_{x = 1}^{n} g(X_{i})\] \[ = (b-a)\overline{g_{n}(X)}\] \[ = \frac{\pi}{3} (\overline{sin({x_{i}}})\]
set.seed(12345)
n <- 10000
x <- runif(n, 0, pi/3)
theta.hat <- (pi/3) * mean(sin(x))
exact <- -(cos(pi/3)-cos(0))
kable(cbind(c("exact","estimate"),round(c(theta.hat,exact),3))) %>%
kable_paper("hover", full_width = F)
| exact | 0.501 |
| estimate | 0.5 |
\[\Phi(x) = \int_{-\infty}^{x} \frac{1}{2\pi}e^{\frac{-t^{2}}{2}} \; dt \] We need to break it into two cases, \[x \ge 0 , x < 0 \] Substituting y=t/x, we have \[ \theta = \int_{0}^{1}xe^{-(xy)^{2}/2}dy \] The estimate is \[ \hat{\theta} = \overline{g_{m}(u)} = \frac{1}{m}\sum_{x = 1}^{m} xe^{-(xu_i)^{2}/2}\]
set.seed(12345)
x <- seq(0.5,2.5, length = 10)
m <- 10000
u <- runif(m)
cdf <- numeric(length(x))
for (i in 1:length(x)) {
g <- x[i] * exp(-u* x[i]^2/2)
cdf[i] <- mean(g) / sqrt(2*pi) + 0.5
}
Phi <- pnorm(x)
kable(round(rbind(x, cdf, Phi),3)) %>%
kable_paper("hover", full_width = F)
| x | 0.500 | 0.722 | 0.944 | 1.167 | 1.389 | 1.611 | 1.833 | 2.056 | 2.278 | 2.500 |
| cdf | 0.687 | 0.754 | 0.804 | 0.837 | 0.855 | 0.859 | 0.853 | 0.840 | 0.823 | 0.804 |
| Phi | 0.691 | 0.765 | 0.828 | 0.878 | 0.918 | 0.946 | 0.967 | 0.980 | 0.989 | 0.994 |
samples <- 2*exp(-2^2*u^2/2)/sqrt(2*pi)+.5
estimate <- mean(samples)
v <- var(samples)/m
LB <- estimate-1.96*sqrt(v)
UB <- estimate+1.96*sqrt(v)
kable(cbind(c("Estimate","Variance estimate","Lower Bound","Upper Bound"),c(round(estimate,3),round(v,8),round(LB,3),round(UB,3)))) %>%
kable_paper("hover",full_width = F)
| Estimate | 0.977 |
| Variance estimate | 5.25e-06 |
| Lower Bound | 0.972 |
| Upper Bound | 0.981 |