# NOT RUN {
set.seed(4321)
Design <- createDesign(sigma = c(1, 2))
#-------------------------------------------------------------------
Generate <- function(condition, fixed_objects = NULL) {
dat <- rnorm(100, 0, condition$sigma)
dat
}
Analyse <- function(condition, dat, fixed_objects = NULL) {
CIs <- t.test(dat)$conf.int
names(CIs) <- c('lower', 'upper')
ret <- c(mean = mean(dat), CIs)
ret
}
Summarise <- function(condition, results, fixed_objects = NULL) {
ret <- c(mu_bias = bias(results[,1], 0),
mu_coverage = ECR(results[,2:3], parameter = 0))
ret
}
# }
# NOT RUN {
# boot_predict supports only one condition at a time
out <- boot_predict(condition=Design[1L, , drop=FALSE],
generate=Generate, analyse=Analyse, summarise=Summarise)
out # list of fitted linear model(s)
# extract first meta-statistic
mu_bias <- out$mu_bias
dat <- model.frame(mu_bias)
print(dat)
# original R metric plot
R <- 1 / dat$one_sqrtR^2
plot(R, dat$MSE, type = 'b', ylab = 'MSE', main = "Replications by MSE")
plot(MSE ~ one_sqrtR, dat, main = "Bootstrap prediction plot", xlim = c(0, max(one_sqrtR)),
ylim = c(0, max(MSE)), ylab = 'MSE', xlab = expression(1/sqrt(R)))
beta <- coef(mu_bias)
abline(a = 0, b = beta, lty = 2, col='red')
# what is the replication value when x-axis = .02? What's its associated expected MSE?
1 / .02^2 # number of replications
predict(mu_bias, data.frame(one_sqrtR = .02)) # y-axis value
# approximately how many replications to obtain MSE = .001?
(beta / .001)^2
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab