我需要帮助计算
bootstrap-based
credible intervals
数量的
qtt.ci
从我的回归
coef.def
.
到目前为止,我的努力已经导致:
分位数错误。默认值(S,C(0.025,0.25,0.5,0.75,0.975)):
如果“na.rm”为false,则不允许缺少值和NaN
前面:
警告消息:in bayesboot(dat,boot_fn):示例
bayesboot包含nas、nans或nulls。确保您的
统计函数只返回实际值。
以下是我的示例数据:
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)
下面是我的回归。我想得到基于引导的95%可信区间的数量是
QT.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
以下是我的尝试:
bb_ci <- bayesboot(dat, boot_fn)
summary(bb_ci)
不确定如何获取
QT.CI
.
提前谢谢你。
编辑:
根据@ruibarradas的回答,我尝试执行bootstrap以获取qtt.ci数量的95%ci(这是我要获取bootstrapped ci的数量),但没有成功:
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
因此,这并不表示
QT.CI
. 输出只是
qtt
:
qtt<-(exp(sum(coef.def[2:4])) - exp(coef.def[2]) - exp(coef.def[3]) + 1)
qtt
[1] 2.705878
任何帮助都将不胜感激。