Skip to content

Commit 5c19f49

Browse files
Merge pull request #35 from DoseResponse/devel
Version 2.7.4
2 parents 171419f + 7d29748 commit 5c19f49

228 files changed

Lines changed: 30957 additions & 1338 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

0 Bytes
Binary file not shown.

.Rbuildignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ cache/
44
README.Rmd
55
README.md
66
README_files/
7-
^\\.github$
7+
^\.github$
8+
docs/
9+
example_extracts/

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5-
cache/
5+
cache/
6+
bmd.Rproj
7+
inst/doc
8+
inst/dev
9+
example_extracts/

DESCRIPTION

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: bmd
22
Type: Package
33
Title: Benchmark dose estimation for dose-response data
4-
Version: 2.7.3
4+
Version: 2.7.4
55
Date: 2025-03-24
66
Author: Signe M.Jensen, Christian Ritz and Jens Riis Baalkilde
77
Maintainer: Signe M. Jensen <smj@plen.ku.dk>
@@ -25,14 +25,18 @@ Suggests:
2525
tidyr,
2626
numDeriv,
2727
drcData,
28-
testthat (>= 3.0.0)
28+
testthat (>= 3.0.0),
29+
knitr,
30+
rmarkdown
2931
Remotes:
3032
doseresponse/drc,
3133
doseresponse/drcData
3234
License: file LICENSE
3335
Encoding: UTF-8
3436
LazyData: true
3537
Config/testthat/edition: 3
38+
Roxygen: list(markdown = TRUE)
3639
RoxygenNote: 7.3.2
3740
Depends:
3841
R (>= 3.5)
42+
VignetteBuilder: knitr

NAMESPACE

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,78 @@
1-
import(drc, ggplot2, dplyr)
2-
importFrom("graphics", "lines")
3-
importFrom("stats", "aggregate", "approx", "as.formula", "coef",
4-
"complete.cases", "confint", "constrOptim", "df.residual",
5-
"dnorm", "fitted", "lm", "model.frame", "model.matrix",
6-
"optim", "pnorm", "predict", "qchisq", "qnorm", "qt",
7-
"quantile", "rbinom", "resid", "residuals", "rnorm", "sd",
8-
"uniroot", "update", "var", "vcov", "AIC", "BIC", "logLik")
9-
importFrom("utils", "setTxtProgressBar", "txtProgressBar")
10-
export(bmd, bmdBoot, bmdIso, bmdIsoBoot, PAV, bmdMA, bootDataGen, bmdMACurve, BCa, invBmd, expandBinomial,
11-
getStackingWeights, drmOrdinal, bmdOrdinal, bmdOrdinalMA,
12-
qplotDrc, qplotBmd, MACurve, monotonicityTest, trendTest, bmdHetVar, drmHetVar, drmMMRE, bmdHetVarMA)
1+
# Generated by roxygen2: do not edit by hand
132

