![](/img/trans.png)
[英]Calculate and plot 95% confidence intervals of a generalised nonlinear model
[英]How to calculate 95% confidence intervals using bayesboot()
我需要幫助,根據我的回歸coef.def
計算數量qtt.ci
的基於引導程序的 可信間隔 。
到目前為止,我的嘗試已導致:
分位數中的錯誤.default(s,c(0.025,0.25,0.5,0.75,0.975)):如果'na.rm'為FALSE,則缺少值和NaN
之前:
警告消息:在bayesboot(dat,boot_fn)中:bayesboot中的樣本包含NA,NaN或NULL。 確保統計函數僅返回實際值。
這是我的示例數據:
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%可信區間的數量是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
這是我的嘗試:
bb_ci <- bayesboot(dat, boot_fn)
summary(bb_ci)
不確定如何獲取qtt.ci
的基於引導的置信區間。
先感謝您。
編輯:
按照@RuiBarradas的回答,我嘗試進行引導以獲取數量qtt.ci(這是我要獲取自舉CI的數量)的95%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
因此,這不會給出qtt.ci
的配置qtt.ci
。 輸出只是qtt
的點估計:
qtt<-(exp(sum(coef.def[2:4])) - exp(coef.def[2]) - exp(coef.def[3]) + 1)
qtt
[1] 2.705878
任何幫助將非常感激。
以下內容解決了警告問題。 我已經用更少的運行次數測試了它,而不是4000的100次測試。
library(bayesboot)
boot_fn <- function(dat) {
fit <- glm(cbind(Pass, Fail) ~ A * B, binomial, dat)
coef.def <- unname(coef(fit))
if(all(!is.na(coef.def))) coef.def else NULL
}
Runs <- 1e2
bb_ci <- bayesboot(dat, boot_fn, R = Runs, R2 = Runs)
summary(bb_ci)
編輯。
根據問題中的公式以及帶有OP的注釋中的對話框,以運行基於引導程序的CI:
qtt <- exp(sum(bb_ci[2:4])) - exp(bb_ci[2]) - exp(bb_ci[3]) + 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.