Learn R Programming

ANTsR (version 1.0)

bigLMStats: Efficiently compute basic statistical inference from regressions with multiple outcomes

Description

This function simplifies calculating p-values from linear models in which there are many outcome variables, such as in voxel-wise regressions. To perform such an analysis in R, you can concatenate the outcome variables column-wise into an n by p matrix y, where there are n subjects and p outcomes (see Examples). Calling lm(y~x) calculates the coefficients, but statistical inference is not provided. This function provides basic statistical inference efficiently.

Usage

bigLMStats(mylm, lambda )

Arguments

mylm

Object of class lm.

Value

A list containing objects:

fstat

F-statistic of whole model (one value per outcome).

pval.model

p-value of model (one value per outcome).

beta

Values of coefficients (one value per predictor per outcome).

beta.std

Standard error of coefficients.

beta.t

T-statistic of coefficients.

beta.pval

p-value of coefficients.

Examples

Run this code
# NOT RUN {
nsub <- 100
set.seed(1500)
x <- 1:nsub
y <- matrix(c(x + rnorm(nsub), sin(x)), nrow=nsub)
x <- cbind(x, x^2)
y1 <- y[, 1]
y2 <- y[, 2]
lm1 <- lm(y1~x)
lm2 <- lm(y2~x)
mylm <- lm(y ~ x)

myest <- bigLMStats(mylm)
print(paste('R beta estimates for first outcome is', summary(lm1)$coefficients[-1,1],
            'and for second outcome is', summary(lm2)$coefficients[-1,1]))
print(paste('and our estimate is', as.numeric(myest$beta[,1]), as.numeric(myest$beta[,2])))
print(paste('R std error estimate for first outcome is', summary(lm1)$coefficients[-1,2], 
            'and for second outcome is', summary(lm2)$coefficients[-1,2],
            'and our estimate is', myest$beta.std[,1], myest$beta.std[,2]))
print(paste('R t value estimate for first outcome is', summary(lm1)$coefficients[-1,3],
            'and for second outcome is', summary(lm2)$coefficients[-1,3],
            'and our estimate is', myest$beta.t[,1], myest$beta.t[,2]))
print(paste('R pval for first outcome is', summary(lm1)$coefficients[-1,4],
            'and for second outcome is', summary(lm2)$coefficients[-1,4],
            'and our estimate is', myest$beta.pval[,1], myest$beta.pval[,2]))
# }

Run the code above in your browser using DataLab