Generates a set of neighbor models from a given current model code. The neighborhood is defined as all single-variable changes (1-bit modifications).
Usage
generate_neighbors_df(
current_string,
search.space = c("ivbase", "oralbase"),
nsize = NULL
)Arguments
- current_string
A named numeric vector representing the current model code. Names correspond to model features (e.g. "no.cmpt", "eta.vc", "rv"), and values to their current states.
- search.space
Character, one of "ivbase" or "oralbase". Default is "ivbase".
- nsize
Integer (optional). Maximum number of neighbors to return. If NULL (default), the full neighborhood is returned. If specified, a random subset of this size is sampled.
Value
A list with two components:
- original
Neighbors generated by single-variable flips, before validation.
- validated
Neighbors after validation, representing feasible models.
Details
For each neighbor, both the original (pre-validation) and the
validated (post-validation) codes are retained. This allows
downstream functions (e.g. detect_move()) to distinguish
between the intended primary modification and any secondary
adjustments introduced by validation.
Optionally, the function can restrict the number of neighbors by random sampling (candidate list strategy).
Examples
current_string <- c(no.cmpt = 2, eta.km = 0, eta.vc = 1,
eta.vp = 0, eta.vp2 = 0, eta.q = 1,
eta.q2 = 0, mm = 0, mcorr = 1, rv = 2)
neighbors <- generate_neighbors_df(current_string, search.space = "ivbase")
head(neighbors$original) # raw neighbors (pre-validation)
#> no.cmpt eta.km eta.vc eta.vp eta.vp2 eta.q eta.q2 mm mcorr rv
#> 1 1 0 1 0 0 1 0 0 1 2
#> 2 3 0 1 0 0 1 0 0 1 2
#> 3 2 1 1 0 0 1 0 0 1 2
#> 4 2 0 0 0 0 1 0 0 1 2
#> 5 2 0 1 1 0 1 0 0 1 2
#> 6 2 0 1 0 0 0 0 0 1 2
head(neighbors$validated) # validated neighbors (post-validation)
#> no.cmpt eta.km eta.vc eta.vp eta.vp2 eta.q eta.q2 mm mcorr rv
#> 1 1 0 1 0 0 0 0 0 1 2
#> 2 3 0 1 0 0 1 0 0 1 2
#> 3 2 0 1 0 0 1 0 0 1 2
#> 4 2 0 0 0 0 1 0 0 1 2
#> 5 2 0 1 1 0 1 0 0 1 2
#> 6 2 0 1 0 0 0 0 0 1 2