# \donttest{
## ------------------------------------------------------------------------
## Multi-response SVEM scoring with Derringer–Suich desirabilities
## ------------------------------------------------------------------------
data(lipid_screen)
# Build a deterministic expansion once and reuse for all responses
spec <- bigexp_terms(
Potency ~ PEG + Helper + Ionizable + Cholesterol +
Ionizable_Lipid_Type + N_P_ratio + flow_rate,
data = lipid_screen,
factorial_order = 3,
polynomial_order = 3,
include_pc_2way = TRUE,
include_pc_3way = FALSE
)
form_pot <- bigexp_formula(spec, "Potency")
form_siz <- bigexp_formula(spec, "Size")
form_pdi <- bigexp_formula(spec, "PDI")
set.seed(1)
fit_pot <- SVEMnet(form_pot, lipid_screen)
fit_siz <- SVEMnet(form_siz, lipid_screen)
fit_pdi <- SVEMnet(form_pdi, lipid_screen)
# Collect SVEM models in a named list by response
objs <- list(Potency = fit_pot, Size = fit_siz, PDI = fit_pdi)
# Targets and user weights for Derringer–Suich desirabilities
goals <- list(
Potency = list(goal = "max", weight = 0.6),
Size = list(goal = "min", weight = 0.3),
PDI = list(goal = "min", weight = 0.1)
)
# Optional mixture constraints (composition columns sum to 1)
mix <- list(list(
vars = c("PEG", "Helper", "Ionizable", "Cholesterol"),
lower = c(0.01, 0.10, 0.10, 0.10),
upper = c(0.05, 0.60, 0.60, 0.60),
total = 1.0
))
# Basic random-search scoring without WMT or design-space specs
set.seed(3)
scored_basic <- svem_score_random(
objects = objs,
goals = goals,
n = 10000, # number of random candidates
mixture_groups = mix,
combine = "geom",
numeric_sampler = "random",
verbose = FALSE
)
# Scored candidate table: predictors, _pred, _des, score, uncertainty
names(scored_basic$score_table)
head(scored_basic$score_table)
# Scored original data (if 'data' is supplied)
# scored_basic$original_data_scored contains predictions + desirabilities
## ------------------------------------------------------------------------
## With whole-model tests (WMT) and process-mean specifications
## ------------------------------------------------------------------------
set.seed(123)
wmt_out <- svem_wmt_multi(
formulas = list(Potency = form_pot,
Size = form_siz,
PDI = form_pdi),
data = lipid_screen,
mixture_groups = mix,
wmt_control = list(seed = 123),
plot = FALSE,
verbose = FALSE
)
# Simple process-mean specs for a joint design space:
# Potency >= 78, Size <= 100, PDI <= 0.25
specs_ds <- list(
Potency = list(lower = 78),
Size = list(upper = 100),
PDI = list(upper = 0.25)
)
set.seed(4)
scored_full <- svem_score_random(
objects = objs,
goals = goals,
data = lipid_screen, # score the original runs as well
n = 25000,
mixture_groups = mix,
level = 0.95,
combine = "geom",
numeric_sampler = "random",
wmt = wmt_out, # optional: WMT reweighting
specs = specs_ds, # optional: design-space columns
verbose = TRUE
)
# The scored table now includes:
# * score, wmt_score, uncertainty_measure
# * per-response CIs: _lwr, _upr
# * design-space columns, e.g. Potency_p_in_spec_mean, p_joint_mean
names(scored_full$score_table)
## ------------------------------------------------------------------------
## Positional (unnamed) goals matched to objects by position
## ------------------------------------------------------------------------
data(lipid_screen)
# Build a deterministic expansion once and reuse for all responses
spec <- bigexp_terms(
Potency ~ PEG + Helper + Ionizable + Cholesterol +
Ionizable_Lipid_Type + N_P_ratio + flow_rate,
data = lipid_screen,
factorial_order = 3,
polynomial_order = 3,
include_pc_2way = TRUE,
include_pc_3way = FALSE
)
form_pot <- bigexp_formula(spec, "Potency")
form_siz <- bigexp_formula(spec, "Size")
form_pdi <- bigexp_formula(spec, "PDI")
set.seed(1)
fit_pot <- SVEMnet(form_pot, lipid_screen)
fit_siz <- SVEMnet(form_siz, lipid_screen)
fit_pdi <- SVEMnet(form_pdi, lipid_screen)
# Collect SVEM models in a list.
# Here goals will be matched by position: Potency, Size, PDI.
objs <- list(fit_pot, fit_siz, fit_pdi)
# Positional goals (unnamed list): must have same length as 'objects'
goals_positional <- list(
list(goal = "max", weight = 0.6), # for Potency (objs[[1]])
list(goal = "min", weight = 0.3), # for Size (objs[[2]])
list(goal = "min", weight = 0.1) # for PDI (objs[[3]])
)
set.seed(5)
scored_pos <- svem_score_random(
objects = objs,
goals = goals_positional,
n = 5000,
numeric_sampler = "random",
verbose = FALSE
)
names(scored_pos$score_table)
# }
Run the code above in your browser using DataLab