gene | R Documentation |
Construct subtests from a given pool of items using a simple genetic algorithm. Allows for multiple constructs, occasions, and groups.
gene(
data,
factor.structure,
capacity = NULL,
item.weights = NULL,
item.invariance = "congeneric",
repeated.measures = NULL,
long.invariance = "strict",
mtmm = NULL,
mtmm.invariance = "configural",
grouping = NULL,
group.invariance = "strict",
comparisons = NULL,
auxiliary = NULL,
use.order = FALSE,
software = "lavaan",
cores = NULL,
objective = NULL,
ignore.errors = FALSE,
burnin = 5,
generations = 256,
individuals = 64,
selection = "tournament",
selection.pressure = NULL,
elitism = NULL,
reproduction = 0.5,
mutation = 0.05,
mating.index = 0,
mating.size = 0.25,
mating.criterion = "similarity",
immigration = 0,
convergence.criterion = "geno.between",
tolerance = NULL,
reinit.n = 1,
reinit.criterion = convergence.criterion,
reinit.tolerance = NULL,
reinit.prop = 0.75,
schedule = "run",
analysis.options = NULL,
suppress.model = FALSE,
seed = NULL,
filename = NULL
)
data |
A data.frame containing all relevant data. |
factor.structure |
A list linking factors to items. The names of the list elements correspond to the factor names. Each list element must contain a character-vector of item names that are indicators of this factor. |
capacity |
A list containing the number of items per subtest. This must be in the same order as the |
item.weights |
A placeholder. Currently all weights are assumed to be one. |
item.invariance |
A character vector of length 1 or the same length as |
repeated.measures |
A list linking factors that are repeated measures of each other. Repeated factors must be in one element of the list - other sets of factors in other elements of the list. When this is |
long.invariance |
A character vector of length 1 or the same length as |
mtmm |
A list linking factors that are measurements of the same construct with different methods. Measurements of the same construct must be in one element of the list - other sets of methods in other elements of the list. When this is |
mtmm.invariance |
A character vector of length 1 or the same length as |
grouping |
The name of the grouping variable. The grouping variable must be part of |
group.invariance |
A single value describing the assumed invariance of items across groups. Currently there are four options: 'configural', 'weak', 'strong', and 'strict'. Defaults to 'strict'. When |
comparisons |
A character vector containing any combination of 'item', 'long', 'mtmm', and 'group' indicating which invariance should be assessed via model comparisons. The order of the vector dictates the sequence in which model comparisons are performed. Defaults to |
auxiliary |
The names of auxiliary variables in |
use.order |
A logical indicating whether or not to take the selection order of the items into account. Defaults to |
software |
The name of the estimation software. Can currently be 'lavaan' (the default) or 'Mplus'. Each option requires the software to be installed. |
cores |
The number of cores to be used in parallel processing. If |
objective |
A function that converts the results of model estimation into a pheromone. See 'details' for... details. |
ignore.errors |
A logical indicating whether or not to ignore estimation problems (such as non positive-definite latent covariance matrices). Defaults to |
burnin |
Number of generations for which to use fixed objective function before switching to empirical objective. Ignored if |
generations |
Maximum number of generations to run. Defaults to 256. |
individuals |
The number of individuals per generation. Defaults to 64. |
selection |
The method used for selecting possible parents. Can be either |
selection.pressure |
The pressure exerted during the selection process, depending on the |
elitism |
The proportion of individuals from the last generation to carry over to the next generation. Defaults to 1/individuals, meaning that the best individual is retained into the next generation. |
reproduction |
The proportion of individuals that are allowed to sire offspring. These individuals are selected using fitness proportionate selection. Defaults to .5. |
mutation |
The mutation probability. Defaults to .05. See 'details'. |
mating.index |
The relative rank of the selected mate within the mating pool. A number bewteen 0 (the default) and 1. The meaning depends on the setting of |
mating.size |
The proportion of potential mates sampled from the pool of reproducers for each selected individual. Defaults to .25. See 'details'. |
mating.criterion |
The criterion by which to select mates. Can be either 'similarity' (the default) or 'fitness'. See 'details'. |
immigration |
The proportion of individuals per generation that are randomly generated immigrants. Defaults to 0. |
convergence.criterion |
The criterion by which convergence is determined. Can be one of four criteria |
tolerance |
The tolerance for determining convergence. The default depends on the setting used for |
reinit.n |
The maximum number of reinitilizations to be performed. Defaults to 1. See 'details'. |
reinit.criterion |
The convergence criterion used to determine whether the population should be reinitialized. Can be one of four criteria |
reinit.tolerance |
The tolerance for determining the necessity of reinitialization. The default depends on the setting used for |
reinit.prop |
The proportion of the population to be discarded and replaced by random individuals when reinitializing. Defaults to .75. See 'details'. |
schedule |
The counter which the scheduling of parameters pertains to. Can be either 'run' (the default), for a continuous schedule, 'generation', for a schedule that is restarted every time the population is reinitialized. |
analysis.options |
A list additional arguments to be passed to the estimation software. The names of list elements must correspond to the arguments changed in the respective estimation software. E.g. |
suppress.model |
A logical indicating whether to suppress the default model generation. If |
seed |
A random seed for the generation of random samples. See |
filename |
The stem of the filenames used to save inputs, outputs, and data files when |
The pheromone function provided via objective
is used to assess the quality of the solutions. These functions can contain any combination of the fit indices provided by the estimation software. When using Mplus these fit indices are 'rmsea', 'srmr', 'cfi', 'tli', 'chisq' (with 'df' and 'pvalue'), 'aic', 'bic', and 'abic'. With lavaan any fit index provided by inspect
can be used. Additionally 'crel' provides an aggregate of composite reliabilites, 'rel' provides a vector or a list of reliability coefficients for the latent variables, 'con' provides an aggregate consistency estimate for MTMM analyses, and 'lvcor' provides a list of the latent variable correlation matrices. For more detailed objective functions 'lambda', 'theta', 'psi', and 'alpha' provide the model-implied matrices. Per default a pheromone function using 'crel', 'rmsea', and 'srmr' is used. Please be aware that the objective
must be a function with the required fit indices as (correctly named) arguments.
Using model comparisons via the comparisons
argument compares the target model to a model with one less degree of assumed invariance (e.g. if your target model contains strong invariance, the comparison model contain weak invariance). Adding comparisons will change the preset for the objective function to include model differences. With comparisons, a custom objective function (the recommended approach) can also include all model fit indices with a preceding delta.
to indicate the difference in this index between the two models. If more than one type of comparison is used, the argument of the objective function should end in the type of comparison requested (e.g. delta.cfi.group
to use the difference in CFI between the model comparison of invariance across groups).
The genetic algorithm implemented selects parents in a two-step procedure. First, either a tournament or a fitness proportionate selection is performed to select inviduals
times reproduction
viable parents. Then, the non-self-adaptive version of mating proposed by Galán, Mengshoel, and Pinter (2013) is used to perform mating. In contrast to the original article, the mating.index
and mating.size
are handled as proportions, not integers. Similarity-based mating is based on the Jaccard Similarity. Mutation is currently always handled as an exchange of the selection state between two items. This results in mutation selecting one item that was not selected prior to mutation and dropping one item selected prior to mutation.
Per default (convergence.criterion = 'geno.between'
), convergence is checked by tracking the changes between selection probabilities over three subsequent generations. If the difference between these selections probabilities falls below tolerance
(.01 by default) in three consecutive generations, the algorithm is deemed to have converged. To avoid false convergence in the early search, the lower of either 10% of the generations or 10 generations must be completed, before convergence is checked. When using reinitialization the default for reinit.tolerance
is .05 to initiate a full reinitialization of the population. An alternative convergence criterion is the variance of the global-best values on the objective function, as proposed by Bhandari, Murthy, and Pal (2012). For generalizability over different functions provided to objective
, variances are scaled to the first global-best found. In this case the setting for tolerance
pertains to the pure variance estimate and defaults to .0005 (or .005 when regarding the reinitialization process discussed below). Alternatively, the setting 'median'
checks for the relative difference between the objective function value of the generation-best and the median value of a generation (scaled by the former). Here, the default is .05 (or .10 when regarding the reinitialization process). The setting 'geno.within'
checks for the variability of genotypes in a generation, by determining the relative frequency, with which each item is selected. Convergence is reached if this relative frequency is either tolerance
(.8, by default - or .7 for the reinitialization process) or 1 - tolerance
for all items within a generation.
A reinitialization procedure can be used to avoid premature convergence. The behavior is controlled via the arguments starting in reinit
. The argument reinit.n
determines the maximum number of possible reinitializations. After each reinitialization, the generation counter is reset, allowing for the maximum number of generations before the search is aborted. The reinit.criterion
and reinit.tolerance
relate to convergence criteria outlined above. It is recommended to use a higher tolerance on reinitialization than on final convergence to avoid long periods of stagnant search. The reinit.prop
determines the proportion of the population to be replaced by random individuals when reinitializing. Note that even when reinit.prop = 1
, the number of individuals kept due to elitism
is not discarded.
Returns an object of the class stuartOutput
for which specific summary
and plot
methods are available. The results are a list.
call |
The called function. |
software |
The software used to fit the CFA models. |
parameters |
A list of the parameters used. |
analysis.options |
A list of the additional arguments passed to the estimation software. |
timer |
An object of the class |
log |
A |
log_mat |
A |
solution |
A list of matrices with the choices made in the global-best solution. |
pheromones |
A list of matrices with the relative selection frequency of items in the final generation. |
subtests |
A list containing the names of the selected items and their respective subtests. |
final |
The results of the estimation of the global-best solution. |
Martin Schultze
Bhandari, D., Murthy, C.A., & Pal, S.K. (2012). Variance as a Stopping Criterion for Genetic Algorithms with Elitist Model. Fundamenta Informaticae, 120, 145-164. doi:10.3233/FI-2012-754
Galán, S.F., Mengshoel, O.J., & Pinter, R. (2013). A novel mating approach for genetic algorithms. Evolutionary Computation, 21(2), 197-229. doi:10.1162/EVCO_a_00067
bruteforce
, mmas
, randomsamples
# Genetic selection in a simple situation
# requires lavaan
# number of cores set to 1 in all examples
data(fairplayer)
fs <- list(si = names(fairplayer)[83:92])
# minimal example
sel <- gene(fairplayer, fs, 4,
generations = 1, individuals = 10, # minimal runtime, remove for application
seed = 55635, cores = 1)
summary(sel)
# longitudinal example
data(fairplayer)
fs <- list(si1 = names(fairplayer)[83:92],
si2 = names(fairplayer)[93:102],
si3 = names(fairplayer)[103:112])
repe <- list(si = c('si1', 'si2', 'si3'))
# run to convergence
# switching to best-last mating and 50\% mating size
sel <- gene(fairplayer, fs, 4,
repeated.measures = repe, long.invariance = 'strong',
mating.criterion = 'fitness', mating.index = 0,
mating.size = .5,
seed = 55635, cores = 1)
# forcing a run through all generations
# by disabling the convergence rule
sel <- gene(fairplayer, fs, 4,
repeated.measures = repe, long.invariance = 'strong',
tolerance = 0, seed = 55635,
cores = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.