Type: | Package |
Title: | Integrating Morphological Modeling and Machine Learning for Decision Support |
Version: | 0.1.0 |
Description: | Integrating morphological modeling with machine learning to support structured decision-making (e.g., in management and consulting). The package enumerates a morphospace of feasible configurations and uses random forests to estimate class probabilities over that space, bridging deductive model exploration with empirical validation. It includes utilities for factorizing inputs, model training, morphospace construction, and an interactive 'shiny' app for scenario exploration. |
License: | MIT + file LICENSE |
URL: | https://github.com/theogrost/MLmorph |
BugReports: | https://github.com/theogrost/MLmorph/issues |
Encoding: | UTF-8 |
Depends: | R (≥ 4.3.0) |
Imports: | caret (≥ 6.0.94), jsonlite (≥ 1.8.8), magrittr, openxlsx (≥ 4.2.5.2), randomForest (≥ 4.7.1.1), shiny (≥ 1.10.0), stats (≥ 4.3.0), tidyr (≥ 1.3.1), utils (≥ 4.3.0) |
RoxygenNote: | 7.3.2 |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Language: | en-US |
NeedsCompilation: | no |
Packaged: | 2025-08-27 19:06:23 UTC; theog |
Author: | Oskar Kosch |
Maintainer: | Oskar Kosch <contact@oskarkosch.com> |
Repository: | CRAN |
Date/Publication: | 2025-09-02 06:20:02 UTC |
MLmorph: Integrating Morphological Modeling and Machine Learning for Decision Support
Description
Integrating morphological modeling with machine learning to support structured decision-making (e.g., in management and consulting). The package enumerates a morphospace of feasible configurations and uses random forests to estimate class probabilities over that space, bridging deductive model exploration with empirical validation. It includes utilities for factorizing inputs, model training, morphospace construction, and an interactive 'shiny' app for scenario exploration.
Author(s)
Maintainer: Oskar Kosch contact@oskarkosch.com (ORCID) [copyright holder]
See Also
Useful links:
Launch the MLmorph shiny app
Description
Launch the MLmorph shiny app
Usage
MLmorph(
host = "127.0.0.1",
port = NULL,
launch.browser = TRUE,
maxUploadSize = 200 * 1024^2
)
Arguments
host |
Host interface to bind (default |
port |
Integer port or |
launch.browser |
Logical; open in a browser. Default |
maxUploadSize |
Maximum request size in bytes; sets
|
Value
The value returned by runApp.
See Also
Examples
if(interactive()){
MLmorph()
}
Launch MLmorph from the source tree (development helper)
Description
Launch MLmorph from the source tree (development helper)
Usage
MLmorph_live()
Create a morphospace of predictor combinations with class probabilities
Description
Create a morphospace of predictor combinations with class probabilities
Usage
create_morphospace(the_data, model, shiny = FALSE)
Arguments
the_data |
A data.frame used to derive unique values of predictors. |
model |
A classification model fitted via a formula interface that
supports |
shiny |
Logical; if |
Value
A list with components:
-
morphospace
: data frame with all predictor combinations, class label column (named as the dependent),calculated
(probability), andpurely_simulated
flag. -
dependent
: character scalar with the outcome name. -
independent
: character vector of predictor names. -
all_vars
: character vectorc(independent, dependent)
. -
purely_simulated
: logical vector aligned withmorphospace
.
Examples
n <- 60
y <- factor(sample(letters[1:3], n, TRUE))
x1 <- factorize_numeric_vector(runif(n, 10, 20), breaks_no = 3)
x2 <- factorize_numeric_vector(runif(n, 1, 2), breaks_no = 3)
df <- data.frame(y, x1, x2)
fit <- create_rf_model(df, dependent = "y", ntree = 50)$model
ms <- create_morphospace(df, fit)
names(ms)
Create a random forest classification model
Description
Create a random forest classification model
Usage
create_rf_model(
data,
dependent = colnames(data)[ncol(data)],
independent = setdiff(colnames(data), dependent),
train_validate_split = 0.8,
shiny = FALSE,
...
)
Arguments
data |
A data.frame containing predictors and the outcome. |
dependent |
Character scalar; the name of the outcome (must be a factor for classification).
Defaults to the last column of |
independent |
Character vector; names of predictor variables.
Defaults to all columns except |
train_validate_split |
Numeric in (0, 1); proportion of rows used for training. Default is |
shiny |
Logical; if |
... |
Additional arguments passed to randomForest (e.g., |
Value
A named list with components:
-
model
: a randomForest return object. -
variables_importance
: matrix from importance. -
model_performance_on_test
: a confusionMatrix return object on the validation set.
Examples
n <- 60
y <- factor(sample(letters[1:3], n, TRUE))
x1 <- factorize_numeric_vector(runif(n, 10, 20), breaks_no = 3)
x2 <- factorize_numeric_vector(runif(n, 1, 2), breaks_no = 5)
df <- data.frame(y, x1, x2)
fit <- create_rf_model(df, dependent = "y", ntree = 50)
names(fit)
Turn binary vector into a factor
Description
Turn binary vector into a factor
Usage
factorize_binary_vector(data_vector, custom_labels = NULL)
Arguments
data_vector |
Logical vector. |
custom_labels |
Optional length-2 character vector: first for |
Value
A factor with two levels in TRUE
, FALSE
order.
Examples
factorize_binary_vector(c(TRUE, FALSE, TRUE))
Turn character vector into a factor
Description
Turn character vector into a factor
Usage
factorize_character_vector(data_vector, custom_labels = NULL)
Arguments
data_vector |
Character vector. |
custom_labels |
Optional named character vector where names are original values and values are labels. |
Value
A factor with labeled levels.
Examples
factorize_character_vector(c("A First", "B Second", "C Third"))
Identity factorization for numbered strings
Description
Identity factorization for numbered strings
Usage
factorize_identity(data_vector)
Arguments
data_vector |
Character vector where values are already labeled (e.g., |
Value
A factor with levels == labels
.
Examples
factorize_identity(c("1. First", "2. Second", "3. Third"))
Heuristic factorization for all columns of a data frame
Description
Heuristic factorization for all columns of a data frame
Usage
factorize_nicely_dataframe(data_frame)
Arguments
data_frame |
A data frame. |
Value
A data frame with all columns converted to factors.
Examples
df <- data.frame(x = runif(20), y = rep(c(TRUE, FALSE, TRUE, TRUE), 5))
factorize_nicely_dataframe(df)
Heuristic factorization for a single vector
Description
Heuristic factorization for a single vector
Usage
factorize_nicely_vector(data_vector)
Arguments
data_vector |
A vector (numeric, logical, or character). |
Value
A factor (ordered for numeric inputs with many distinct values).
Examples
factorize_nicely_vector(c("a", "b", "a"))
Turn numeric vector into an ordered factor
Description
Turn numeric vector into an ordered factor
Usage
factorize_numeric_vector(
data_vector,
method = c("equal_bins", "equal_distance", "custom_breaks"),
breaks_no = 5,
custom_breaks = NULL,
custom_labels = NULL
)
Arguments
data_vector |
Numeric vector. |
method |
Factorization rule: one of |
breaks_no |
Integer |
custom_breaks |
Optional numeric vector of cut points (strictly increasing) used when |
custom_labels |
Optional character vector of labels. If supplied, its length should equal |
Value
An ordered factor with interval labels.
Examples
factorize_numeric_vector(runif(10))
Zero-padded ordinal labels
Description
Zero-padded ordinal labels
Usage
get_label_numbers(vec)
Arguments
vec |
A vector; its length determines the padding width. |
Value
A character vector of zero-padded ordinals (e.g., "01", "02", …).
Load tabular data (xlsx, csv, or json)
Description
Load tabular data (xlsx, csv, or json)
Usage
load_data(data_path)
Arguments
data_path |
Character scalar; path to a |
Value
A base data.frame
with the imported data.
Examples
tmp_csv <- tempfile(fileext = ".csv")
utils::write.csv(data.frame(a = 1:2, b = c("x", "y")), tmp_csv, row.names = FALSE)
load_data(tmp_csv)
tmp_json <- tempfile(fileext = ".json")
jsonlite::write_json(list(a = 1:2, b = c("x","y")), tmp_json, auto_unbox = TRUE)
load_data(tmp_json)
tmp_xlsx <- tempfile(fileext = ".xlsx")
openxlsx::write.xlsx(data.frame(a = 1:2, b = c("x","y")), tmp_xlsx)
load_data(tmp_xlsx)