Computational Provenance & Reproducibility Record

RAISINS - R and AI Solutions for INferential Statistics · Online Statistical Analysis Platform for Agricultural Research

Computational Provenance & Reproducibility Record Binary Logistic Regression · 2.0.0 · DOI pending

Computational Provenance & Reproducibility Record

RAISINS · Binary Logistic Regression Module

This Computational Provenance Record documents the statistical computing environment, software dependencies, computational provenance, and bibliographic references associated with the RAISINS Binary Logistic Regression module. It is intended to support computational reproducibility and software transparency. Detailed statistical methodology, mathematical derivations, and user guidance are provided separately in the official module documentation.

Any issues or updates required please comment here

Go to the App from here

1 Module Metadata

Parameter Specification
Module Binary Logistic Regression
Module Version 2.0.0
DOI pending (Zenodo)
Document Type Computational workflow
Statistical Engine R
R Version 4.5.2
Reproducibility Execution Environment: Posit Connect · GCR · renv-locked

2 Statistical Dependency Manifest

Package Version Repository Core Statistical Functions
MASS 7.3-65 CRAN stepAIC()
car 3.1-5 CRAN vif()
pROC 1.19.0.1 CRAN roc(), auc(), plot.roc()
broom 1.0.13 CRAN augment() (diagnostic quantities)
stats 4.5.2 Base R glm(), summary(), fitted(), predict(), AIC(), logLik(), pchisq(), qnorm(), quantile(), plogis(), relevel()

3 Statistical Function Registry

Analytical Role Primary Function(s)
Model fitting stats::glm(family = binomial(link = "logit"))
Variable selection MASS::stepAIC()
Coefficient inference base::summary() (estimate, SE, Wald z, p-value)
Odds ratios & intervals exp(coef()); Wald 95% CI exp(β ± qnorm(0.975)·SE)
Model fit stats::AIC(); residual & null deviance; likelihood-ratio test via stats::pchisq()
Pseudo R² Cox & Snell, Nagelkerke, McFadden from stats::logLik()
Multicollinearity car::vif()
Goodness of fit Hosmer–Lemeshow decile-of-risk test (native implementation; stats::quantile(), stats::pchisq())
Linearity of the logit Box–Tidwell refit: glm(. ~ . + I(x·log(x))), Wald p of the added term
Influence diagnostics broom::augment() (.std.resid, .hat, .cooksd); stats::plogis() for predicted probabilities
Hold-out validation (ML mode) base::sample() split + stats::predict(type = "response"); confusion matrix via base::table(); accuracy, sensitivity, specificity, precision, F1 from its cells
Discrimination (ML mode) pROC::roc(levels = levels(y), direction = "<"), pROC::auc()

4 Default Methods & Parameters

Analysis Step / Parameter Default Method / Value
Model Fitting Method Binary logistic regression by maximum likelihood via glm() with binomial(link = "logit"); rows with missing values are removed listwise (na.omit()) before fitting
Outcome coding The dependent variable is coerced to a factor; the second factor level is the modelled event (R convention). The outcome must carry exactly two distinct values
Categorical predictors Character/logical predictors are converted to factors and dummy-coded; the reference level defaults to the first level and is user-adjustable (stats::relevel()), after which the model is refitted
Variable Selection Stepwise (optional) AIC-based MASS::stepAIC(trace = FALSE), backward elimination from the full model (the stepAIC default when no scope is supplied); the AIC trace and the final model are reported. Reported p-values and confidence intervals do not account for the selection step
Coefficient
Inference
Estimates Estimate (log-odds), standard error, Wald z value, and p-value from summary()
Significance Star codes at cut points 0.001 / 0.01 / 0.05 / 0.1
Odds ratios & intervals OR = exp(β); 95% Wald confidence intervals exp(β ± qnorm(0.975)·SE) (not profile-likelihood; chosen to match the Wald z-tests in the same table)
Model Fit Overall test Likelihood-ratio χ² = null deviance − residual deviance, df = dfnull − dfresidual, p from pchisq(lower.tail = FALSE); AIC and −2 log-likelihood (deviance) reported alongside
Pseudo R² Cox & Snell R² = 1 − exp{(2/n)(LL₀ − LLₓ)}; Nagelkerke R² = R²CS / {1 − exp((2/n)·LL₀)}; McFadden R² = 1 − LLₓ/LL₀
Model
Assumptions
Multicollinearity car::vif() on the fitted GLM; low < 5, moderate 5–10, high > 10
Goodness of fit Hosmer–Lemeshow decile-of-risk test with g = 10 groups from quantile(fitted(model)); duplicate breaks collapsed with unique(); df = groups − 2; reported as unavailable if fewer than 3 groups can be formed. p ≥ 0.05 indicates no evidence of poor fit
Linearity of the logit Box–Tidwell check for each continuous predictor with all values > 0: the model is refitted with an added I(x·log(x)) term and the Wald p-value of that term is reported; predictors with zero/negative values are reported as not testable
Influence
Diagnostics
Measures & thresholds From broom::augment(): standardized deviance residuals (|.| > 2 potential outlier, > 3 extreme), leverage (flag > 2p/n), Cook's distance (flag > 4/n); predicted probabilities via plogis(.fitted)
Hold-out
Validation

