View source: R/idiographic_ml.R
| fit_ml | R Documentation |
Fits train/test supervised prediction models in an idiographic design: each subject can receive a model trained only on that subject's earlier rows, and the same held-out rows can also be scored by a pooled model trained on all subjects' earlier rows. This mirrors individualized modelling designs where person-specific prediction is compared against a nomothetic pooled baseline.
The implementation is dependency-free beyond base R. Regression supports mean baseline, ordinary least squares, ridge, lasso, elastic net, principal component regression, k-nearest neighbours, and a one-split regression tree. Binary classification supports majority baseline, logistic regression, ridge/lasso/elastic-net logistic regression, linear discriminant analysis, Gaussian naive Bayes, k-nearest neighbours, and a one-split classification tree. Predictors are standardized using training rows only.
fit_ml(
data,
outcome,
predictors,
id,
day = NULL,
beep = NULL,
task = c("auto", "regression", "classification"),
model = NULL,
estimator = NULL,
compare = c("both", "individual", "pooled"),
test_prop = 0.2,
min_train = 10L,
min_test = 1L,
lambda = 1,
alpha = 0.5,
k = 5L,
n_components = NULL,
max_iter = 100L,
tol = 1e-06,
standardize = TRUE,
keep_fits = FALSE,
...
)
fit_idiographic_ml(
data,
outcome,
predictors,
id,
day = NULL,
beep = NULL,
task = c("auto", "regression", "classification"),
model = NULL,
estimator = NULL,
compare = c("both", "individual", "pooled"),
test_prop = 0.2,
min_train = 10L,
min_test = 1L,
lambda = 1,
alpha = 0.5,
k = 5L,
n_components = NULL,
max_iter = 100L,
tol = 1e-06,
standardize = TRUE,
keep_fits = FALSE,
...
)
fit_individualized_ml(
data,
outcome,
predictors,
id,
day = NULL,
beep = NULL,
task = c("auto", "regression", "classification"),
model = NULL,
estimator = NULL,
compare = c("both", "individual", "pooled"),
test_prop = 0.2,
min_train = 10L,
min_test = 1L,
lambda = 1,
alpha = 0.5,
k = 5L,
n_components = NULL,
max_iter = 100L,
tol = 1e-06,
standardize = TRUE,
keep_fits = FALSE,
...
)
data |
A |
outcome |
Character. Name of the outcome column. |
predictors |
Character vector of predictor columns. |
id |
Character. Name of the subject/person ID column. |
day, beep |
Optional ordering columns. Rows are ordered by |
task |
|
model |
|
estimator |
|
compare |
Which models to fit: |
test_prop |
Proportion of each subject's ordered rows held out from the
end of the series. Default |
min_train |
Minimum complete training rows required for a model. Default
|
min_test |
Minimum held-out rows required per subject. Default |
lambda |
Ridge penalty for |
alpha |
Elastic-net mixing value in |
k |
Number of neighbours for |
n_components |
Number of principal components for |
max_iter |
Maximum iterations for coordinate-descent penalized models.
Default |
tol |
Convergence tolerance for iterative models. Default |
standardize |
Logical. Standardize predictors using training-set means
and SDs? Default |
keep_fits |
Logical. Store fitted internal model objects? Default
|
... |
Optional model controls using the same names as the explicit
tuning arguments ( |
An idioml_result with $predictions, $metrics, $coefficients,
$failures, and optionally $fits.
set.seed(1)
d <- data.frame(
id = rep(1:4, each = 40),
beep = rep(seq_len(40), 4),
x1 = rnorm(160),
x2 = rnorm(160)
)
d$y <- 0.4 * d$x1 - 0.2 * d$x2 + rep(c(-1, 0, 1, 0.5), each = 40) +
rnorm(160, sd = 0.4)
fit <- fit_ml(d, outcome = "y", predictors = c("x1", "x2"),
id = "id", beep = "beep",
model = c("linear", "ridge", "knn"))
fit$metrics
coefs(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.