14-
## S3 methods
15-
S3method(logLik, drcOrdinal)
16-
S3method(logLik, drcHetVar)
17-
S3method(AIC, drcOrdinal)
18-
S3method(AIC, drcHetVar)
19-
S3method(BIC, drcOrdinal)
20-
S3method(BIC, drcHetVar)
21-
S3method(plot, drcOrdinal)
22-
S3method(print, drcOrdinal)
23-
S3method(print, bmdOrdinal)
24-
S3method(print, drcHetVar)
25-
S3method(plot, bmd)
26-
S3method(plot, drcHetVar)
27-
S3method(vcov, drcMMRE)
28-
S3method(print, drcMMRE)
29-
S3method(coef, drcHetVar)
3+
S3method(AIC,drcHetVar)
4+
S3method(AIC,drcOrdinal)
5+
S3method(BIC,drcHetVar)
6+
S3method(BIC,drcOrdinal)
7+
S3method(coef,drcHetVar)
8+
S3method(logLik,drcHetVar)
9+
S3method(logLik,drcOrdinal)
10+
S3method(plot,bmd)
11+
S3method(plot,drcHetVar)
12+
S3method(plot,drcOrdinal)
13+
S3method(print,bmd)
14+
S3method(print,bmdHetVar)
15+
S3method(print,bmdOrdinal)
16+
S3method(print,drcHetVar)
17+
S3method(print,drcMMRE)
18+
S3method(print,drcOrdinal)
19+
S3method(vcov,drcMMRE)
20+
export(BCa)
21+
export(MACurve)
22+
export(PAV)
23+
export(bmd)
24+
export(bmdBoot)
25+
export(bmdHetVar)
26+
export(bmdHetVarMA)
27+
export(bmdIso)
28+
export(bmdIsoBoot)
29+
export(bmdMA)
30+
export(bmdMACurve)
31+
export(bmdOrdinal)
32+
export(bmdOrdinalMA)
33+
export(drmHetVar)
34+
export(drmMMRE)
35+
export(drmOrdinal)
36+
export(getStackingWeights)
37+
export(monotonicityTest)
38+
export(qplotBmd)
39+
export(qplotDrc)
40+
export(trendTest)
41+
import(dplyr)
42+
import(drc)
43+
import(ggplot2)
44+
importFrom(graphics,lines)
45+
importFrom(stats,AIC)
46+
importFrom(stats,BIC)
47+
importFrom(stats,aggregate)
48+
importFrom(stats,approx)
49+
importFrom(stats,as.formula)
50+
importFrom(stats,coef)
51+
importFrom(stats,complete.cases)
52+
importFrom(stats,confint)
53+
importFrom(stats,constrOptim)
54+
importFrom(stats,df.residual)
55+
importFrom(stats,dnorm)
56+
importFrom(stats,fitted)
57+
importFrom(stats,lm)
58+
importFrom(stats,logLik)
59+
importFrom(stats,model.frame)
60+
importFrom(stats,model.matrix)
61+
importFrom(stats,optim)
62+
importFrom(stats,pnorm)
63+
importFrom(stats,predict)
64+
importFrom(stats,qchisq)
65+
importFrom(stats,qnorm)
66+
importFrom(stats,qt)
67+
importFrom(stats,quantile)
68+
importFrom(stats,rbinom)
69+
importFrom(stats,resid)
70+
importFrom(stats,residuals)
71+
importFrom(stats,rnorm)
72+
importFrom(stats,sd)
73+
importFrom(stats,uniroot)
74+
importFrom(stats,update)
75+
importFrom(stats,var)
76+
importFrom(stats,vcov)
77+
importFrom(utils,setTxtProgressBar)
78+
importFrom(utils,txtProgressBar)

