selection: Selection Function for Genetic Algorithm for Variable...

Description Usage Arguments Examples

Description

Selects independent variables to be bred by genetic algorithm based on AIC fitness function

Usage

1
selection(mm, model, parents, P)

Arguments

mm

Model matrix object with intercept and column for each independent variable specified in model

model

A formula object ( eg. data$y ~ x1 + x2^2 + x2:x3 ). Note: must specify data source for dependent variable

parents

Parents matrix of P rows indicating with 0 or 1 which variable selection

P

Population size for each generation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# simulate data
initData <- matrix( rnorm( 2500 , sd = c(1,  5, 7 , 100 , 40 ) ) , ncol = 5 , byrow = TRUE )
initOutcome <- 10 - 15 * initData[ , 1 ] + 2 * initData[ , 3 ] + 1.1 * initData[ , 5 ]
data <- data.frame( initData, initOutcome )

# define input parameters
P <- 30
parents <- initiation( C = 5 , P = P )
model <- data$initOutcome ~ X1 + X2 + X3 + X4 + X5
mm <- model.matrix( model , data = data )

# call selection function
selection( mm = mm , model = model , parents = parents , P = P )

WaverlyWei/GA documentation built on May 28, 2019, 6:41 a.m.