View source: R/trainGlmDredge.r
trainGlmDredge | R Documentation |
This is a pseudo-deprecated function to construct a GLM piece-by-piece by first calculating AICc for all models with univariate, quadratic, cubic, 2-way-interaction, and linear-by-quadratic terms. It then creates a "full" model with the highest-ranked uni/bivariate terms. Finally, it implements an all-subsets model selection routine using AICc. Its output is a table with AICc for all possible models (resulting from the "full" model) and/or the model of these with the lowest AICc. The procedure uses Firth's penalized likelihood to address issues related to separability, small sample size, and bias. This function uses dredge
in the MuMIn package to cycle through all possible models.
trainGlmDredge( data, resp = names(data)[1], preds = names(data)[2:ncol(data)], family = "binomial", tooBig = 1e+07, construct = TRUE, select = TRUE, quadratic = TRUE, cubic = TRUE, interaction = TRUE, interQuad = TRUE, presPerTermInitial = 10, presPerTermFinal = 10, initialTerms = 10, w = TRUE, method = "glm.fit", out = "model", verbose = FALSE, ... )
data |
Data frame. Must contain fields with same names as in |
resp |
Character or integer. Name or column index of response variable. Default is to use the first column in |
preds |
Character list or integer list. Names of columns or column indices of predictors. Default is to use the second and subsequent columns in |
family |
Name of family for data error structure (see |
tooBig |
Numeric. Used to catch errors when fitting a model fit with the |
construct |
Logical. If |
select |
Logical. If |
quadratic |
Logical. Used only if |
cubic |
Logical. Used only if |
interaction |
Logical. Used only if |
interQuad |
Logical. Used only if |
presPerTermInitial |
Positive integer. Minimum number of presences needed per model term for a term to be included in the model construction stage. Used only is |
presPerTermFinal |
Positive integer. Minimum number of presence sites per term in initial starting model. Used only if |
initialTerms |
Positive integer. Maximum number of terms to be used in an initial model. Used only if |
w |
Either logical in which case |
method |
Character, name of function used to solve. This can be |
out |
Character. Indicates type of value returned. If |
verbose |
Logical. If |
... |
Arguments to pass to |
If out = 'model'
this function returns an object of class glm
. If out = 'table'
this function returns a data frame with tuning parameters and AICc for each model tried. If out = c('model', 'table'
then it returns a list object with the glm
object and the data frame.
trainGlm
, glm
in the stats package, brglmFit
in the brglm2 package
## Not run: set.seed(123) x <- matrix(rnorm(n = 6*100), ncol = 6) # true variables will be #1, #2, #5, and #6, plus # the squares of #1 and #6, plus # interaction between #1 and #6 # the cube of #5 imp <- c('x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x1_pow2', 'x6_pow2', 'x1_by_x6', 'x5_pow3') betas <- c(5, 2, 0, 0, 1, -1, 8, 1, 2, -4) names(betas) <- imp y <- 0.5 + x %*% betas[1:6] + betas[7] * x[ , 1] + betas[8] * x[ , 6] + betas[9] * x[ , 1] * x[ , 6] + betas[10] * x[ , 5]^3 y <- as.integer(y > 10) x <- cbind(y, x) x <- as.data.frame(x) names(x) <- c('y', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6') model <- trainGlmDredge(x, verbose=TRUE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.