statwitness provides model-aware behavioral validation
and audit certificates for statistical analyses.
The package applies controlled transformations with known expected consequences, refits the analysis, and verifies that the fitted model responds correctly. Examples include reordering observations, changing measurement units, relabeling factors, reconstructing predictions, and refitting models with alternative optimizers.
These behavioral checks are combined with model-specific diagnostics for numerical stability, design adequacy, assumptions, and influential observations.
statwitness organizes checks into five domains.
Verifies:
Evaluates:
Screens:
Provides model-specific checks for:
Evaluates influential:
The same audit domains are used across model families, but the individual checks are model-specific. A check is run only when its expected behavior is justified for the fitted model.
Version 0.1.0 supports:
stats::lm();lm() or
aov();stats::glm();lme4::lmer();lme4::glmer();glmmTMB;afex::aov_ez();survival::coxph();survival::survreg();Packages such as lme4, glmmTMB,
afex, and survival are required only for their
corresponding model classes.
Install the released version from CRAN:
install.packages("statwitness")Load the package:
library(statwitness)The main interface is:
audit <- statwitness(
formula,
data = your_data,
focus = "term_of_interest",
audit_level = "standard"
)Print a concise certificate:
auditDisplay every individual check:
print(audit, details = TRUE)focus identifies the coefficient or omnibus model term
treated as the primary result.
For example:
audit <- statwitness(
outcome ~ treatment + age + sex,
data = dataset,
focus = "treatment"
)For an interaction:
audit <- statwitness(
outcome ~ treatment * sex,
data = dataset,
focus = "treatment:sex"
)When focus refers to a multi-parameter term, such as an
interaction between factors, statwitness evaluates it as an
omnibus term rather than selecting a single dummy-coded coefficient.
The focus argument is optional. Specifying it is
recommended whenever a model contains multiple predictors or
interactions.
audit <- statwitness(
score ~ criterion * model + (1 | rater),
data = dataset,
focus = "criterion:model"
)
auditFor mixed-effects models, the standard audit can include:
A possible certificate is:
Computational integrity: PASSED
Numerical stability: PASSED
Design adequacy: REVIEW NEEDED
Assumption screening: PASSED
Influence stability: PASSED
Overall status:
PASSED WITH REVIEW ITEMS
A design review does not automatically mean that the fitted model is incorrect. It identifies an aspect of the model that requires scientific consideration.
dat <- transform(
mtcars,
transmission = factor(am)
)
audit <- statwitness(
mpg ~ transmission + wt + hp,
data = dat,
focus = "transmission"
)
auditThe standard linear-model audit can include:
dat <- transform(
mtcars,
high_mpg = mpg > median(mpg),
transmission = factor(am)
)
audit <- statwitness(
high_mpg ~ transmission + wt,
data = dat,
family = binomial(),
focus = "transmission"
)
auditGeneralized linear-model audits can additionally include:
audit <- statwitness(
breaks ~ wool * tension,
data = warpbreaks,
focus = "wool:tension",
method = "aov"
)
auditThe ANOVA design audit can identify:
Repeated-measures designs use a dedicated interface:
audit <- statwitness_repeated(
data = dataset,
outcome = "score",
id = "rater",
within = c("criterion", "model"),
focus = "criterion:model",
type = 3,
correction = "GG"
)
auditThe repeated-measures audit can include:
audit <- statwitness(
correct ~ criterion * model + (1 | rater),
data = dataset,
family = binomial(),
focus = "criterion:model"
)
auditGeneralized mixed-model audits combine GLM-specific checks with:
audit <- statwitness(
survival::Surv(time, event) ~ treatment + age,
data = patients,
focus = "treatment"
)
auditThe Cox-model audit can include:
Three audit levels are available.
statwitness(
outcome ~ treatment,
data = dataset,
focus = "treatment",
audit_level = "core"
)Runs relatively fast computational-integrity checks.
statwitness(
outcome ~ treatment,
data = dataset,
focus = "treatment",
audit_level = "standard"
)Adds routine numerical, design, assumption, and influence checks.
statwitness(
outcome ~ treatment,
data = dataset,
focus = "treatment",
audit_level = "thorough"
)Adds more computationally intensive checks, including broader optimizer comparisons and deletion-based influence analyses where supported.
The exact tests depend on the model class and analysis structure.
Use audit_plan() to see which checks are applicable
before running the full audit:
audit_plan(
score ~ criterion * model + (1 | rater),
data = dataset,
focus = "criterion:model",
audit_level = "standard"
)The plan reports:
Possible domain results include:
PASSED;WARNING;REVIEW NEEDED;FAILED;NOT EVALUATED.A passing certificate means that the analysis behaved as expected under the registered checks that were performed.
It does not establish that:
statwitness complements scientific judgment and
substantive model evaluation; it does not replace them.
Audit reports can include:
Fingerprints help determine whether two certificates were generated from the same supplied data and analysis configuration.
To cite statwitness in publications, run:
citation("statwitness")