代码之家  ›  专栏  ›  技术社区  ›  Krantz

如何引导两个模型回归系数的算术运算结果

  •  0
  • Krantz  · 技术社区  · 6 年前

    我想对两个回归模型的输出进行bootstrap,得到运算结果均值的置信区间。

    ldose <- rep(0:5, 2)
    numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
    sex <- factor(rep(c("M", "F"), c(6, 6)))
    SF <- cbind(numdead, numalive = 20-numdead)
    dat<-data.frame(ldose, numdead, sex, SF)
    tibble::rowid_to_column(dat, "indices")
    

    #创建要引导的函数

    out<-function(dat) {
         d<-data[indices, ] #allows boot to select sample
         fit1<- glm(SF ~ sex*ldose, family = binomial (link = log), start=c(-1,0,0,0))
         fit2<- glm(SF ~ sex*ldose, family = binomial (link = log), start=c(-1,0,0,0))
         coef1<-coef(fit1)
         numer<-exp(coef1[2])
         coef2<-coef(fit2)
         denom<-exp(coef2[2])
         resultX<-numer/denom
         return(mean(resultX))
    }
    

    results <- boot(dat, out, 1000)
    

    #错误消息

    统计错误(数据,原始,…):未使用的参数(原始)

    提前谢谢你的帮助。

    0 回复  |  直到 6 年前