| Title: | Fitting a Log-Binomial Model Using the Bekhit–Schöpe–Wagenpfeil (BSW) Algorithm |
|---|---|
| Description: | Implements a modified Newton-type algorithm (BSW algorithm) for solving the maximum likelihood estimation problem in fitting a log-binomial model under linear inequality constraints. |
| Authors: | Adam Bekhit [aut], Jakob Schöpe [aut], Thomas Wolf [aut] (ORCID: <https://orcid.org/0009-0004-9532-1487>), Julius Johannes Weise [aut, cre] (ORCID: <https://orcid.org/0000-0002-0908-5579>), Stefan Wagenpfeil [aut] (ORCID: <https://orcid.org/0000-0002-4558-4041>) |
| Maintainer: | Julius Johannes Weise <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.2 |
| Built: | 2026-06-04 08:46:01 UTC |
| Source: | https://github.com/uds-mf-imbei/bsw |
bsw()
bootbsw() applies nonparametric bootstrapping to an object of class "bsw"
and computes bias-corrected accelerated confidence intervals (BCa) for the estimated Relative Risk.
bootbsw(object, ci_level = 0.95, R = 1000L, maxit = NULL, conswitch = NULL)bootbsw(object, ci_level = 0.95, R = 1000L, maxit = NULL, conswitch = NULL)
object |
An object of the class |
ci_level |
A value between 0 and 1 indicating the confidence interval.
Provides bias-corrected accelerated bootstrap confidence intervals
of the original estimated model parameters of |
R |
A positive integer greater than or equal to 1000 giving the number of bootstrap replicates. |
maxit |
A positive integer giving the maximum number of iterations in the |
conswitch |
Specifies how the constraint matrix is constructed:
If |
An object of class "bsw_boot", which is a list containing:
The original call to the bsw() function used to fit the model.
The number of bootstrap replicates that were completed successfully.
A character string with a status message indicating how many bootstrap samples succeeded.
A matrix with the original estimated model parameters (Orig. Est.), the mean of the bootstrap estimates (Boot. Est.), the standard error of the bootstrap estimates (Boot. SE), the difference between the bootstrap mean and the original estimate (bias), the Risk Difference (equal to the estimate; RD), and the bias-corrected accelerated confidence intervals at the specified level.
An object of class "boot" (from the boot package) containing the full bootstrap output,
including replicates and metadata. This can be used for further analyses or plotting.
Julius Johannes Weise, Thomas Wolf, Stefan Wagenpfeil
set.seed(123) x <- rnorm(100, 50, 10) y <- rbinom(100, 1, exp(-4 + x * 0.04)) fit <- bsw(formula = y ~ x, data = data.frame(y = y, x = x)) result <- bootbsw(fit, ci_level = 0.90) print(result)set.seed(123) x <- rnorm(100, 50, 10) y <- rbinom(100, 1, exp(-4 + x * 0.04)) fit <- bsw(formula = y ~ x, data = data.frame(y = y, x = x)) result <- bootbsw(fit, ci_level = 0.90) print(result)
bsw() fits a log-binomial model using a modified Newton-type algorithm (BSW algorithm) for solving the maximum likelihood estimation problem under linear inequality constraints.
bsw(formula, data, maxit = 200L, conswitch = 1)bsw(formula, data, maxit = 200L, conswitch = 1)
formula |
An object of class |
data |
A data frame containing the variables in the model. |
maxit |
A positive integer giving the maximum number of iterations. |
conswitch |
Specifies how the constraint matrix is constructed:
|
An object of S4 class "bsw" containing the following slots:
call |
An object of class |
formula |
An object of class |
coefficients |
A numeric vector containing the estimated model parameters. |
iter |
A positive integer indicating the number of iterations. |
converged |
A logical constant that indicates whether the model has converged. |
y |
A numerical vector containing the dependent variable of the model. |
x |
The model matrix. |
data |
A data frame containing the variables in the model. |
Adam Bekhit, Jakob Schöpe
Wagenpfeil S (1996) Dynamische Modelle zur Ereignisanalyse. Herbert Utz Verlag Wissenschaft, Munich, Germany
Wagenpfeil S (1991) Implementierung eines SQP-Verfahrens mit dem Algorithmus von Ritter und Best. Diplomarbeit, TUM, Munich, Germany
set.seed(123) x <- rnorm(100, 50, 10) y <- rbinom(100, 1, exp(-4 + x * 0.04)) fit <- bsw(formula = y ~ x, conswitch = 1, data = data.frame(y = y, x = x)) summary(fit)set.seed(123) x <- rnorm(100, 50, 10) y <- rbinom(100, 1, exp(-4 + x * 0.04)) fit <- bsw(formula = y ~ x, conswitch = 1, data = data.frame(y = y, x = x)) summary(fit)
"bsw"
S4 Class "bsw"
callAn object of class "call".
formulaAn object of class "formula".
coefficientsA numeric vector containing the estimated model parameters.
iterA positive integer indicating the number of iterations.
convergedA logical constant that indicates whether the model has converged.
yA numeric vector containing the dependent variable of the model.
xThe model matrix.
dataA data frame containing the variables in the model.
Adam Bekhit, Jakob Schöpe
bsw()
For objects of class "bsw", coef() extracts the estimated model parameters of bsw().
## S4 method for signature 'bsw' coef(object)## S4 method for signature 'bsw' coef(object)
object |
An object of class |
A numeric vector containing the estimated model parameters.
Adam Bekhit, Jakob Schöpe
bsw()
For objects of class "bsw", confint() estimates confidence intervals of the estimated model parameters of bsw().
## S4 method for signature 'bsw' confint(object, parm, level = 0.95, method = "wald", R = 1000L)## S4 method for signature 'bsw' confint(object, parm, level = 0.95, method = "wald", R = 1000L)
object |
An object of class |
parm |
A specification of which model parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all model parameters are considered. |
level |
A numeric value that indicates the level of confidence. |
method |
A character giving the estimation method of the confidence intervals ( |
R |
A positive integer giving the number of bootstrap replicates. |
confint provides Wald (default) and bias-corrected accelerated bootstrap confidence intervals of the estimated model parameters of bsw().
A matrix with columns giving the lower and upper confidence limits of each estimated model parameter.
Adam Bekhit, Jakob Schöpe
bsw()
constr() sets the linear inequality constraints for bsw().
constr(x, version = 1)constr(x, version = 1)
x |
A model matrix. |
version |
switch for constraints |
A matrix containing the linear inequality constraints for bsw().
Adam Bekhit, Jakob Schöpe
bsw()
gradF() derives the first derivatives of the log likelihood function of the log-binomial model.
gradF(theta, y, x)gradF(theta, y, x)
theta |
A numeric vector containing the initial values of the model parameters. |
y |
A numeric vector containing the dependent variable of the model. |
x |
The model matrix. |
A numeric vector containing the first derivatives of the log likelihood function of the log-binomial model.
Adam Bekhit, Jakob Schöpe
bsw() (Hessian matrix)hess() derives the second partial derivatives of the log likelihood function of the log-binomial model.
hess(theta, y, x)hess(theta, y, x)
theta |
A numeric vector containing the initial values of the model parameters. |
y |
A numeric vector containing the dependent variable of the model. |
x |
The model matrix. |
A numeric matrix containing the second partial derivatives of the log likelihood function of the log-binomial model (Hessian matrix).
Adam Bekhit, Jakob Schöpe
bsw()
For objects of class "bsw", summary() summarizes the estimated model parameters of bsw().
## S4 method for signature 'bsw' summary(object)## S4 method for signature 'bsw' summary(object)
object |
An object of class |
A list containing the following elements:
coefficients |
A numeric vector containing the estimated model parameters. |
std.err |
A numeric vector containing the estimated standard errors of the model parameters. |
z.value |
A numeric vector containing the estimated z test statistic of the model parameters. |
p.value |
A numeric vector containing the estimated p values of the model parameters. |
Adam Bekhit, Jakob Schöpe
BSW()
Performs forward or backward variable selection based on Wald test p-values for models estimated using bsw().
In each step, a new model is fitted using bsw(), and variables are added or removed based on the significance level defined by alpha.
variable_selection_bsw(model, selection = c("backward", "forward"), alpha = 0.157, print_models = FALSE, maxit = NULL, conswitch = NULL)variable_selection_bsw(model, selection = c("backward", "forward"), alpha = 0.157, print_models = FALSE, maxit = NULL, conswitch = NULL)
model |
A model object from |
selection |
Character string, either |
alpha |
P-value threshold for variable inclusion (forward) or exclusion (backward). Defaults to 0.157, as recommended by Heinze, G., Wallisch, C., & Dunkler, D. (2018). |
print_models |
Logical; whether to print each model during selection. Defaults to FALSE. |
maxit |
Maximum number of iterations in the bsw() algorithm. If NULL, defaults to 200L or value from original model call. |
conswitch |
Specifies how the constraint matrix is constructed:
|
An object of class "bsw_selection", which is a list containing:
An object of class bsw representing the final model selected through the variable selection process.
A list of intermediate bsw model objects fitted during each step of the selection.
A named list of models that failed to converge and were skipped during the selection. Each entry includes the attempted formula.
The final model formula used in the last step.
Estimated events-per-variable (EPV) of the final model, used as a diagnostic for model stability.
Optional warning messages about convergence issues or model stability (e.g., low EPV or skipped variables).
Julius Johannes Weise, Thomas Wolf, Stefan Wagenpfeil
Heinze, G., Wallisch, C., & Dunkler, D. (2018). Variable selection – A review and recommendations for the practicing statistician. Biometrical Journal, 60(3), 431–449.
set.seed(123) x1 <- rnorm(500, 50, 10) x2 <- rnorm(500, 30, 5) x3 <- rnorm(500, 40, 8) x4 <- rnorm(500, 60, 12) logit <- (-4 + x1 * 0.04 + x3 * 0.04) p <- 1 / (1 + exp(-logit)) y <- rbinom(500, 1, p) df <- data.frame(y, x1, x2, x3, x4) fit <- bsw(formula = y ~ x1 + x2 + x3 + x4, data = df) result <- variable_selection_bsw(fit, selection = "forward", alpha = 0.1) print(result)set.seed(123) x1 <- rnorm(500, 50, 10) x2 <- rnorm(500, 30, 5) x3 <- rnorm(500, 40, 8) x4 <- rnorm(500, 60, 12) logit <- (-4 + x1 * 0.04 + x3 * 0.04) p <- 1 / (1 + exp(-logit)) y <- rbinom(500, 1, p) df <- data.frame(y, x1, x2, x3, x4) fit <- bsw(formula = y ~ x1 + x2 + x3 + x4, data = df) result <- variable_selection_bsw(fit, selection = "forward", alpha = 0.1) print(result)