(ML mode, optional)
Split Random train/test split of the complete-case data; training fraction user-set, default 80%; set.seed(123) for reproducibility. The model is fitted on the training rows only
Classification Fixed threshold p̂ > 0.5 for the event class; confusion matrix via table(Observed, Predicted); accuracy = (TP+TN)/N, sensitivity = TP/(TP+FN), specificity = TN/(TN+FP), precision = TP/(TP+FP), F1 = 2·(precision·recall)/(precision+recall)
Discrimination ROC curve and AUC via pROC::roc(test_outcome, predicted_probabilities, levels = levels(outcome), direction = "<")

5 R Code for Key Analytical Steps

The code blocks below demonstrate the exact computation behind each reported result using the mtcars dataset from the datasets package (outcome am, transmission type; predictors mpg and wt).

5.1 Model Fitting and Variable Selection

dat <- transform(mtcars, am = factor(am))   # second level "1" = modelled event
model_full <- glm(am ~ mpg + wt, data = dat, family = binomial(link = "logit"))

# optional AIC-based stepwise selection (backward from the full model)
model <- MASS::stepAIC(model_full, trace = FALSE)
model$anova                                  # AIC trace
AIC(model_full); AIC(model)

5.2 Coefficients, Odds Ratios and Wald Intervals

sm <- summary(model)$coefficients   # estimate, std. error, z value, p-value
OR  <- exp(sm[, "Estimate"])        # odds ratios
LCI <- exp(sm[, "Estimate"] - qnorm(0.975) * sm[, "Std. Error"])
UCI <- exp(sm[, "Estimate"] + qnorm(0.975) * sm[, "Std. Error"])
cbind(sm, OR, LCI, UCI)

5.3 Model Fit Metrics

AIC(model)
c(deviance = model$deviance, null.deviance = model$null.deviance)

# likelihood-ratio test of the overall model
lr    <- model$null.deviance - model$deviance
lr_df <- model$df.null - model$df.residual
pchisq(lr, lr_df, lower.tail = FALSE)

# pseudo R-squared (Cox & Snell, Nagelkerke, McFadden)
ll_m <- as.numeric(logLik(model))
ll_0 <- as.numeric(logLik(update(model, . ~ 1)))
n    <- nobs(model)
R2_CS <- 1 - exp((2 / n) * (ll_0 - ll_m))
c(CoxSnell   = R2_CS,
  Nagelkerke = R2_CS / (1 - exp((2 / n) * ll_0)),
  McFadden   = 1 - ll_m / ll_0)

5.4 Model Assumption Checks

car::vif(model)                 # multicollinearity (VIF)

# Hosmer-Lemeshow goodness of fit (g = 10, decile-of-risk construction)
y  <- model$y
p  <- fitted(model)
qs <- unique(quantile(p, probs = seq(0, 1, length.out = 11)))
g  <- droplevels(cut(p, breaks = qs, include.lowest = TRUE))
n_g <- tapply(y, g, length); o1 <- tapply(y, g, sum); e1 <- tapply(p, g, sum)
chi <- sum((o1 - e1)^2 / e1 + ((n_g - o1) - (n_g - e1))^2 / (n_g - e1))
c(chisq = chi, df = nlevels(g) - 2,
  p = pchisq(chi, nlevels(g) - 2, lower.tail = FALSE))

