| civic_fit | R Documentation |
Single unified entry point for all civic.icarm modelling. Automatically detects the prediction task from your target variable — you do not need to choose between classification and regression upfront.
**Task auto-detection rules:** | Target type | Task | Default model | |—|—|—| | 'factor' / 'character', 2 levels | Binary classification | '"cart"' | | 'factor' / 'character', 3+ levels | Multi-class classification | '"cart"' | | 'numeric' / 'integer' | Regression | '"cart"' |
**Supported models:**
*Binary classification:* - '"cart"' — Classification tree (rpart). Fully inspectable. - '"logistic"' — Logistic regression (stats::glm). Coefficient-interpretable. - '"logistic_l1"' — L1-penalised logistic (glmnet). Requires 'glmnet'.
*Multi-class classification:* - '"cart"' — Classification tree (rpart). Handles any number of classes. - '"multinomial"' — Multinomial logistic regression (nnet). Requires 'nnet'.
*Regression:* - '"cart"' — Regression tree (rpart). - '"linear"' — Ordinary least squares (stats::lm). - '"gam"' — Generalised Additive Model (mgcv). Requires 'mgcv'.
civic_fit(
formula,
data,
task = "auto",
model = "auto",
seed = 2025L,
cart_control = NULL,
positive = NULL,
...
)
formula |
A model formula. Use '.' for all columns: 'target ~ .' or 'target ~ x1 + x2 + x3'. |
data |
A 'data.frame' or 'tibble' of training data. |
task |
One of '"auto"' (default), '"binary"', '"multiclass"', or '"regression"'. Use '"auto"' to let the package detect the task. |
model |
Character. Model type. Use '"auto"' to let the package pick a sensible default, or specify one explicitly (see above). |
seed |
Integer. Random seed recorded for reproducibility (default 2025). |
cart_control |
A [rpart::rpart.control()] list for tuning CART trees. Default: 'cp = 0.01', 'minsplit = 20'. |
positive |
Character. For binary classification: which factor level is the "positive" class. If 'NULL', uses the first factor level. |
... |
Additional arguments passed to the underlying model fitter. |
An S3 object of class 'civic_model' containing:
The underlying fitted model object.
Detected/specified task: '"binary"', '"multiclass"', or '"regression"'.
Model type string.
The model formula used.
Name of the target/outcome variable.
Factor levels (classification only).
Positive class (binary classification only).
Random seed used.
Number of training rows.
SHA-256 digest of training data for provenance.
POSIXct timestamp.
Number of predictor features.
Names of predictor features.
# Binary classification (auto-detected from factor target)
data(civic_voting)
m <- civic_fit(voted ~ age + education + political_interest,
data = civic_voting)
print(m)
# Regression (auto-detected from numeric target)
data(civic_education)
m2 <- civic_fit(civic_knowledge_score ~ age + stats_course + news_consumption,
data = civic_education)
# Explicit model choice
m3 <- civic_fit(voted ~ ., data = civic_voting, model = "logistic")
# Works on any data frame — here using the built-in iris dataset
m4 <- civic_fit(Species ~ ., data = iris) # multi-class
m5 <- civic_fit(Sepal.Length ~ ., data = iris) # regression
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.