Learn R Programming

AICcmodavg (version 2.1-1)

extractX: Extract Predictors from Candidate Model List

Description

This function extracts the predictors used in candidate models. The function is currently implemented for glm, gls, lm, lme, merMod, rlm, survreg object classes that are stored in a list as well as various models of unmarkedFit classes.

Usage

extractX(cand.set, …)

# S3 method for AICaov.lm extractX(cand.set, …)

# S3 method for AICglm.lm extractX(cand.set, …)

# S3 method for AIClm extractX(cand.set, …)

# S3 method for AICgls extractX(cand.set, …)

# S3 method for AIClme extractX(cand.set, …)

# S3 method for AICglmerMod extractX(cand.set, …)

# S3 method for AIClmerMod extractX(cand.set, …)

# S3 method for AICrlm.lm extractX(cand.set, …)

# S3 method for AICsurvreg extractX(cand.set, …)

# S3 method for AICunmarkedFitOccu extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitColExt extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitOccuRN extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitPCount extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitPCO extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitDS extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitGDS extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitOccuFP extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitMPois extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitGMM extractX(cand.set, parm.type = NULL, …)

# S3 method for AICunmarkedFitGPC extractX(cand.set, parm.type = NULL, …)

Arguments

cand.set

a list storing each of the models in the candidate model set.

parm.type

this argument specifies the parameter type on which the effect size will be computed and is only relevant for models of unmarkedFitOccu, unmarkedFitColExt, unmarkedFitOccuFP, unmarkedFitOccuRN, unmarkedFitMPois, unmarkedFitPCount, unmarkedFitPCO, unmarkedFitDS, unmarkedFitGDS, unmarkedFitGMM, and unmarkedFitGPC classes. The character strings supported vary with the type of model fitted. For unmarkedFitOccu objects, either psi or detect can be supplied to indicate whether the parameter is on occupancy or detectability, respectively. For unmarkedFitColExt, possible values are psi, gamma, epsilon, and detect, for parameters on occupancy in the inital year, colonization, extinction, and detectability, respectively. For unmarkedFitOccuFP objects, one can specify psi, detect, falsepos, and certain, for occupancy, detectability, probability of assigning false-positives, and probability detections are certain, respectively. For unmarkedFitOccuRN objects, either lambda or detect can be entered for abundance and detectability parameters, respectively. For unmarkedFitPCount and unmarkedFitMPois objects, lambda or detect denote parameters on abundance and detectability, respectively. For unmarkedFitPCO objects, one can enter lambda, gamma, omega, iota, or detect, to specify parameters on abundance, recruitment, apparent survival, immigration, and detectability, respectively. For unmarkedFitDS objects, lambda and detect are supported. For unmarkedFitGDS, lambda, phi, and detect denote abundance, availability, and detection probability, respectively. For unmarkedFitGMM and unmarkedFitGPC objects, lambda, phi, and detect denote abundance, availability, and detectability, respectively.

additional arguments passed to the function.

Value

extractX returns an object of class extractX with the following components:

predictors

a character vector of the names of the predictors included in the model, excluding the intercept term.

data

a data frame or, in the case of unmarkedFit objects, a list of data frames (e.g., obsCovs, siteCovs, yearlySiteCovs).

Details

The candidate models must be stored in a list. The results of extractX are useful in preparing a newdata data frame to use in computing model-averaged predictions with modavgPred or differences between groups with modavgEffect (Burnham and Anderson 2002, Anderson 2008, Burnham et al. 2011).

References

Anderson, D. R. (2008) Model-based Inference in the Life Sciences: a primer on evidence. Springer: New York.

Burnham, K. P., Anderson, D. R. (2002) Model Selection and Multimodel Inference: a practical information-theoretic approach. Second edition. Springer: New York.

Burnham, K. P., Anderson, D. R., Huyvaert, K. P. (2011) AIC model selection and multimodel inference in behaviorial ecology: some background, observations and comparisons. Behavioral Ecology and Sociobiology 65, 23--25.

Mazerolle, M. J. (2006) Improving data analysis in herpetology: using Akaike's Information Criterion (AIC) to assess the strength of biological hypotheses. Amphibia-Reptilia 27, 169--180.

Pinheiro, J. C., Bates, D. M. (2000). Mixed-effects Models in S and S-PLUS. Springer Verlag: New York.

Royle, J. A. (2004) N-mixture models for estimating population size from spatially replicated counts. Biometrics 60, 108--115.

See Also

extractCN, extractSE, modavgPred, modavgCustom, modavgEffect, predict, predictSE

Examples

Run this code
# NOT RUN {
##example from subset of models in Table 1 in Mazerolle (2006)
data(dry.frog)