R/AIC.drcOrdinal.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2+
#' AIC Method for drcOrdinal Objects
3+
#'
4+
#' Calculates the Akaike Information Criterion for drcOrdinal model objects.
5+
#'
6+
#' @param object A drcOrdinal model object
7+
#' @param ... Additional arguments (not used)
8+
#' @param k The penalty per parameter to be used; default is 2
9+
#'
10+
#' @return The AIC value
11+
#' @export
112
AIC.drcOrdinal <- function(object, ..., k = 2) {
213
dots <- list(...)
314
if (!is.null(dots$epsilon)){
@@ -8,4 +19,4 @@ AIC.drcOrdinal <- function(object, ..., k = 2) {
819

920
n.parameters <- sum(sapply(object$drmList, function(mod) length(mod$coefficients)))
1021
-2 * logLik(object, epsilon = epsilon) + k * n.parameters
11-
}
22+
}

R/BCa.R

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,82 @@
1+
#' Calculate BCa (Bias-Corrected and Accelerated) Bootstrap Confidence Interval
2+
#'
3+
#' @description
4+
#' This function calculates the BCa confidence interval for a given statistic using bootstrap and jackknife estimates.
5+
#'
6+
#' @details
7+
#' It computes the BCa confidence interval for a statistic using bootstrap and jackknife estimates.
8+
#' The BCa method adjusts for both bias and skewness in the bootstrap distribution and generally
9+
#' provides better coverage than standard bootstrap confidence intervals.
10+
#'
11+
#' @param obs numeric; The observed value of the statistic computed from the original sample
12+
#' @param data data.frame or matrix; The original dataset from which bootstrap samples are drawn
13+
#' @param bootSample numeric vector; Bootstrap replicates of the statistic. Must be of length R
14+
#' where R is the number of bootstrap replicates
15+
#' @param bootjack numeric vector; Jackknife replicates of the statistic. Must be of length n
16+
#' where n is the number of observations in data
17+
#' @param level numeric; Confidence level between 0 and 1 (e.g., 0.95 for 95% confidence interval)
18+
#'
19+
#' @return A numeric vector of length 2 containing:
20+
#' \itemize{
21+
#' \item lower: The lower confidence limit
22+
#' \item upper: The upper confidence limit
23+
#' }
24+
#'
25+
#'
26+
#' @examples \dontrun{
27+
#' # Example with mean as the statistic
28+
#' data <- rnorm(100)
29+
#' obs_mean <- mean(data)
30+
#'
31+
#' # Generate bootstrap samples
32+
#' R <- 1000
33+
#' boot_means <- replicate(R, mean(sample(data, replace = TRUE)))
34+
#'
35+
#' # Generate jackknife samples
36+
#' jack_means <- sapply(1:length(data),
37+
#' function(i) mean(data[-i]))
38+
#'
39+
#' # Calculate 95% CI
40+
#' BCa(obs_mean, data, boot_means, jack_means, 0.95)
41+
#' }
42+
#'
43+
#' @references
44+
#' Efron, B. (1987). Better Bootstrap Confidence Intervals.
45+
#' _Journal of the American Statistical Association_, 82(397), 171-185.
46+
#'
47+
#' DiCiccio, T. J., & Efron, B. (1996). Bootstrap confidence intervals.
48+
#' _Statistical Science_, 11(3), 189-212.
49+
#'
50+
#' @export
151
BCa <- function(obs, data, bootSample, bootjack, level){
2-
R <- length(bootSample)
3-
b <- qnorm((sum(bootSample > obs)+sum(bootSample==obs)/2)/R)
52+
R <- length(bootSample)
53+
b <- qnorm((sum(bootSample > obs)+sum(bootSample==obs)/2)/R)
454

5-
n <- nrow(data)
6-
n1 <- n-1
7-
obsn <- obs*n
8-
pv <- i <- 0
9-
while(i < n){
10-
i = i+1
11-
pv[i] = obsn-n1*bootjack[i]
55+
n <- nrow(data)
56+
n1 <- n-1
57+
obsn <- obs*n
58+
pv <- i <- 0
59+
while(i < n){
60+
i = i+1
61+
pv[i] = obsn-n1*bootjack[i]
62+
}
63+
pv<-pv[!is.na(pv)]
64+
65+
je <- mean(pv)-pv
66+
a <- sum(je^3)/(6*sum(je^2))^(3/2)
67+
68+
alpha <- (1-level)*2
69+
z <- qnorm(c(alpha/2,1-alpha/2)) # Std. norm. limits
70+
p <- pnorm((z-b)/(1-a*(z-b))-b) # correct & convert to proportions
71+
72+
quantile(bootSample,p=p) # ABC percentile lims.
1273
}
13-
pv<-pv[!is.na(pv)]
1474

15-
je <- mean(pv)-pv
16-
a <- sum(je^3)/(6*sum(je^2))^(3/2)
1775

18-
alpha <- (1-level)*2
19-
z <- qnorm(c(alpha/2,1-alpha/2)) # Std. norm. limits
20-
p <- pnorm((z-b)/(1-a*(z-b))-b) # correct & convert to proportions
2176

22-
quantile(bootSample,p=p) # ABC percentile lims.
23-
}
77+
78+
79+
80+
2481

2582

R/BIC.drcOrdinal.R

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1+
#' BIC Method for drcOrdinal Objects
2+
#'
3+
#' @description
4+
#' S3 method to calculate the Bayesian Information Criterion (BIC) for fitted
5+
#' ordinal dose-response models. This method extends the generic `BIC()` function
6+
#' to handle `drcOrdinal` objects which contain multiple fitted dose-response models
7+
#' for different response categories.
8+
#'
9+
#' @param object An object of class "drcOrdinal" containing fitted ordinal
10+
#' dose-response models
11+
#' @param ... Additional arguments passed to the method. Currently supports:
12+
#' \itemize{
13+
#' \item \code{epsilon}: Small positive value to avoid log(0) in likelihood
14+
#' calculations (default: 1e-16)
15+
#' }
16+
#'
17+
#' @details
18+
#' The BIC is calculated using the standard formula:
19+
#' \deqn{BIC = k \log(n) - 2 \log(L)}{BIC = k * log(n) - 2 * log(L)}
20+
#' where:
21+
#' \itemize{
22+
#' \item \eqn{k}{k} is the total number of parameters across all models in the ordinal fit
23+
#' \item \eqn{n}{n} is the total number of observations (sum of weights)
24+
#' \item \eqn{L}{L} is the likelihood of the fitted model
25+
#' }
26+
#'
27+
#' For ordinal dose-response models, the total number of parameters is the sum
28+
#' of parameters from all individual models in the `drmList` component, and the
29+
#' sample size is calculated as the sum of weights in the data.
30+
#'
31+
#' The `epsilon` parameter is used in the `logLik()` calculation to prevent
32+
#' numerical issues when probabilities approach zero.
33+
#'
34+
#' @return A numeric value representing the BIC of the fitted ordinal dose-response model.
35+
#' Lower values indicate better model fit when comparing models.
36+
#'
37+
#' @section Model Comparison:
38+
#' BIC penalizes model complexity more heavily than AIC, making it useful for:
39+
#' \itemize{
40+
#' \item Comparing ordinal dose-response models with different numbers of parameters
41+
#' \item Model selection in situations where simpler models are preferred
42+
#' \item Avoiding overfitting in dose-response modeling
43+
#' }
44+
#'
45+
#' @note
46+
#' This method assumes that the `drcOrdinal` object contains:
47+
#' \itemize{
48+
#' \item A `drmList` component with fitted dose-response models
49+
#' \item A `data` component with the original data including weights
50+
#' \item A `weights` component specifying the column name for observation weights
51+
#' }
52+
#'
53+
#' @seealso
54+
#' \code{\link{BIC}} for the generic BIC function,
55+
#' \code{\link{AIC.drcOrdinal}} for the corresponding AIC method,
56+
#' \code{\link{logLik.drcOrdinal}} for the log-likelihood method
57+
#'
58+
#' @examples
59+
#' \dontrun{
60+
#' # Assuming you have a fitted drcOrdinal object
61+
#' ordinal_model <- drm(response ~ dose,
62+
#' weights = count,
63+
#' data = ordinal_data,
64+
#' fct = cumulative.logit())
65+
#'
66+
#' # Calculate BIC
67+
#' bic_value <- BIC(ordinal_model)
68+
#'
69+
#' # Compare models
70+
#' model1_bic <- BIC(ordinal_model1)
71+
#' model2_bic <- BIC(ordinal_model2)
72+
#'
73+
#' # Lower BIC indicates better model
74+
#' if(model1_bic < model2_bic) {
75+
#' cat("Model 1 is preferred\n")
76+
#' } else {
77+
#' cat("Model 2 is preferred\n")
78+
#' }
79+
#'
80+
#' # Use custom epsilon for numerical stability
81+
#' bic_custom <- BIC(ordinal_model, epsilon = 1e-12)
82+
#' }
83+
#'
84+
#' @method BIC drcOrdinal
85+
#' @export
186
BIC.drcOrdinal <- function(object, ...){
287
dots <- list(...)
388
if (!is.null(dots$epsilon)){

0 commit comments

Comments
 (0)