Learn R Programming

AICcmodavg (version 2.3-2)

extractX: Extract Predictors from Candidate Model List

Description

This function extracts the predictors used in candidate models. The function is currently implemented for glm, glmmTMB, gls, lm, lme, merMod, lmerModLmerTest, 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 AICglmmTMB 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 AIClmerModLmerTest 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, ...)

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

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

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

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

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

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).

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 predictors will be extracted and is only relevant for models of unmarkedFit classes. The character strings supported vary with the type of model fitted. For unmarkedFitOccu and unmarkedFitOccuMulti objects, either psi or detect can be supplied to indicate whether the parameter is on occupancy or detectability, respectively. For unmarkedFitColExt and unmarkedFitOccuTTD, 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 unmarkedFitOccuMS objects, possible values are psi, phi, or detect, denoting occupancy, transition, and detection probabilities, 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, unmarkedFitMMO, and unmarkedFitDSO 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.

Author

Marc J. Mazerolle

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
##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)

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


##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
if (FALSE) {
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)
}


##example of model-averaged abundance from distance model
if (FALSE) {
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)
}



##example using Orthodont data set from Pinheiro and Bates (2000)
if (FALSE) {
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