Cand.models <- list( )
Cand.models[[1]] <- lm(log_Mass_lost ~ Shade + Substrate +
                           cent_Initial_mass + Initial_mass2,
                       data = dry.frog)
Cand.models[[2]] <- lm(log_Mass_lost ~ Shade + Substrate +
                           cent_Initial_mass + Initial_mass2 +
                           Shade:Substrate, data = dry.frog)
Cand.models[[3]] <- lm(log_Mass_lost ~ cent_Initial_mass +
                           Initial_mass2, data = dry.frog)
Cand.models[[4]] <- lm(log_Mass_lost ~ Shade + cent_Initial_mass +
                           Initial_mass2, data = dry.frog)
Cand.models[[4]] <- lm(log_Mass_lost ~ Shade + cent_Initial_mass +
                           Initial_mass2, data = dry.frog)
Cand.models[[5]] <- lm(log_Mass_lost ~ Substrate + cent_Initial_mass +
                           Initial_mass2, data = dry.frog)
##assign names
names(Cand.models) <- paste(1:length(Cand.models))

##extract predictors from candidate model set
orig.data <- extractX(cand.set = Cand.models)
orig.data
str(orig.data)

# }
# NOT RUN {
##model-averaged prediction with original variables
modavgPred(Cand.models, newdata = orig.data$data)
# }
# NOT RUN {

##example of model-averaged predictions from N-mixture model (e.g., Royle 2004)
##modified from ?pcount
##each variable appears twice on lambda in the models
# }
# NOT RUN {
require(unmarked)    
data(mallard)
mallardUMF <- unmarkedFramePCount(mallard.y, siteCovs = mallard.site,
                                  obsCovs = mallard.obs)
##set up models so that each variable on abundance appears twice
fm.mall.one <- pcount(~ ivel + date  ~ length + forest, mallardUMF,
                      K = 30)
fm.mall.two <- pcount(~ ivel + date  ~ elev + forest, mallardUMF,
                      K = 30)
fm.mall.three <- pcount(~ ivel + date  ~ length + elev, mallardUMF,
                        K = 30)
fm.mall.four <- pcount(~ ivel + date  ~ 1, mallardUMF, K = 30)

##model list
Cands <- list(fm.mall.one, fm.mall.two, fm.mall.three, fm.mall.four)
names(Cands) <- c("length + forest", "elev + forest", "length + elev",
                  "null")

##extract predictors on lambda
lam.dat <- extractX(cand.set = Cands, parm.type = "lambda")
lam.dat
str(lam.dat)

##extract predictors on detectability
extractX(cand.set = Cands, parm.type = "detect")

##model-averaged predictions on lambda
##extract data
siteCovs <- lam.dat$data$siteCovs
##create vector of forest values
forest <- seq(min(siteCovs$forest),
              max(siteCovs$forest),
              length.out = 40)
dframe <- data.frame(forest = forest,
                     length = mean(siteCovs$length),
                     elev = mean(siteCovs$elev))
modavgPred(Cands, parm.type = "lambda",
           newdata = dframe)
detach(package:unmarked)
# }
# NOT RUN {

##example of model-averaged abundance from distance model
# }
# NOT RUN {
require(unmarked)
data(linetran) #example from ?distsamp
     
ltUMF <- with(linetran, {
  unmarkedFrameDS(y = cbind(dc1, dc2, dc3, dc4),
                  siteCovs = data.frame(Length, area, habitat),
                  dist.breaks = c(0, 5, 10, 15, 20),
                  tlength = linetran$Length * 1000, survey = "line",
                  unitsIn = "m")
})
     
## Half-normal detection function. Density output (log scale). No covariates.
fm1 <- distsamp(~ 1 ~ 1, ltUMF)
     
## Halfnormal. Covariates affecting both density and and detection.
fm2 <- distsamp(~area + habitat ~ habitat, ltUMF)

## Hazard function. Covariates affecting both density and and detection.
fm3 <- distsamp(~area + habitat ~ habitat, ltUMF, keyfun="hazard")

##assemble model list
Cands <- list(fm1, fm2, fm3)

##model-average predictions on abundance
extractX(cand.set = Cands, parm.type = "lambda")
detach(package:unmarked)
# }
# NOT RUN {


##example using Orthodont data set from Pinheiro and Bates (2000)
# }
# NOT RUN {
require(nlme)

##set up candidate models
m1 <- gls(distance ~ age, correlation = corCompSymm(value = 0.5, form = ~ 1 | Subject),
          data = Orthodont, method = "ML")

m2 <- gls(distance ~ 1, correlation = corCompSymm(value = 0.5, form = ~ 1 | Subject),
          data = Orthodont, method = "ML")

##assemble in list
Cand.models <- list("age effect" = m1, "null model" = m2)

##model-averaged predictions
extractX(cand.set = Cand.models)
detach(package:nlme)
# }

Run the code above in your browser using DataLab