Model.selection {biology}R Documentation

~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

Model.selection(object, data)

Arguments

object ~~Describe object here~~
data ~~Describe data here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use

comp1 Description of 'comp1'
comp2 Description of 'comp2'

...

Warning

....

Note

~~further notes~~

~Make other sections like Warning with section{Warning }{....} ~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (object, data) 
{
    library(hier.part)
    library(nlme)
    library(R.utils)
    predictors <- dimnames(attr(object$terms, "factors"))[[2]]
    comb <- combos(length(predictors))[[1]]
    ll <- length(comb[, 1])
    var.names <- vector(mode = "character", length = ll)
    d <- data.frame(r.squared = 1:ll, Adj.r.sq = 1:ll, P = 1:ll, 
        Cp = 1:ll, AIC = 1:ll, BIC = 1:ll, Select = factor(rep(" ", 
            ll), levels = c(" ", "*")))
    form <- object$call$formula
    minAIC = 1e+05
    minBIC = 1e+05
    minCp <- 1e+05
    for (i in 1:length(comb[, 1])) {
        pred <- predictors[comb[i, ]]
        var.names[i] <- paste(pred, collapse = "+")
        ii <- paste(pred, collapse = "+", sep = "")
        new_fit <- update.formula(form, paste("~  +", ii))
        fit <- lm(new_fit, data = data)
        fit_sum <- summary(lm(fit))
        d$r.squared[i] <- fit_sum$r.squared
        d$Adj.r.sq[i] <- fit_sum$adj.r.squared
        d$P[i] <- fit_sum$fstatistic[["numdf"]]
        d$Cp[i] <- Cp(fit, object)
        deltaCp <- abs(d$Cp[i] - d$P[i])
        d$AIC[i] <- extractAIC(fit)[2]
        if (minCp > d$Cp[i]) 
            minCp <- d$Cp[i]
        if (minAIC > d$AIC[i]) 
            minAIC <- d$AIC[i]
        d$BIC[i] <- extractAIC(fit, k = log(nrow(data)))[2]
        if (minBIC > d$BIC[i]) 
            minBIC <- d$BIC[i]
    }
    rownames(d) <- var.names
    d$Select[d$BIC == minBIC] <- "*"
    d$Select[d$AIC == minAIC] <- "*"
    d$Select[d$Cp == minCp] <- "*"
    d
  }

[Package biology version 1.0 Index]