Description Usage Arguments Author(s) Examples
Fit a linear model, using the genetic algorithm for variable selection.
1 | galogistic(formula, data, population = 200, generations = 100, mutateRate = 0.02, zeroOneRatio = 10, ...)
|
formula |
|
data |
|
population |
|
generations |
|
mutateRate |
|
zeroOneRatio |
|
... |
Wesley Brooks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (formula, data, population = 200, generations = 100,
mutateRate = 0.02, zeroOneRatio = 10, ...)
{
result = list()
class(result) = "adalasso"
result[["formula"]] = as.formula(formula, env = data)
na.rows = (which(is.na(data)) - 1)%%dim(data)[1] + 1
if (length(na.rows) > 0)
data = data[-na.rows, ]
m = ncol(data)
n = nrow(data)
response.name = rownames(attr(terms(formula, data = data),
"factors"))[1]
predictor.names = attr(terms(formula, data = data), "term.labels")
response.col = which(names(data) == response.name)
result[["response"]] = response.name
result[["predictors"]] = predictor.names
f = as.formula(paste(paste(response.name, "~", sep = ""),
paste(predictor.names, collapse = "+"), sep = ""))
y = as.matrix(data[, response.col])
x = as.matrix(data[, -response.col])
m = ncol(data) - 1
result[["ga"]] = rbga.bin(size = m, zeroToOneRatio = zeroOneRatio,
evalFunc = evalBIC, monitorFunc = monitor, mutationChance = mutateRate,
popSize = population, iters = generations, verbose = TRUE)
indx = which.min(result[["ga"]]$evaluations)
indiv = as.logical(drop(result[["ga"]]$population[indx, ]))
result[["vars"]] = predictor.names[indiv]
result[["formula"]] = as.formula(paste(response.name, "~",
paste(result[["vars"]], collapse = "+"), sep = ""))
result[["model"]] = lm(formula = result[["formula"]], data = data)
class(result) = "galm"
result
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.