# Box-Tidwell linearity of the logit (continuous predictors, all values > 0)
m_bt <- glm(am ~ mpg + wt + I(mpg * log(mpg)), data = dat, family = binomial)
summary(m_bt)$coefficients["I(mpg * log(mpg))", ]   # Wald p of the added term

5.5 Influence and Outlier Diagnostics

aug <- broom::augment(model)
n <- nobs(model); pn <- length(coef(model))
plogis(aug$.fitted)                 # predicted probability
aug$.std.resid                      # standardized deviance residuals (|.| > 2 / > 3)
aug$.hat                            # leverage        (flag > 2p/n)
aug$.cooksd                         # Cook's distance (flag > 4/n)

5.6 Hold-out Validation (Machine-Learning Mode)

df <- na.omit(transform(mtcars, am = factor(am)))
n  <- nrow(df)

set.seed(123)                              # reproducible split
train_pct <- 80                            # user-set, default 80
idx      <- sample(seq_len(n), size = floor((train_pct / 100) * n))
trainSet <- df[idx, ]
testSet  <- df[-idx, ]

fit   <- glm(am ~ mpg + wt, data = trainSet, family = binomial(link = "logit"))
probs <- predict(fit, newdata = testSet, type = "response")
lv    <- levels(df$am)
pred  <- factor(ifelse(probs > 0.5, lv[2], lv[1]), levels = lv)  # 0.5 threshold

cm <- table(Observed = testSet$am, Predicted = pred)
TP <- cm[lv[2], lv[2]]; TN <- cm[lv[1], lv[1]]
FP <- cm[lv[1], lv[2]]; FN <- cm[lv[2], lv[1]]
c(accuracy    = (TP + TN) / sum(cm),
  sensitivity = TP / (TP + FN),
  specificity = TN / (TN + FP),
  precision   = TP / (TP + FP),
  F1          = 2 * TP / (2 * TP + FP + FN))

roc_obj <- pROC::roc(testSet$am, probs, levels = lv, direction = "<")
pROC::auc(roc_obj)                         # area under the ROC curve

Explore the entire Binary Logistic Regression module in preview mode using our demo datasets. To submit suggestions or report a workflow issue, please use the discussion section below, or visit the official RAISINS website.

6 RAISINS Native Statistical Framework

RAISINS uses R for all its statistical computations. Every package used to generate major results is listed and demonstrated with examples, so results can be reproduced independently. These results are then organized and formatted on the RAISINS website along with visualisation to make them easier to use and interpret. RAISINS also has its own custom-built statistical tools for managing workflows, validating results, and generating reports. Details of these are not fully covered here, they’re shared with outside researchers only on request, and are subject to licensing terms.

7 Package References

R Core Team. (2025). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/

Venables, W. N., & Ripley, B. D. (2002). Modern Applied Statistics with S (4th ed.). Springer. https://www.stats.ox.ac.uk/pub/MASS4/

Fox, J., & Weisberg, S. (2019). An R Companion to Applied Regression (3rd ed.). Sage. https://socialsciences.mcmaster.ca/jfox/Books/Companion/

Robin, X., Turck, N., Hainard, A., Tiberti, N., Lisacek, F., Sanchez, J.-C., & Müller, M. (2011). pROC: an open-source package for R and S+ to analyze and compare ROC curves. BMC Bioinformatics, 12, 77. https://doi.org/10.1186/1471-2105-12-77

Robinson, D., Hayes, A., & Couch, S. (2025). broom: Convert Statistical Objects into Tidy Tibbles (R package version 1.0.13). https://CRAN.R-project.org/package=broom

Cox, D. R. (1958). The regression analysis of binary sequences. Journal of the Royal Statistical Society: Series B, 20(2), 215-232. https://doi.org/10.1111/j.2517-6161.1958.tb00292.x

Hosmer, D. W., Lemeshow, S., & Sturdivant, R. X. (2013). Applied Logistic Regression (3rd ed.). Wiley. https://doi.org/10.1002/9781118548387

Allaire, J. J., Xie, Y., Dervieux, C., McPherson, J., Luraschi, J., Ushey, K., Atkins, A., Wickham, H., Cheng, J., Chang, W., & Iannone, R. (2026). rmarkdown: Dynamic Documents for R (R package version 2.31). https://github.com/rstudio/rmarkdown

Feedback & Discussion