diff --git a/R/Mods.R b/R/Mods.R index 2e73ef9..dd9551b 100644 --- a/R/Mods.R +++ b/R/Mods.R @@ -311,8 +311,8 @@ plot.Mods <- function(x, nPoints = 200, superpose = FALSE, xlab = "Dose", } -#' Calculate dose estimates for a fitted dose-response model (via \code{\link{fitMod}} or \code{\link{bFitMod}}) or a -#' \code{\link{Mods}} object +#' Calculate dose estimates for a fitted dose-response model (via \code{\link{fitMod}}, \code{\link{bFitMod}}) +#' or \code{\link{maFitMod}}) or a \code{\link{Mods}} object #' #' @description The TD (target dose) is defined as the dose that achieves a target effect of Delta over placebo (if #' there are multiple such doses, the smallest is chosen): @@ -348,7 +348,7 @@ plot.Mods <- function(x, nPoints = 200, superpose = FALSE, xlab = "Dose", #' @param direction Direction to be used in defining the TD. This depends on whether an increasing #' or decreasing of the response variable is beneficial. In case of ED calculation only needed for maFit objects. #' @param doses Dose levels to be used if \samp{TDtype} or \samp{EDtype} are -#' equal to \samp{"discrete"}. Needs to include placebo, . +#' equal to \samp{"discrete"}. Needs to include placebo, and may not exceed the dose range of the model(s) provided in \samp{object}. #' #' @return Returns the dose estimate #' @@ -389,7 +389,8 @@ TD <- function(object, Delta, TDtype = c("continuous", "discrete"), scal <- attr(object, "scal") nodes <- attr(object, "doses") maxD <- max(attr(object, "doses")) - if(any(doses > maxD)) + TDtype <- match.arg(TDtype) + if(TDtype == "discrete" & any(doses > maxD)) stop("Doses provided may not exceed the observed dose range") ## loop through list for(nam in names(object)){ @@ -417,7 +418,8 @@ TD <- function(object, Delta, TDtype = c("continuous", "discrete"), nodes <- attr(object, "nodes") doseNam <- attr(object, "doseRespNam")[1] maxD <- max(attr(object,"data")[[doseNam]]) - if(any(doses > maxD)) + TDtype <- match.arg(TDtype) + if(TDtype == "discrete" & any(doses > maxD)) stop("Doses provided may not exceed the observed dose range") if(attr(object, "placAdj")){ par <- c(0, par) @@ -435,7 +437,8 @@ TD <- function(object, Delta, TDtype = c("continuous", "discrete"), nodes <- attr(object, "nodes") doseNam <- attr(object, "doseRespNam")[1] maxD <- max(attr(object,"data")[[doseNam]]) - if(any(doses > maxD)) + TDtype <- match.arg(TDtype) + if(TDtype == "discrete" & any(doses > maxD)) stop("Doses provided may not exceed the observed dose range") if(attr(object, "placAdj")){ if(nam == "linInt") @@ -456,7 +459,7 @@ TD <- function(object, Delta, TDtype = c("continuous", "discrete"), TDtype <- match.arg(TDtype) maxD <- max(object$args$dose) if(TDtype == "discrete"){ - if(missing(doses)) + if(is.null(doses)) stop("For TDtype = \"discrete\" need the possible doses in doses argument") if(doses[1] != 0) stop("need placebo dose for TD calculation") @@ -560,7 +563,7 @@ ED <- function(object, p, EDtype = c("continuous", "discrete"), EDtype <- match.arg(EDtype) maxD <- max(object$args$dose) if(EDtype == "discrete"){ - if(missing(doses)) + if(is.null(doses)) stop("For EDtype = \"discrete\" need the possible doses in doses argument") if(!any(doses == 0)) stop("need placebo dose for ED calculation") @@ -584,11 +587,12 @@ ED <- function(object, p, EDtype = c("continuous", "discrete"), difs <- (pred_med - pred_med[1]) ind <- which(difs > p*max(difs)) - if(EDtype == "discrete") - ind <- ind[ind <= length(doses)] ## only include doses that where initially included + if(length(ind) == 0) + return(NA) - if (length(ind)>0) { - return(min(doseSeq[ind])) + edose <- min(doseSeq[ind]) + if (EDtype == "continuous" | edose %in% doses) {## don't return maxD if it was not in originally provided doses for discrete type + return(edose) } else { return(NA) } diff --git a/R/Mods_helpers.R b/R/Mods_helpers.R index 6241581..16f21de 100644 --- a/R/Mods_helpers.R +++ b/R/Mods_helpers.R @@ -605,11 +605,12 @@ calcED <- function(model, pars, p, maxD, EDtype = c("continuous", "discrete"), } } ind <- which(resp > p*maxResp) - if(EDtype == "discrete") - ind <- ind[ind <= length(doses)] ## only include doses that where initially included + if(length(ind) == 0) + return(NA) - if(length(ind) > 0){ ## ED does exist return smallest dose fulfilling threshold - return(min(doseSeq[ind])) + edose <- min(doseSeq[ind]) + if (EDtype == "continuous" | edose %in% doses) {## don't return maxD if it was not in originally provided doses for discrete type + return(edose) } else { return(NA) } diff --git a/R/maFitMod.R b/R/maFitMod.R index 6ab80c1..cf5abea 100644 --- a/R/maFitMod.R +++ b/R/maFitMod.R @@ -110,8 +110,8 @@ maFitMod <- function(dose, resp, S, models, #' @param doseSeq Where to calculate predictions. #' @param ... Further arguments (currently ignored) #' @rdname maFitMod -#' @method predict maFitMod -#' #' @export +#' @method predict maFit +#' @export predict.maFit <- function(object, summaryFct = function(x) quantile(x, probs = c(0.025, 0.25, 0.5, 0.75, 0.975)), doseSeq = NULL, diff --git a/man/targdose.Rd b/man/targdose.Rd index 5886f32..264d670 100644 --- a/man/targdose.Rd +++ b/man/targdose.Rd @@ -4,8 +4,8 @@ \alias{Target doses} \alias{TD} \alias{ED} -\title{Calculate dose estimates for a fitted dose-response model (via \code{\link{fitMod}} or \code{\link{bFitMod}}) or a -\code{\link{Mods}} object} +\title{Calculate dose estimates for a fitted dose-response model (via \code{\link{fitMod}}, \code{\link{bFitMod}}) + or \code{\link{maFitMod}}) or a \code{\link{Mods}} object} \usage{ TD( object, @@ -37,7 +37,7 @@ variable when calculating the TD/ED or whether the TD/ED should be calculated ba or decreasing of the response variable is beneficial. In case of ED calculation only needed for maFit objects.} \item{doses}{Dose levels to be used if \samp{TDtype} or \samp{EDtype} are -equal to \samp{"discrete"}. Needs to include placebo, .} +equal to \samp{"discrete"}. Needs to include placebo, and may not exceed the dose range of the model(s) provided in \samp{object}.} } \value{ Returns the dose estimate