lm.II {biology}R Documentation

~~function to do ... ~~

Description

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

Usage

lm.II(formula, data, print = "all", type = "RMA", plot = F, zero = F, ...)

Arguments

formula ~~Describe formula here~~
data ~~Describe data here~~
print ~~Describe print here~~
type ~~Describe type here~~
plot ~~Describe plot here~~
zero ~~Describe zero here~~
... ~~Describe ... 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 (formula, data, print = "all", type = "RMA", plot = F, 
    zero = F, ...) 
{
    cl <- match.call()
    mf <- form.call <- match.call(expand.dots = FALSE)
    m <- match(c("formula", "data", "subset", "weights", "na.action", 
        "offset"), names(mf), 0)
    mf <- mf[c(1, m)]
    mf[[1]] <- as.name("lm")
    mf <- eval(mf, parent.frame())
    terms <- mf$terms
    x <- model.matrix(mf)
    var.names <- colnames(x)
    asgn <- attr(x, "assign")
    tl <- attr(mf$terms, "term.labels")
    response <- response(mf)
    responseName <- responseName(mf)
    tab <- NULL
    stats <- NULL
    if (is.null(weights(mf))) 
        wt <- rep(1, length(response))
    else wt <- weights(mf)
    if (length(var.names) > 2) {
        if (plot == T) {
            save.mfrow <- par(mfrow = mfrow(length(var.names)))
            on.exit(par(mfrow = save.mfrow))
        }
        for (i in var.names) {
            var <- which(i == var.names)
            res <- lsfit(x[, -var], cbind(x[, var], response), 
                wt = wt, intercept = FALSE)$residuals
            z <- m2regress(res[, 1], res[, 2], type = type, zero = zero)$coef[2, 
                ]
            zz <- matrix(z$stats[2, ], nrow = 1)
            rownames(zz) <- i
            z <- matrix(z$coef[2, ], nrow = 1)
            a <- mean(res[, 2]) - (z[1] * mean(res[, 1]))
            rownames(z) <- i
            tab <- rbind(tab, i = z)
            stats <- rbind(stats, i = zz)
            if (plot == T) {
                plot(res[, 1], res[, 2], xlab = paste(i, "| others"), 
                  ylab = paste(responseName, " | others"), las = 1, 
                  col = "black", pch = 16)
                abline(a, z[[1]], col = "red", lwd = 1.5)
            }
        }
    }
    else {
        var <- which(var.names[2] == var.names)
        z <- m2regress(x[, var], response, type = type, zero = zero)
        zz <- matrix(z$stats, nrow = 2)
        rownames(zz) <- c("(Intercept)", var.names[2])
        z <- matrix(z$coef, nrow = 2)
        rownames(z) <- c("(Intercept)", var.names[2])
        tab <- rbind(tab, z)
        stats <- rbind(stats, zz)
        if (plot == T) {
            plot(x[, var], response, xlab = paste(var.names[2]), 
                ylab = paste(responseName), las = 1, col = "black", 
                pch = 16)
            abline(z[1], z[2], col = "red", lwd = 1.5)
        }
    }
    colnames(stats) <- c("St. Error", "t value", "Pr(>|t|)", 
        "CI 2.5%", "CI 97.5%")
    colnames(tab) <- c("Estimate")
    l <- list(coefficients = tab, statistics = stats, call = form.call, 
        terms = terms, model = mf$model, xlevels = mf$xlevels)
    class(l) <- "lm2"
    l
  }

[Package biology version 1.0 Index]