55# '
66# ' BMDL is defined as the 5th percentile in the bootstrap distribution.
77# '
8- # ' Bootstrapping with the argument boot = "nonparametric" is done by sampling
8+ # ' Bootstrapping with the argument bootType = "nonparametric" is done by sampling
99# ' with replacement from the original data set. Bootstrapping with the argument
10- # ' boot = "parametric" is done by sampling from norm(mean(Y_i),sd(Y_0)),
10+ # ' bootType = "parametric" is done by sampling from norm(mean(Y_i),sd(Y_0)),
1111# ' assuming equal variance between groups, in case of continuous data. For
1212# ' binomial data, each bootstrap data set is sampled from binom(N_i,Y_i/N_i).
1313# ' In case of Y_i = 0 or Y_i = N_i shrinkage is used to avoid that the
1414# ' resampling always produces 0 or 1, respectively. In this case data is
1515# ' sampled from binom(N_i,(Y_i+1/4)/(N_i+1/2)). Bootstrapping with argument
16- # ' boot = "semiparametric" is done by sampling with replacement from the
17- # ' residuals.
16+ # ' bootType = "semiparametric" is done by sampling with replacement from the
17+ # ' residuals. Bootstrapping with argument bootType = "wild" is done by resampling
18+ # ' with replacement from the residuals multiplied by a random sign (-1 or +1).
1819# '
19- # ' All sampling is made within dose groups.
20+ # ' All sampling is made within dose groups. When a meta-analytic random effects
21+ # ' model is supplied, sampling is made within dose groups within each experiment.
2022# '
21- # ' @param object object of class \code{drc}
23+ # ' @param object object of class \code{drc} or \code{drcMMRE}
2224# ' @param bmr numeric value of benchmark response level for which to calculate
2325# ' the benchmark dose
2426# ' @param R number of bootstrap samples. Default is 1000
2527# ' @param bootType character string specifying type of bootstrap used.
26- # ' "nonparametric" (default), "semiparametric" or "parametric ". "Semiparametric
28+ # ' "nonparametric" (default), "semiparametric", "parametric" or "wild ". "semiparametric" and "wild"
2729# ' is only available for continuous data and "nonparametric" is at present the
2830# ' only option for count data. See details below
2931# ' @param bmdType Type of estimate for BMD. Default is "orig" the bmd estimate
102104# ' and adjusted)
103105# ' @param display logical. If TRUE the results are displayed; otherwise they
104106# ' are not
105- # ' @param level numeric value specifying the levle of the confidence interval
107+ # ' @param level numeric value specifying the level of the confidence interval
106108# ' underlying BMDL. Default is 0.95
107- # ' @return A list of three elements: Results contain the estimated BMD and
108- # ' BMDL, bootEst is a vector af all of the estimated BMD values from each
109+ # ' @return A list of four elements: Results contain the estimated BMD and
110+ # ' BMDL, Boot.samples.used is the number of samples used, bootEst is a vector af all of the estimated BMD values from each
109111# ' bootstrap sample, Interval gives BMDL and BMDU, which is identical to the
110112# ' confidence interval for the percentile interval approach.
111113# ' @author Signe M. Jensen
125127# ' ## BMD from the same definitions but using parametric bootstrap
126128# ' bmdBoot(ryegrass.m1, 0.05, backgType = "hybridSD", def = "hybridAdd", bootType="parametric",R = 50)
127129# '
130+ # ' ## BMD on meta-analytic random effects model
131+ # ' set.seed(1)
132+ # ' data0 <- data.frame(x = rep(drcData::ryegrass$conc, 2),
133+ # ' y = rep(drcData::ryegrass$rootl, 2) +
134+ # ' c(rnorm(n = nrow(drcData::ryegrass), mean = 2, sd = 0.5),
135+ # ' rnorm(n = nrow(drcData::ryegrass), mean = 2.7, sd = 0.7)),
136+ # ' EXP_ID = rep(as.character(1:2), each = nrow(drcData::ryegrass)))
137+ # '
138+ # ' modMMRE <- drmMMRE(y~x, exp_id = EXP_ID, data = data0, fct = LL.4())
139+ # ' bmdBoot(modMMRE, bmr = 0.1, backgType = "modelBased", def = "relative", R = 50, bootType = "wild")
140+ # '
128141# ' @export
129142bmdBoot <- function (object , bmr , R = 1000 , bootType = " nonparametric" , bmdType = " orig" ,
130143 backgType = c(" modelBased" , " absolute" , " hybridSD" , " hybridPercentile" ),
@@ -183,7 +196,16 @@ bmdBoot <- function(object, bmr, R=1000, bootType="nonparametric", bmdType = "or
183196 interval = " delta" , display = FALSE )
184197
185198 get.drm.list <- function (tmp.data ){
186- if (ncol(object $ parmMat ) == 1 ){
199+ if (inherits(object , " drcMMRE" )){
200+ drm.list.tmp <- lapply(tmp.data , function (x ){
201+ try(eval(substitute(drmMMRE(formula0 , exp_id = exp_id0 , data = x , type = object $ type , fct = object [[" fct" ]]),
202+ list (formula0 = object $ call $ formula ,
203+ exp_id0 = object $ call $ exp_id )
204+ )), TRUE )
205+ }
206+ )
207+ }
208+ else if (ncol(object $ parmMat ) == 1 ){
187209 drm.list.tmp <- lapply(tmp.data , function (x ){
188210 try(eval(substitute(drm(formula0 , data = x , type = object $ type , fct = object [[" fct" ]],
189211 control = drmc(noMessage = TRUE )),
@@ -193,9 +215,6 @@ bmdBoot <- function(object, bmr, R=1000, bootType="nonparametric", bmdType = "or
193215 )
194216 } else if (is.null(object $ call $ pmodels )){
195217 drm.list.tmp <- lapply(tmp.data , function (x ){
196- # if(object$type != "binomial"){
197- # x[[as.character(object$call$curveid)]] <- x[[paste0("orig.", as.character(object$call$curveid))]]
198- # }
199218 try(
200219 eval(substitute(drm(object $ call $ formula , weights = weights0 , curveid = curveid0 ,
201220 data = x , type = object $ type , fct = object $ fct , control = drmc(noMessage = TRUE )),
@@ -206,9 +225,6 @@ bmdBoot <- function(object, bmr, R=1000, bootType="nonparametric", bmdType = "or
206225 })
207226 } else {
208227 drm.list.tmp <- lapply(tmp.data , function (x ){
209- # if(object$type != "binomial"){
210- # x[[as.character(object$call$curveid)]] <- x[[paste0("orig.", as.character(object$call$curveid))]]
211- # }
212228 try(
213229 eval(substitute(drm(formula0 , weights = weights0 , curveid = curveid0 , pmodels = pmodels0 ,
214230 data = x , type = object $ type , fct = object $ fct , control = drmc(noMessage = TRUE )),
@@ -233,11 +249,14 @@ bmdBoot <- function(object, bmr, R=1000, bootType="nonparametric", bmdType = "or
233249 }
234250
235251 if (object $ type %in% c(" binomial" ," continuous" )) {
236-
237- tmp.data <- bootDataGen(object ,R ,bootType ,aggregated = FALSE )
252+ if (inherits(object , " drcMMRE" )){
253+ tmp.data <- bootDataGenMMRE(object ,R ,bootType )
254+ } else {
255+ tmp.data <- bootDataGen(object ,R ,bootType ,aggregated = FALSE )
256+ }
238257
239258 drm.list.tmp <- get.drm.list(tmp.data )
240- list.condition <- sapply(drm.list.tmp , function ( x ) class( x ) == " drc" )
259+ list.condition <- sapply(drm.list.tmp , inherits , " drc" )
241260 drm.list <- drm.list.tmp [list.condition ]
242261
243262 bmd.list.try <- lapply(drm.list ,get.bmd )
0 commit comments