trainGlm | R Documentation |
This function constructs a GLM piece-by-piece by first calculating AICc for all models with univariate, quadratic, and 2-way-interaction 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 any or all of: a table with AICc for all possible models, all possible models (after model construction), and/or the model with the lowest AICc.
trainGlm( data, resp = names(data)[1], preds = names(data)[2:ncol(data)], family = "binomial", construct = TRUE, select = TRUE, anyway = FALSE, quadratic = TRUE, interaction = TRUE, verboten = NULL, verbotenCombos = NULL, presPerTermInitial = 10, presPerTermFinal = 10, initialTerms = 10, w = TRUE, method = "glm.fit", out = "model", tooBig = 1e+07, 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 |
construct |
Logical. If |
select |
Logical. If |
anyway |
Logical. If |
quadratic |
Logical. Used only if |
interaction |
Logical. Used only if |
verboten |
Either |
verbotenCombos |
Either |
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. Values can be |
tooBig |
Numeric. Used to catch errors when fitting a model fit with the |
verbose |
Logical. If |
... |
Arguments to pass to |
## Not run: library(brglm2) ### model red-bellied lemurs data(mad0) data(lemurs) # climate data bios <- c(1, 5, 12, 15) clim <- raster::getData('worldclim', var='bio', res=10) clim <- raster::subset(clim, bios) clim <- raster::crop(clim, mad0) # occurrence data occs <- lemurs[lemurs$species == 'Eulemur rubriventer', ] occsEnv <- raster::extract(clim, occs[ , c('longitude', 'latitude')]) # background sites bg <- 2000 # too few cells to locate 10000 background points bgSites <- dismo::randomPoints(clim, 2000) bgEnv <- raster::extract(clim, bgSites) # collate presBg <- rep(c(1, 0), c(nrow(occs), nrow(bgSites))) env <- rbind(occsEnv, bgEnv) env <- cbind(presBg, env) env <- as.data.frame(env) preds <- paste0('bio', bios) # GLM gl <- trainGlm( data = env, resp = 'presBg', preds = preds, verbose = TRUE ) # GAM ga <- trainGam( data = env, resp = 'presBg', preds = preds, verbose = TRUE ) # NS ns <- trainNs( data = env, resp = 'presBg', preds = preds, verbose = TRUE ) # prediction rasters mapGlm <- predict(clim, gl, type='response') mapGam <- predict(clim, ga, type='response') mapNs <- predict(clim, ga, type='response') par(mfrow=c(1, 3)) plot(mapGlm, main='GLM') plot(mad0, add=TRUE) points(occs[ , c('longitude', 'latitude')]) plot(mapGam, main='GAM') plot(mad0, add=TRUE) points(occs[ , c('longitude', 'latitude')]) plot(mapNs, main='NS') plot(mad0, add=TRUE) points(occs[ , c('longitude', 'latitude')]) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.