SOLUTION TO hw5 =============== (a) Exact answer = > integrate(function(x) sqrt(1+x+x^4), 0,1, abs.tol=1e-10) 1.288417 with absolute error < 1.4e-14 (b) Exact discrete-probability answer to probability distribution of # Z of distinct elements of (X1,..,X6) for iid discrete-uniform variates X in 0:9 is k 1 2 3 4 5 6 Prob(Z=k) 1e-5 .00279 .0648 .3276 .4536 .1512 -------------- In both parts: it is OK to overestimate variances, i.e. bound them conservatively, in providiing confidence intervals widths. It is also OK to make a preliminary estimate of variance based on a moderate-sized sample (say n0=400), then choose the actual n toattain the desired precision, and then to confirm by re-estimating variance using the full sample that your CI has the desired precision. -------------- Simulations for (a): > fa = function(x) sqrt(1+x+x^4) sqrt(var(fa(runif(1000)))) ### = .20321 ## Using this + 0.2 as the estimated variance, use sample size ## n for simulation found by solving ## qnorm(.995)*.22321/sqrt(n) < .01 , or n >= 3306 > ftmp = fa(runif(3306)) ## now CI estimate = > mean(ftmp) + c(-1,1)*qnorm(.995)*sqrt(var(ftmp)/3306) [1] 1.277210 1.295301 #### OK, the mean 1.2863 is close ! Simulation for (b): find sample size by using conservative bound 1/4 for variance of each of the indicators, and solving ## n >= (qnorm(1-.01/6)/.01)^2*(.25) = 21538.5 ## Here are two ways to do the simulation, both with n=22000: > tmpmat <- array(0, dim=c(22000,10)) for(i in 1:6) { tmpvec <- sample(1:10,22000, replace=T) tmpmat[cbind(1:22000,tmpvec)] = 1 } dvec <- c(tmpmat %*% rep(1,10)) > round(table(dvec)/22000, 4) 2 3 4 5 6 0.0029 0.0647 0.3223 0.4565 0.1536 ### Compare with true analytically calculated values: 0.0028 0.0648 0.3276 0.4536 0.1512 ### NB. The probability that only 1 distinct value occurs = 1e-5. > max(abs(c(.00279,.0648,.3276,.4536,.1512)-table(dvec)/22000)) [1] 0.005327273 ### The largest absolute error turns out to have been: .0053 ### which indicates that our Bonferroni-inequality calculation ### was not terribly conservative.