### Install DoseFinding from GitHub Source: https://github.com/openpharma/dosefinding/blob/master/README.md Installs the development version of the DoseFinding package from GitHub. Requires the devtools package. ```r # install.packages("devtools") devtools::install_github("openpharma/DoseFinding") ``` -------------------------------- ### Get default bounds for non-linear model parameters with defBnds() Source: https://context7.com/openpharma/dosefinding/llms.txt Call `defBnds()` to obtain default lower and upper bounds for nonlinear model parameters, scaled to the study's maximum dose. These bounds are essential for internal use by fitting functions like `fitMod()` and `MCPMod()`. ```r library(DoseFinding) # Bounds for a study with maximum dose 200 bnds <- defBnds(mD = 200) bnds$emax # c(0.2, 300) — bounds for ED50 bnds$logistic # 2x2 matrix: rows = ED50, delta bnds$sigEmax bnds$exponential bnds$betaMod ``` -------------------------------- ### Define and use built-in dose-response model functions Source: https://context7.com/openpharma/dosefinding/llms.txt The DoseFinding package provides direct access to its built-in dose-response model functions, such as `emax()`, `sigEmax()`, `logistic()`, `betaMod()`, `exponential()`, `quadratic()`, and `linlog()`. These can be used for custom calculations, simulations, or visualizations. ```r library(DoseFinding) dose <- seq(0, 150, by = 5) # Emax model: f(d) = e0 + eMax * d / (ed50 + d) emax(dose, e0 = 0, eMax = 0.4, ed50 = 25) ``` ```r # Sigmoid Emax: f(d) = e0 + eMax / (1 + (ed50/d)^h) sigEmax(dose, e0 = 0, eMax = 0.4, ed50 = 50, h = 2) ``` ```r # Logistic: S-shaped with left asymptote e0, right asymptote e0+eMax logistic(dose, e0 = 0, eMax = 0.4, ed50 = 50, delta = 10) ``` ```r # Beta model (unimodal with fixed scal parameter) betaMod(dose, e0 = 0, eMax = 0.4, delta1 = 0.33, delta2 = 2.31, scal = 200) ``` ```r # Exponential: f(d) = e0 + e1*(exp(d/delta) - 1) exponential(dose, e0 = 0, e1 = 0.03, delta = 85) ``` ```r # Quadratic: f(d) = e0 + b1*d + b2*d^2 quadratic(dose, e0 = 0, b1 = 0.005, b2 = -0.00002) ``` ```r # Linear in log: f(d) = e0 + delta * log(d + off) linlog(dose, e0 = 0, delta = 0.2, off = 1) ``` -------------------------------- ### Calculate Sample Size with sampSizeMCT() and sampSize() Source: https://context7.com/openpharma/dosefinding/llms.txt Calculates the required sample size for multiple contrast tests or general target functions using bisection search. `sampSizeMCT` is a convenience wrapper for MCT. ```r library(DoseFinding) fmodels <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, betaMod = rbind(c(0.33, 2.31), c(1.39, 1.39)), doses = c(0, 10, 25, 50, 100, 150), placEff = 0, maxEff = 0.4, addArgs = list(scal = 200)) contMat <- optContr(fmodels, w = 1) # Convenience wrapper: target 80% mean power, balanced allocation sSize <- sampSizeMCT(upperN = 100, contMat = contMat, sigma = 1, altModels = fmodels, power = 0.8, alRatio = rep(1, 6), alpha = 0.05) sSize ``` ```r # General sampSize: custom target function (minimum power over all models) tFunc <- function(n) min(powMCT(contMat, altModels = fmodels, n = n, sigma = 1, alpha = 0.05)) sampSize(upperN = 150, targFunc = tFunc, target = 0.8, alRatio = rep(1, 6), verbose = TRUE) ``` -------------------------------- ### Evaluate operating characteristics of a design using planMod() Source: https://context7.com/openpharma/dosefinding/llms.txt Use `planMod()` to assess design performance metrics like RMSE, power, and probability of correct EDp identification. It supports asymptotic approximations for speed or simulations for accuracy, and requires a set of candidate models and study parameters. ```r library(DoseFinding) doses <- c(0, 10, 25, 50, 100, 150) fmodels <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, doses = doses, addArgs = list(scal = 200), placEff = 0, maxEff = 0.4) # Asymptotic approximation (single model, fast) plan <- planMod(model = "emax", altModels = fmodels, n = 50, sigma = 1, doses = doses, asyApprox = TRUE, simulation = FALSE) print(plan) # dRMSE, Pow(maxDose), P(EDp) summary(plan) # additional cRMSE, Eff-vs-ANOVA metrics plot(plan) ``` -------------------------------- ### Perform Multiple Contrast Tests Source: https://github.com/openpharma/dosefinding/blob/master/README.md Performs model-based multiple contrast tests using candidate dose-response shapes. Requires the DoseFinding library and data. Set a random seed for reproducible adjusted p-values. ```r library(DoseFinding) data(IBScovars) ## set random seed to ensure reproducible adj. p-values for multiple contrast test set.seed(12) ## perform (model based) multiple contrast test ## define candidate dose-response shapes models <- Mods(linear = NULL, emax = 0.2, quadratic = -0.17, doses = c(0, 1, 2, 3, 4)) ## plot models plot(models) ## perform multiple contrast test MCTtest(dose, resp, IBScovars, models=models, addCovars = ~ gender) ``` -------------------------------- ### Bayesian Dose-Response Model Fitting (bFitMod) Source: https://context7.com/openpharma/dosefinding/llms.txt Fits dose-response models using MCMC sampling (Bayes) or parametric bootstrap. Input requires dose-group estimates and their covariance matrix from a first-stage fit. ```r library(DoseFinding) data(biom) # First-stage ANOVA fit anMod <- lm(resp ~ factor(dose) - 1, data = biom) drFit <- coef(anMod) S <- vcov(anMod) dose <- sort(unique(biom$dose)) # Bayesian Emax model fit prior <- list( norm = c(0, 10), # E0: N(0, 10) norm = c(0, 100), # Emax: N(0, 100) beta = c(0, 1.5, 0.45, 1.7) # ED50: Beta on [0, 1.5] ) gsample <- bFitMod(dose, drFit, S, model = "emax", start = c(0, 1, 0.1), nSim = 2000, prior = prior) gsample head(gsample$samples) # raw MCMC samples (nSim x n_params) # Posterior quantiles at specified doses predict(gsample, doseSeq = c(0, 0.2, 0.5, 1)) # Posterior distribution of TD (target dose) TD(gsample, Delta = 0.2) # returns a vector of nSim TD samples # Plot posterior bands plot(gsample) # Bootstrap approach gsample_bs <- bFitMod(dose, drFit, S, model = "emax", type = "bootstrap", nSim = 500, bnds = defBnds(1)$emax) plot(gsample_bs) ``` -------------------------------- ### Bayesian Multiple Contrast Test (bMCTtest) Source: https://context7.com/openpharma/dosefinding/llms.txt Implements the Bayesian MCP-Mod multiple contrast test. Requires RBesT package. The threshold can be derived from a frequentist alpha level or supplied directly. ```r library(DoseFinding) if (require("RBesT")) { data(biom) doses <- c(0, 0.05, 0.2, 0.6, 1) modlist <- Mods(emax = 0.05, linear = NULL, logistic = c(0.5, 0.1), linInt = c(0, 1, 1, 1), doses = doses) # Informative prior for placebo, vague for all active doses plc_prior <- mixnorm(inf = c(0.8, 0.4, 0.1), rob = c(0.2, 0.4, 10)) vague_prior <- mixnorm(c(1, 0, 10)) prior <- list(plc_prior, vague_prior, vague_prior, vague_prior, vague_prior) # Run Bayesian MCT test (threshold derived from frequentist alpha=0.025) m1 <- bMCTtest(dose, resp, biom, models = modlist, prior = prior) print(m1) # Supply threshold directly m2 <- bMCTtest(dose, resp, biom, models = modlist, prior = prior, critV = 0.99) } ``` -------------------------------- ### Define Candidate Dose-Response Models with Mods() Source: https://context7.com/openpharma/dosefinding/llms.txt Creates a 'Mods' object to define a set of candidate dose-response shapes. Standardized or full model parameters can be supplied. Use this to set up models for further analysis. ```R library(DoseFinding) doses <- c(0, 10, 25, 50, 100, 150) # Define a candidate set with multiple model shapes models <- Mods( linear = NULL, emax = 25, # ED50 guesstimate logistic = c(50, 10.88111), # ED50, delta exponential = 85, # delta betaMod = rbind(c(0.33, 2.31), c(1.39, 1.39)), # two betaMod shapes linInt = rbind(c(0, 1, 1, 1, 1), c(0, 0, 1, 1, 0.8)), # piecewise-linear shapes doses = doses, placEff = 0, maxEff = 0.4, addArgs = list(scal = 200) # fixed scal for betaMod ) # Plot all candidate models (lattice) plot(models) # Plot using ggplot2 plotMods(models) # Extract mean responses at selected doses getResp(models, doses = c(0, 25, 100, 150)) #> #> linear emax logistic exponential betaMod1 ... #> dose=0 0.000 0.000 0.000 0.000 0.000 #> dose=25 0.067 0.250 0.082 0.041 0.289 #> dose=100 0.267 0.360 0.379 0.288 0.393 #> dose=150 0.400 0.375 0.400 0.400 0.340 # Target dose: smallest dose achieving an improvement of 0.3 over placebo TD(models, Delta = 0.3) #> #> linear emax logistic exponential betaMod1 betaMod2 linInt1 linInt2 #> 112.50 62.50 88.52 130.27 62.14 62.14 25.00 50.00 # Effective dose: dose giving 50% of the maximum effect ED(models, p = 0.5) ``` -------------------------------- ### Compute guesstimates for model parameters using guesst() Source: https://context7.com/openpharma/dosefinding/llms.txt Use `guesst()` to translate clinical knowledge into nonlinear model parameters. It supports Emax, logistic, and beta models, taking dose-effect pairs as input. The output can be used to build and plot candidate models with `Mods()`. ```r library(DoseFinding) # Emax: expect 80% of max effect at dose 0.3 emx <- guesst(d = 0.3, p = 0.8, model = "emax") # Verify: emax(0.3, 0, 1, emx) should be close to 0.8 emax(0.3, 0, 1, emx) ``` ```r # Logistic model: two (dose, effect%) pairs lgc <- guesst(d = c(0.2, 0.6), p = c(0.2, 0.95), model = "logistic") ``` ```r # Beta model: one pair + location of maximum bta <- guesst(d = 0.4, p = 0.8, model = "betaMod", dMax = 0.8, scal = 1.2, Maxd = 1) ``` ```r # Build and plot candidate set from guesstimates models <- Mods(emax = emx, logistic = rbind(lgc), betaMod = bta, doses = c(0, 0.2, 0.4, 0.6, 0.8, 1), addArgs = list(scal = 1.2)) plot(models) ``` -------------------------------- ### Perform MCP-Mod Procedure with MCPMod Source: https://context7.com/openpharma/dosefinding/llms.txt Execute the complete MCP-Mod procedure, including multiple contrast testing, shape selection, dose-response model fitting, model selection, and target dose estimation. Returns an MCPMod object. ```r library(DoseFinding) data(biom) models <- Mods(linear = NULL, emax = c(0.05, 0.2), linInt = c(1, 1, 1, 1), doses = c(0, 0.05, 0.2, 0.6, 1)) # Full MCP-Mod (AIC model selection, TD estimation) MM <- MCPMod(dose, resp, biom, models, Delta = 0.5) summary(MM) # Predictions from all significant models predict(MM, se.fit = TRUE, doseSeq = c(0, 0.2, 0.4, 0.9, 1), predType = "ls-means") # Plot all fitted models plot(MM, plotData = "meansCI", CI = TRUE) # Model averaging via aveAIC weights MM2 <- MCPMod(dose, resp, biom, models, Delta = 0.5, selModel = "aveAIC") sq <- seq(0, 1, length = 11) pred <- predict(MM2, doseSeq = sq, predType = "ls-means") modWeights <- MM2$selMod pred_avg <- do.call("cbind", pred) %*% modWeights # model-averaged predictions TDEst <- MM2$doseEst %*% modWeights # model-averaged dose estimate # Two-stage approach (placebo-adjusted estimates from ANCOVA) data(IBScovars) anovaMod <- lm(resp ~ factor(dose) + gender, data = IBScovars) drFit <- coef(anovaMod)[2:5] vCov <- vcov(anovaMod)[2:5, 2:5] dose2 <- sort(unique(IBScovars$dose))[-1] models2 <- Mods(emax = c(0.5, 1), betaMod = c(1, 1), doses = c(0, 4)) MM3 <- MCPMod(dose2, drFit, S = vCov, models = models2, type = "general", placAdj = TRUE, Delta = 0.2) ``` -------------------------------- ### MCPMod() Source: https://context7.com/openpharma/dosefinding/llms.txt Performs the complete MCP-Mod procedure, including multiple contrast testing, selection of significant shapes, fitting of dose-response models, model selection, and target dose estimation. Returns an MCPMod object. ```APIDOC ## MCPMod() — Full MCP-Mod procedure (testing + modeling) ### Description Performs the complete MCP-Mod procedure: multiple contrast testing, selection of significant shapes, fitting of dose-response models to those shapes, model selection, and target dose estimation. Returns an `MCPMod` object. ### Example Usage ```r library(DoseFinding) data(biom) models <- Mods(linear = NULL, emax = c(0.05, 0.2), linInt = c(1, 1, 1, 1), doses = c(0, 0.05, 0.2, 0.6, 1)) # Full MCP-Mod (AIC model selection, TD estimation) MM <- MCPMod(dose, resp, biom, models, Delta = 0.5) summary(MM) # Predictions from all significant models predict(MM, se.fit = TRUE, doseSeq = c(0, 0.2, 0.4, 0.9, 1), predType = "ls-means") # Plot all fitted models plot(MM, plotData = "meansCI", CI = TRUE) # Model averaging via aveAIC weights MM2 <- MCPMod(dose, resp, biom, models, Delta = 0.5, selModel = "aveAIC") sq <- seq(0, 1, length = 11) pred <- predict(MM2, doseSeq = sq, predType = "ls-means") modWeights <- MM2$selMod pred_avg <- do.call("cbind", pred) %*% modWeights # model-averaged predictions TDEst <- MM2$doseEst %*% modWeights # model-averaged dose estimate # Two-stage approach (placebo-adjusted estimates from ANCOVA) data(IBScovars) anovaMod <- lm(resp ~ factor(dose) + gender, data = IBScovars) drFit <- coef(anovaMod)[2:5] vCov <- vcov(anovaMod)[2:5, 2:5] dose2 <- sort(unique(IBScovars$dose))[-1] models2 <- Mods(emax = c(0.5, 1), betaMod = c(1, 1), doses = c(0, 4)) MM3 <- MCPMod(dose2, drFit, S = vCov, models = models2, type = "general", placAdj = TRUE, Delta = 0.2) ``` ``` -------------------------------- ### Calculate Conditional/Predictive Power with powMCTInterim() Source: https://context7.com/openpharma/dosefinding/llms.txt Calculates conditional or predictive power for multiple contrast tests using interim data. Useful for futility analyses or when only partial data is available. ```r library(DoseFinding) doses <- c(0, 0.5, 1, 2, 4, 8) mods <- Mods(emax = c(0.5, 1, 2, 4), sigEmax = rbind(c(0.5, 3), c(1, 3), c(2, 3), c(4, 3)), quadratic = -0.1, doses = doses) w <- c(1, 0.5, 0.5, 0.5, 1, 1) contMat <- optContr(mods, w = w)$contMat sigma <- 0.3 n_final <- round(531 * w / sum(w)) n <- floor(n_final / 2) S_0t <- diag(sigma^2 / n) # interim covariance S_01 <- diag(sigma^2 / n_final) # final covariance mu_0t <- 0.05 * doses / (doses + 1) + rnorm(6, 0, sigma / sqrt(n)) mu_assumed <- 0.135 * doses / (doses + 1) # Predictive power (flat prior over second-stage data) powMCTInterim(contMat = contMat, S_0t = S_0t, S_01 = S_01, mu_0t = mu_0t, type = "predictive") # Conditional power (assuming mu_assumed for second stage) powMCTInterim(contMat = contMat, S_0t = S_0t, S_01 = S_01, mu_0t = mu_0t, type = "conditional", mu_assumed = mu_assumed) ``` -------------------------------- ### optContr() Source: https://context7.com/openpharma/dosefinding/llms.txt Computes optimal contrast coefficients for detecting specified dose-response alternatives. It supports sample size weights or a covariance matrix, and can handle constrained contrasts and placebo-adjusted formulations. ```APIDOC ## optContr() — Calculate optimal contrast vectors ### Description Computes contrast coefficients that are optimal (maximize the non-centrality parameter) for detecting specified dose-response alternatives. Accepts either sample size weights (`w`) or a covariance matrix (`S`). Also supports constrained contrasts and placebo-adjusted formulations. ### Example Usage ```r library(DoseFinding) doses <- c(0, 10, 25, 50, 100, 150) models <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, betaMod = rbind(c(0.33, 2.31), c(1.39, 1.39)), doses = doses, addArgs = list(scal = 200)) # Equal group sizes (balanced design) contMat <- optContr(models, w = rep(50, 6)) print(contMat) # Placebo-adjusted contrasts (for two-stage general approach) dosPlac <- doses[-1] S <- diag(5) + matrix(1, 5, 5) # proportional to cov-matrix contMat0 <- optContr(models, doses = dosPlac, S = S, placAdj = TRUE) colSums(contMat0$contMat) # columns do NOT sum to 0 (by design) ``` ``` -------------------------------- ### Configure R Markdown Vignette Settings Source: https://github.com/openpharma/dosefinding/blob/master/vignettes/children/settings.txt Sets up knitr chunk options for rendering vignettes, including graphics device, resolution, and figure aspect ratio. Also sets the default ggplot2 theme. ```r library(ggplot2) knitr::opts_chunk$set(echo = TRUE, message = FALSE, cache = FALSE, comment = NA, dev = "png", dpi = 150, fig.asp = 0.618, fig.width = 7, out.width = "85%", fig.align = "center") options(rmarkdown.html_vignette.check_title = FALSE) theme_set(theme_bw()) ``` -------------------------------- ### guesst() — Compute guesstimates for model parameters Source: https://context7.com/openpharma/dosefinding/llms.txt Computes nonlinear model parameter estimates from prior knowledge expressed as expected percentages of maximum effect at specific doses. This function helps translate clinical knowledge into model parameters for use in Mods(). ```APIDOC ## guesst() ### Description Computes the nonlinear model parameter θ₂ from prior knowledge expressed as expected percentages of the maximum effect at specific doses. This helps practitioners translate clinical knowledge into model parameters for use in `Mods()`. ### Usage ```r guesst(d, p, model, dMax, scal, Maxd) ``` ### Parameters * **d** (numeric or numeric vector) - Dose(s). * **p** (numeric or numeric vector) - Expected percentage(s) of maximum effect at the given dose(s). * **model** (character) - The name of the dose-response model. * **dMax** (numeric, optional) - Maximum dose for beta models. * **scal** (numeric, optional) - Scaling parameter for beta models. * **Maxd** (numeric, optional) - Dose at which maximum effect is achieved for beta models. ### Examples ```r # Emax model: expect 80% of max effect at dose 0.3 emx <- guesst(d = 0.3, p = 0.8, model = "emax") # Logistic model: two (dose, effect%) pairs lgc <- guesst(d = c(0.2, 0.6), p = c(0.2, 0.95), model = "logistic") # Beta model: one pair + location of maximum bta <- guesst(d = 0.4, p = 0.8, model = "betaMod", dMax = 0.8, scal = 1.2, Maxd = 1) ``` ``` -------------------------------- ### Visualize Power Curves with powN() Source: https://context7.com/openpharma/dosefinding/llms.txt Evaluates power or any scalar target function over a range of sample sizes to visualize power curves. Useful for study design planning. ```r library(DoseFinding) fmodels <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, doses = c(0, 10, 25, 50, 100, 150), placEff = 0, maxEff = 0.4, addArgs = list(scal = 200)) contMat <- optContr(fmodels, w = 1) # Power for each model + min/mean/max across n=10,...,100 pVsN <- powN(upperN = 100, lowerN = 10, step = 10, contMat = contMat, sigma = 1, altModels = fmodels, alpha = 0.05, alRatio = rep(1, 6)) # Trellis/lattice plot of power curves plot(pVsN, superpose = TRUE, line.at = 0.8) ``` -------------------------------- ### Perform Multiple Contrast Test with MCTtest() Source: https://context7.com/openpharma/dosefinding/llms.txt Performs the multiple contrast test (MCT) to detect a dose-response signal. Supports standard ANCOVA ('normal') and a general formulation for non-normal endpoints ('general'). Use this to test for dose-response effects. ```R library(DoseFinding) data(biom) # built-in dataset: 100 patients, doses 0, 0.05, 0.2, 0.6, 1 # Define candidate models modlist <- Mods(emax = 0.05, linear = NULL, logistic = c(0.5, 0.1), linInt = c(0, 1, 1, 1), doses = c(0, 0.05, 0.2, 0.6, 1)) # Standard normal-ANCOVA test m1 <- MCTtest(dose, resp, biom, models = modlist) print(m1) #> #> Multiple Contrast Test #> Contrasts: #> emax linear logistic linInt #> dose=0.00 -0.616 -0.447 -0.556 -0.447 #> ... #> Multiple Contrast Test: #> t-Stat adj-p #> linInt 3.453 0.002 #> emax 3.310 0.003 #> ... # With covariates data(IBScovars) modlist2 <- Mods(emax = 0.05, linear = NULL, doses = c(0, 1, 2, 3, 4)) MCTtest(dose, resp, IBScovars, models = modlist2, addCovars = ~gender) # General approach: supply pre-computed estimates and covariance matrix ancMod <- lm(resp ~ factor(dose) + gender, data = IBScovars) drEst <- coef(ancMod)[2:5] # placebo-adjusted estimates vc <- vcov(ancMod)[2:5, 2:5] MCTtest(1:4, drEst, S = vc, models = modlist2, placAdj = TRUE, type = "general", df = Inf) # Retrieve multiplicity-adjusted p-values attr(m1$tStat, "pVal") ``` -------------------------------- ### planMod() — Evaluate operating characteristics of a design Source: https://context7.com/openpharma/dosefinding/llms.txt Evaluates performance metrics for a model-based dose-response analysis under different true scenarios, including RMSE for dose-response curve estimation, power to detect an effect at the top dose, and probability of correctly identifying the EDp. Uses either asymptotic approximations or simulation. ```APIDOC ## planMod() ### Description Evaluates performance metrics for a model-based dose-response analysis under different true scenarios: RMSE for dose-response curve estimation, power to detect an effect at the top dose, and probability of correctly identifying the EDp. Uses either asymptotic approximations or simulation. ### Usage ```r planMod(model, altModels, n, sigma, doses, asyApprox, simulation) ``` ### Parameters * **model** (character) - The name of the candidate model. * **altModels** (list or object) - A list of alternative models to compare against. * **n** (numeric) - Sample size. * **sigma** (numeric) - Standard deviation of the error term. * **doses** (numeric vector) - The doses to be used in the study. * **asyApprox** (logical) - Whether to use asymptotic approximation. * **simulation** (logical) - Whether to perform simulation. ### Examples ```r doses <- c(0, 10, 25, 50, 100, 150) fmodels <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, doses = doses, addArgs = list(scal = 200), placEff = 0, maxEff = 0.4) # Asymptotic approximation (single model, fast) plan <- planMod(model = "emax", altModels = fmodels, n = 50, sigma = 1, doses = doses, asyApprox = TRUE, simulation = FALSE) print(plan) # dRMSE, Pow(maxDose), P(EDp) summary(plan) # additional cRMSE, Eff-vs-ANOVA metrics plot(plan) ``` ``` -------------------------------- ### defBnds() — Default bounds for non-linear model parameters Source: https://context7.com/openpharma/dosefinding/llms.txt Returns a list of reasonable lower and upper bounds for the nonlinear parameters of each built-in model, scaled to the maximum dose in the study. These bounds are used internally by fitMod(), MCPMod(), and bFitMod(). ```APIDOC ## defBnds() ### Description Returns a list of reasonable lower/upper bounds for the nonlinear parameters of each built-in model, scaled to the maximum dose in the study. These bounds are used internally by `fitMod()`, `MCPMod()`, and `bFitMod()`. ### Usage ```r defBnds(mD, model) ``` ### Parameters * **mD** (numeric) - Maximum dose in the study. * **model** (character, optional) - The name of the model for which to get bounds. If NULL, bounds for all models are returned. ### Examples ```r # Bounds for a study with maximum dose 200 bnds <- defBnds(mD = 200) bnds$emax # c(0.2, 300) — bounds for ED50 bnds$logistic # 2x2 matrix: rows = ED50, delta bnds$sigEmax bnds$exponential bnds$betaMod ``` ``` -------------------------------- ### Calculate Optimal Contrast Vectors with optContr Source: https://context7.com/openpharma/dosefinding/llms.txt Use optContr to compute contrast coefficients that are optimal for detecting specified dose-response alternatives. It accepts sample size weights (w) or a covariance matrix (S) and supports constrained contrasts and placebo-adjusted formulations. ```r library(DoseFinding) doses <- c(0, 10, 25, 50, 100, 150) models <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, betaMod = rbind(c(0.33, 2.31), c(1.39, 1.39)), doses = doses, addArgs = list(scal = 200)) # Equal group sizes (balanced design) contMat <- optContr(models, w = rep(50, 6)) print(contMat) #> Optimal contrasts #> linear emax logistic exponential betaMod1 betaMod2 #> dose=0 -0.408 -0.342 -0.378 -0.289 -0.342 -0.342 #> ... # Plot contrasts (lattice) plot(contMat) # Plot using ggplot2 plotContr(contMat) # Placebo-adjusted contrasts (for two-stage general approach) dosPlac <- doses[-1] S <- diag(5) + matrix(1, 5, 5) # proportional to cov-matrix contMat0 <- optContr(models, doses = dosPlac, S = S, placAdj = TRUE) colSums(contMat0$contMat) # columns do NOT sum to 0 (by design) ``` -------------------------------- ### fitMod() Source: https://context7.com/openpharma/dosefinding/llms.txt Fits a non-linear dose-response model to observed data using ordinary or generalized least squares. Supports various built-in models and returns a DRMod object with methods for coefficients, variance-covariance, prediction, plotting, and model fit statistics. ```APIDOC ## fitMod() — Fit a non-linear dose-response model ### Description Fits one of the built-in dose-response models ("linear", "quadratic", "emax", "sigEmax", "logistic", "exponential", "betaMod", "linlog", "linInt") to observed data via ordinary or generalized least squares. Returns a `DRMod` object with `coef`, `vcov`, `predict`, `plot`, `AIC`, and `logLik` methods. ### Example Usage ```r library(DoseFinding) data(IBScovars) # Fit Emax model (normal OLS) fitemax <- fitMod(dose, resp, data = IBScovars, model = "emax", bnds = c(0.01, 4)) summary(fitemax) # Predictions with standard errors predict(fitemax, predType = "ls-means", doseSeq = c(0, 1, 2, 4), se.fit = TRUE) # Target dose from fitted model TD(fitemax, Delta = 0.2) ED(fitemax, p = 0.5) # Plot with confidence band and dose-group means+CIs plot(fitemax, plotData = "meansCI", CI = TRUE) # General approach for binary data (two-stage) data(migraine) PFrate <- migraine$painfree / migraine$ntrt doseVec <- migraine$dose fitBin <- glm(PFrate ~ as.factor(doseVec) - 1, family = binomial, weights = migraine$ntrt) gEst <- coef(fitBin) vCov <- vcov(fitBin) gfit <- fitMod(doseVec, gEst, S = vCov, model = "emax", bnds = c(0, 100), type = "general") gAIC(gfit) # Include covariate fitemax2 <- fitMod(dose, resp, data = IBScovars, model = "emax", addCovars = ~gender, bnds = c(0.01, 4)) AIC(fitemax2) ``` ``` -------------------------------- ### Fit Dose-Response Models with fitMod Source: https://context7.com/openpharma/dosefinding/llms.txt Fit various dose-response models to observed data using ordinary or generalized least squares. The function returns a DRMod object with methods for coefficients, variance-covariance, prediction, plotting, and model fit statistics. ```r library(DoseFinding) data(IBScovars) # Fit Emax model (normal OLS) fitemax <- fitMod(dose, resp, data = IBScovars, model = "emax", bnds = c(0.01, 4)) summary(fitemax) #> Dose Response Model #> Model: emax Fit-type: normal #> Coefficients with approx. stand. error: #> Estimate Std. Error #> e0 0.372 0.059 #> eMax 0.451 0.118 #> ed50 0.789 0.380 coef(fitemax) vcov(fitemax) # Predictions with standard errors predict(fitemax, predType = "ls-means", doseSeq = c(0, 1, 2, 4), se.fit = TRUE) # Target dose from fitted model TD(fitemax, Delta = 0.2) ED(fitemax, p = 0.5) # Plot with confidence band and dose-group means+CIs plot(fitemax, plotData = "meansCI", CI = TRUE) # General approach for binary data (two-stage) data(migraine) PFrate <- migraine$painfree / migraine$ntrt doseVec <- migraine$dose fitBin <- glm(PFrate ~ as.factor(doseVec) - 1, family = binomial, weights = migraine$ntrt) drEst <- coef(fitBin) vCov <- vcov(fitBin) gfit <- fitMod(doseVec, drEst, S = vCov, model = "emax", bnds = c(0, 100), type = "general") gAIC(gfit) # Include covariate fitemax2 <- fitMod(dose, resp, data = IBScovars, model = "emax", addCovars = ~gender, bnds = c(0.01, 4)) AIC(fitemax2) ``` -------------------------------- ### Bootstrap Model Averaging (maFitMod) Source: https://context7.com/openpharma/dosefinding/llms.txt Fits dose-response models using a bagging (bootstrap model averaging) approach. Selects the best-fitting model by gAIC for each bootstrap sample. Supports predict, plot, TD, and ED methods. ```r library(DoseFinding) data(biom) anMod <- lm(resp ~ factor(dose) - 1, data = biom) drFit <- coef(anMod) S <- vcov(anMod) dose <- sort(unique(biom$dose)) mFit <- maFitMod(dose, drFit, S, models = c("emax", "sigEmax", "linear"), nSim = 500) mFit # Median prediction across bootstrap models plot(mFit, plotData = "meansCI") # Effective dose (p=0.9) using median ensemble prediction ED(mFit, direction = "increasing", p = 0.9) ``` -------------------------------- ### Calculate Optimal Experimental Design with optDesign() Source: https://context7.com/openpharma/dosefinding/llms.txt Calculates D-optimal or TD-optimal experimental designs for estimating dose-response model parameters or target doses. It determines optimal allocation weights to candidate doses. ```r library(DoseFinding) doses <- c(0, 10, 25, 50, 100, 150) models <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, doses = doses, addArgs = list(scal = 200), placEff = 0, maxEff = 0.4) # Equal model probabilities probs <- rep(1/5, 5) # D-optimal design (maximize determinant of information matrix) des_D <- optDesign(models, probs = probs, designCrit = "Dopt") des_D ``` ```r # TD-optimal design des_TD <- optDesign(models, probs = probs, designCrit = "TD", Delta = 0.3) # Mixture of D-optimal and TD-optimal des_mix <- optDesign(models, probs = probs, designCrit = "Dopt&TD", Delta = 0.3) # Plot design overlaid on candidate models plot(des_D, models) # Round to finite sample size (total N=150) rndDesign(des_D, n = 150) ``` -------------------------------- ### Power of Multiple Contrast Test (powMCT) Source: https://context7.com/openpharma/dosefinding/llms.txt Calculates the power to detect a dose-response signal for a given contrast matrix, sample size, and standard deviation. Supports normal balanced/unbalanced designs or general covariance matrices. ```r library(DoseFinding) doses <- c(0, 10, 25, 50, 100, 150) fmodels <- Mods(linear = NULL, emax = 25, logistic = c(50, 10.88111), exponential = 85, betaMod = rbind(c(0.33, 2.31), c(1.39, 1.39)), doses = doses, addArgs = list(scal = 200), placEff = 0, maxEff = 0.4) contMat <- optContr(fmodels, w = 1) # Power for balanced design, 50 patients/arm, sigma=1 powMCT(contMat, altModels = fmodels, n = 50, alpha = 0.05, sigma = 1) #> linear emax logistic exponential betaMod1 betaMod2 #> 0.872 0.913 0.878 0.769 0.911 0.902 # Power using a general covariance matrix S <- diag(6) / 50 powMCT(contMat, altModels = fmodels, S = S, alpha = 0.05, df = 6*50 - 6) ``` -------------------------------- ### Calculate Optimal Designs for Dose Estimation Source: https://github.com/openpharma/dosefinding/blob/master/README.md Calculates optimal designs for target dose (TD) estimation using specified dose levels and candidate models. The plot function can visualize these designs, and optDesign computes the optimal allocation of subjects. ```r ## Calculate optimal designs for target dose (TD) estimation doses <- c(0, 10, 25, 50, 100, 150) fmodels <- Mods(linear = NULL, emax = 25, exponential = 85, logistic = c(50, 10.8811), doses = doses, placEff=0, maxEff=0.4) plot(fmodels, plotTD = TRUE, Delta = 0.2) weights <- rep(1/4, 4) optDesign(fmodels, weights, Delta=0.2, designCrit="TD") ``` -------------------------------- ### Fit Non-linear Emax Dose-Response Model Source: https://github.com/openpharma/dosefinding/blob/master/README.md Fits a non-linear Emax dose-response model to the data. The function fitMod is used for this purpose, and the results can be visualized with plot, including confidence intervals and data means. ```r ## fit non-linear emax dose-response model fitemax <- fitMod(dose, resp, data=IBScovars, model="emax", bnds = c(0.01,5)) ## display fitted dose-effect curve plot(fitemax, CI=TRUE, plotData="meansCI") ```