| logistic | R Documentation |
Fits binary logistic regression using formula syntax or compact R4VN syntax.
Compact syntax avoids the need to type ~ and +.
logistic(
y,
...,
vars = NULL,
data = NULL,
event = NULL,
or = FALSE,
exp = FALSE,
noconstant = FALSE,
vce = c("model", "robust", "cluster"),
cluster = NULL,
weights = NULL,
subset = NULL,
ref = NULL,
gof = FALSE,
groups = 10,
classification = FALSE,
cutoff = 0.5,
vif = FALSE,
diagnosis = FALSE,
level = 0.95,
digits = 3,
p_digits = 3,
show = TRUE,
console = FALSE
)
y |
Formula or binary outcome variable. |
... |
Predictors or model terms when |
vars |
Optional model terms written as |
data |
Data frame or |
event |
Event level for a simple named outcome. |
or |
Add an odds-ratio table while retaining coefficients. |
exp |
Display odds ratios only. |
noconstant |
Fit without an intercept. |
vce |
Model-based, HC1 robust, or cluster-robust covariance. |
cluster |
Cluster variable. |
weights |
Optional non-negative weights. |
subset |
Optional logical subset. |
ref |
Optional named list of factor reference levels. |
gof |
Show a Hosmer-Lemeshow test. |
groups |
Number of groups for the Hosmer-Lemeshow test. |
classification |
Show a classification table. |
cutoff |
Classification cutoff. |
vif |
Show coefficient-level VIFs. |
diagnosis |
Logical; if |
level |
Confidence level. |
digits, p_digits |
Decimal places. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the traditional result in the Console. Default |
Compact model syntax:
x: use the variable as stored in the data.
c.x: force x to be continuous.
i.x: force x to be categorical.
b2.x, b3.x, ...: categorical with the corresponding factor-level
position as reference.
ib0.x, ib1.x, ib2.x, ...: categorical with the requested
value/level as reference. If that literal level is unavailable, a
positive integer can fall back to the corresponding factor-level
position.
i.a*i.b: main effects for a and b plus their interaction.
i.a:i.b: interaction only.
c.x*i.a: continuous and categorical main effects plus interaction.
Thus logistic(y, ib2.occupation*i.treatment, c.age) fits occupation,
treatment, occupation-by-treatment interaction, and age without requiring
formula operators ~ or +.
The fitted glm object is stored in result$raw$model, so nested models can
be compared directly with lrtest().
An object of class r4vn_stat, returned invisibly. Its sections
component contains the formatted model summary, coefficient and/or odds-
ratio tables, and any requested goodness-of-fit, classification, or VIF
tables. In raw, model is the fitted binomial glm object, vcov is
the covariance matrix, coefficients contains coefficient-level estimates
and tests, logLik and null.logLik are model log likelihoods, pseudo.r2
is McFadden-style pseudo-R-squared, event records the modeled outcome
level, and vce and model.terms record the covariance estimator and
fitted terms.
lrtest(), poisson()
set.seed(2026)
d <- data.frame(
outcome = factor(rbinom(200, 1, .35), levels = 0:1,
labels = c("No", "Yes")),
age = rnorm(200, 45, 12),
occupation = factor(sample(c("Office", "Worker", "Other"), 200, TRUE)),
treatment = factor(sample(c("No", "Yes"), 200, TRUE))
)
m1 <- logistic(
outcome,
c.age,
i.occupation,
i.treatment,
data = d,
event = "Yes",
show = FALSE
)
m2 <- logistic(
outcome,
c.age,
ib2.occupation*i.treatment,
data = d,
event = "Yes",
show = FALSE
)
m3 <- logistic(
outcome,
vars = vars(c.age, ib2.occupation*i.treatment),
data = d,
event = "Yes",
show = FALSE
)
lrtest(m1, m2, show = FALSE)
# Request a complete diagnostic panel
logistic(outcome, c.age, i.occupation, data = d, event = "Yes",
diagnosis = TRUE, show = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.