I need help to calculate bootstrap-based credible intervals of the quantity qtt.ci
from my regression coef.def
.
So far my attempts have resulted in:
Error in quantile.default(s, c(0.025, 0.25, 0.5, 0.75, 0.975)) : missing values and NaN's not allowed if 'na.rm' is FALSE
preceded by:
Warning message: In bayesboot(dat, boot_fn) : The sample from bayesboot contains either NAs, NaNs or NULLs. Make sure that your statistic function only return actual values.
Here are my sample data:
dat <- data.frame(
A = c(1, 1, 0, 0), B = c(1, 0, 1, 0),
Pass = c(278, 100, 153, 79), Fail = c(743, 581, 1232, 1731)
Below is my regression. The quantity I want to get the bootstrap-based 95% credible intervals is qtt.ci
:
boot_fn <- function(dat) {
coef.def = unname(coef(glm(cbind(Pass, Fail) ~ A * B, binomial,
dat)))
}
qtt.ci <- exp(sum(coef.def[2:4])) - exp(coef.def[2]) - exp(coef.def[3]) + 1
Here is my attempt:
bb_ci <- bayesboot(dat, boot_fn)
summary(bb_ci)
Not certain how to get the bootstrap-based confidence intervals for qtt.ci
.
Thank you in advance.
EDIT:
Following the answer by @RuiBarradas, I tried doing bootstrap to get the 95% CI for the quantity qtt.ci (which is the quantity for which I want to get the bootstrapped CI), but no success:
library(bayesboot)
boot_fn <- function(dat) {
coef.def <- unname(coef(glm(cbind(Pass, Fail) ~ A * B, binomial, dat)))
qtt<- (exp(sum(coef.def[2:4])) - exp(coef.def[2]) - exp(coef.def[3]) + 1)
if(all(!is.na(qtt))) qtt else NULL
}
Runs <- 1e2
qtt.ci <- bayesboot(dat, boot_fn, R = Runs, R2 = Runs)
summary(qtt.ci)
Quantiles:
statistic q2.5% q25% median q75% q97.5%
V1 2.705878 2.705878 2.705878 2.705878 2.705878
Therefore, this does not give the CI for qtt.ci
. The output is simply the point estimate for qtt
:
qtt<-(exp(sum(coef.def[2:4])) - exp(coef.def[2]) - exp(coef.def[3]) + 1)
qtt
[1] 2.705878
Any help would be much appreciated.