From b9f8d306f6d00b8476400127380b8cd12631b854 Mon Sep 17 00:00:00 2001 From: bbnkmp Date: Tue, 17 Mar 2026 19:15:56 +0100 Subject: [PATCH 1/2] fix several minor issues --- NAMESPACE | 1 - R/DoseFinding-package.R | 5 ++--- R/Mods_helpers.R | 6 +++--- R/bFitMod.R | 2 +- R/fitMod_helpers.R | 2 +- R/guesst.R | 4 ++++ vignettes/faq.Rmd | 4 ---- vignettes/mult_regimen.Rmd | 5 ++--- 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 0955722..c387c2a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -44,7 +44,6 @@ S3method(plot, Mods) S3method(AIC, DRMod) S3method(gAIC, DRMod) S3method(logLik, DRMod) -S3method(gAIC, DRMod) S3method(predict, bFitMod) S3method(plot, bFitMod) diff --git a/R/DoseFinding-package.R b/R/DoseFinding-package.R index a2b6f67..9197ca5 100644 --- a/R/DoseFinding-package.R +++ b/R/DoseFinding-package.R @@ -284,7 +284,6 @@ NULL #' @docType data #' @usage data(glycobrom) #' @format A data frame with 5 summary estimates (one per dose). Variables: -#' A data frame with 5 summary estimates (one per dose). Variables: #' \describe{ #' \item{`dose`}{a numeric vector containing the dose values} #' \item{`fev1`}{a numeric vector containing the least square @@ -337,7 +336,7 @@ NULL #' @docType data #' @usage data(IBScovars) #' @format -#' A data frame with 369 observations on the following 2 variables. +#' A data frame with 369 observations on the following 3 variables. #' \describe{ #' \item{`gender`}{a factor specifying the gender} #' \item{`dose`}{a numeric vector} @@ -360,7 +359,7 @@ NULL #' @docType data #' @usage data(migraine) #' @format -#' A data frame with 517 columns corresponding to the patients that +#' A data frame with 8 rows (one per dose group) summarizing 517 patients that #' completed the trial #' \describe{ #' \item{`dose`}{a numeric vector containing the dose values} diff --git a/R/Mods_helpers.R b/R/Mods_helpers.R index 16f21de..5f6f7be 100644 --- a/R/Mods_helpers.R +++ b/R/Mods_helpers.R @@ -66,8 +66,8 @@ checkEntries <- function(modL, doses, fullMod){ stop("For model ", nam, ", model entry needs to be equal to NULL") if((nam %in% c("emax", "sigEmax", "betaMod", "logistic", "exponential")) & any(pars <= 0)) stop("For model ", nam, " model entries needs to be positive") - if((nam %in% c("emax", "exponential", "quadratic")) & is.matrix(nam)) - stop("For model ", nam, " parameters need to specified in a vector") + if((nam %in% c("emax", "exponential", "quadratic")) & is.matrix(pars)) + stop("For model ", nam, " parameters need to be specified in a vector") if((nam %in% c("sigEmax", "betaMod", "logistic"))){ if(is.matrix(pars)){ if(ncol(pars) != 2) @@ -776,4 +776,4 @@ getModNams <- function(parList){ mod_nams[i] <- sprintf("linInt (%s)", paste0(parList[[i]], collapse=",")) } mod_nams -} \ No newline at end of file +} diff --git a/R/bFitMod.R b/R/bFitMod.R index 126c10a..2887647 100644 --- a/R/bFitMod.R +++ b/R/bFitMod.R @@ -122,7 +122,7 @@ bFitMod <- function(dose, resp, model, S, placAdj = FALSE, MCMCcontrol = list(), control = NULL, bnds, addArgs = NULL){ if(placAdj & model %in% c("linlog", "logistic")) - stop("logistic and linlog models can only be fitted with placAdj") + stop("logistic and linlog models cannot be fitted to placebo adjusted data") nD <- length(dose) if (length(resp) != nD) stop("dose and resp need to be of the same size") diff --git a/R/fitMod_helpers.R b/R/fitMod_helpers.R index e19880b..c5507c8 100644 --- a/R/fitMod_helpers.R +++ b/R/fitMod_helpers.R @@ -20,7 +20,7 @@ fit.control <- function(control){ if(ind){ stop("gridSize list needs to have names dim1 and dim2") } else { - if(!is.numeric(control$gridSize$dim1) | !is.numeric(control$gridSize$dim1)) + if(!is.numeric(control$gridSize$dim1) | !is.numeric(control$gridSize$dim2)) stop("gridSize$dim1 and gridSize$dim2 need to be numeric") } } diff --git a/R/guesst.R b/R/guesst.R index 0f62ed1..e25225f 100644 --- a/R/guesst.R +++ b/R/guesst.R @@ -148,6 +148,8 @@ guesst <- function(d, p, model = c("emax", "exponential", "logistic", "quadratic (logistic(Maxd,0,1,par[1],par[2])-e0)-p)^2) } res <- try(optim(par=res, fn=foolog, d=d, p=p, Maxd=Maxd)) + if(inherits(res, "try-error")) + stop("cannot find guesstimates for specified values") if(res$convergence > 0) stop("cannot find guesstimates for specified values") else res <- res$par @@ -196,6 +198,8 @@ guesst <- function(d, p, model = c("emax", "exponential", "logistic", "quadratic sigEmax(Maxd,0,1,par[1],par[2])-p)^2) } res <- try(optim(par=res, fn=fooSE, d=d, p=p, Maxd=Maxd)) + if(inherits(res, "try-error")) + stop("cannot find guesstimates for specified values") if(res$convergence > 0) stop("cannot find guesstimates for specified values") else res <- res$par diff --git a/vignettes/faq.Rmd b/vignettes/faq.Rmd index 53b31ba..e972638 100644 --- a/vignettes/faq.Rmd +++ b/vignettes/faq.Rmd @@ -14,10 +14,6 @@ vignette: > --- - - ```{css, echo=FALSE} h2 { font-size: 20px; diff --git a/vignettes/mult_regimen.Rmd b/vignettes/mult_regimen.Rmd index a24aafd..9dd79e1 100644 --- a/vignettes/mult_regimen.Rmd +++ b/vignettes/mult_regimen.Rmd @@ -100,8 +100,8 @@ plot_estimates <- function(est) { ggplot(df, aes(daily_dose, mu_hat)) + geom_point() + geom_errorbar(aes(ymin = lb, ymax = ub)) + facet_wrap(vars(regimen), labeller = label_both) + - xlab("daily dose") + ylab("percent body weight cange") + - labs(title = "ANOVA estimates with 95% confindence intervals") + xlab("daily dose") + ylab("percent body weight change") + + labs(title = "ANOVA estimates with 95% confidence intervals") } est <- example_estimates() @@ -169,7 +169,6 @@ We also need to calculate the test statistics by hand. mct_test <- function(cont_mat, est) { cont_cov <- t(cont_mat) %*% est$S_hat %*% cont_mat t_stat <- drop(est$mu_hat %*% cont_mat) / sqrt(diag(cont_cov)) - # FIXME: calling non-exported function p <- MCTpval(contMat = cont_mat, corMat = cov2cor(cont_cov), df=Inf, tStat=t_stat, alternative = "one.sided") ord <- rev(order(t_stat)) From a1a986d98a33686f0748b800e48d84ea50eedd29 Mon Sep 17 00:00:00 2001 From: bbnkmp Date: Tue, 17 Mar 2026 19:34:13 +0100 Subject: [PATCH 2/2] updated bFitMod test according to new error message --- tests/testthat/test-bFitMod.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-bFitMod.R b/tests/testthat/test-bFitMod.R index d0ace07..9c0af8a 100644 --- a/tests/testthat/test-bFitMod.R +++ b/tests/testthat/test-bFitMod.R @@ -45,7 +45,7 @@ test_that("bFitMod handles placebo adjustment appropriately", { prior <- list(norm = c(0, 10), norm = c(0, 100)) expect_error(bFitMod(dose = doses, resp = drFit, model = "linlog", S = S, placAdj = TRUE, type = "Bayes", nSim = 100, prior = prior), - "logistic and linlog models can only be fitted with placAdj") + "logistic and linlog models cannot be fitted to placebo adjusted data") }) test_that("bFitMod correctly handles 'linInt' model", { @@ -106,4 +106,4 @@ test_that("appropriate methods for bFitMod are defined", { expect_true("predict.bFitMod" %in% methods("predict")) expect_true("plot.bFitMod" %in% methods("plot")) expect_true("coef.bFitMod" %in% methods("coef")) -}) \ No newline at end of file +})