A function using a Feasible Solution Algorithm to find a set of feasible solutions for a statistical model of a specific form that could include mth-order interactions (Note that these solutions are optimal in the sense that no one swap to any of the variables will increase the criterion function.)
FSA(
formula,
data,
fitfunc = lm,
fixvar = NULL,
quad = FALSE,
m = 2,
numrs = 1,
cores = 1,
interactions = T,
criterion = AIC,
minmax = "min",
checkfeas = NULL,
var4int = NULL,
min.nonmissing = 1,
return.models = FALSE,
fix.formula = NULL,
...
)lmFSA(...)
glmFSA(...)
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted.
a data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model.
the method that should be used to fit the model. For Example: lm, glm, or other methods that rely on formula, data, and other inputs.
variable(s) to fix in the model. Usually a covariate that should always be included (Example: Age, Sex). Will still consider it with interactions. Default is NULL.
Include quadratic terms or not. Logical.
order of terms to include. If interactions is set to TRUE then m is the order of interactions to be considered. For Subset selection (interaction=F), m is the size of the subset to examine. Defaults to 2.
number of random starts to perform.
number of cores to use while running. Note: Windows can only use 1 core. See mclapply for details. If function detects a Windows user it will automatically set cores=1.
whether to include interactions in model. Defaults to TRUE.
which criterion function to either maximize or minimize. For linear models one can use: r.squared, adj.r.squared, cv5.lmFSA (5 Fold Cross Validation error), cv10.lmFSA (10 Fold Cross Validation error), apress (Allen's Press Statistic), int.p.val (Interaction P-value), AIC, BIC.
whether to minimize or maximize the criterion function
vector of variables that could be a feasible solution. These variables will be used as the last random start.
specification of which variables to check for marginal feasiblilty. Default is NULL
the combination of predictors will be ignored unless this many of observations are not missing
bool value to specify whether return all the fitted models which have been checked
...
other arguments passed to fitfunc.
matrix of results
FSA
: find best set of variables for statistical models
lmFSA
: alias for FSA(fitfunc=lm,...)
glmFSA
: alias for FSA(fitfunc=glm,...)
# NOT RUN {
N <- 10 #number of obs
P <- 100 #number of variables
data <- data.frame(matrix(rnorm(N*(P+1)), nrow = N, ncol = P+1))
sln <- FSA(formula = "X101~1", data = data, cores = 1, m = 2,
interactions = FALSE, criterion = AIC, minmax = "min",
numrs = 10)
sln
# }
Run the code above in your browser using DataLab