getF: Given two nested models, calculate the F-statistics

View source: R/getF.R

getFR Documentation

Given two nested models, calculate the F-statistics

Description

For some data Y organized in a matrix, calculate a F-statitic per row comparing two nested models.

Usage

getF(fit, fit0, theData)

Arguments

fit

An object created with lmFit using the alternative model (the larger model).

fit0

An object created with lmFit using the null model (the smaller model, nested in the larger one).

theData

The data used in the lmFit call.

Details

This function can also work with outputs from lm.

Value

A data.frame with the F-statistics (fstat), the degrees of freedom for the nallternative model (df1), the null model (df0), and the p-value given the F-distribution (f_pval).

Author(s)

Leonardo Collado-Torres, Andrew E Jaffe

Examples


set.seed(20161005)
## From limma::limFit example page:
sd <- 0.3 * sqrt(4 / rchisq(100, df = 4))
y <- matrix(rnorm(100 * 6, sd = sd), 100, 6)
rownames(y) <- paste("Gene", seq_len(100))
y[seq_len(2), seq_len(3) + 3] <- y[seq_len(2), seq_len(3) + 3] + 4

## Define the alternative and null models
pheno <- data.frame(group = rep(c(0, 1), each = 3), RIN = runif(6) + 8)
mod <- model.matrix(~ pheno$group + pheno$RIN)
mod0 <- model.matrix(~ pheno$RIN)

## Fit the models
library("limma")
fit <- lmFit(y, mod)
fit0 <- lmFit(y, mod0)

## Calculate the F statistics for these nested models
finfo <- getF(fit, fit0, y)
head(finfo)

## You can then use p.adjust() for multiple testing corrections
qvals <- p.adjust(finfo$f_pval, "fdr")
summary(qvals)

LieberInstitute/jaffelab documentation built on April 1, 2024, 7:26 a.m.