getR2 | R Documentation |
Using limma, calculate the R squared from a matrix using nested models
getR2(p, mod, mod0 = NULL)
p |
A matrix that will be passed to lmFit |
mod |
A model matrix for the alternative model (the larger one). |
mod0 |
A model matrix for the null model (the smaller one). If |
A data.frame with the R squared and the adjusted R squared.
Andrew E Jaffe, Leonardo Collado-Torres (examples)
## Define a model generating function for 30 'samples'
set.seed(20190827)
model_fun <- function(x) {
## Baseline + a group effect (2 groups) + a second covariate effect
rnorm(30) +
c(rnorm(15, mean = 3), rnorm(15, mean = 1)) +
c(
rnorm(5, sd = 0.5), rnorm(5, sd = 0.2, mean = 0.5),
rnorm(5, sd = 0.2, mean = 0.9)
)
}
## Generate the data for 20 'genes'
p <- t(sapply(seq_len(20), model_fun))
## Define the phenotype data for these 30 'samples'
pheno <- data.frame(
group = rep(c("A", "B"), each = 15),
batch = rep(seq_len(3), each = 5)
)
## Define a full model
mod <- with(pheno, model.matrix(~ group + batch))
## and compute the R2 for each 'gene'
getR2(p, mod)
## Define a smaller model
mod0 <- with(pheno, model.matrix(~group))
## And now compute the new R2 for each 'gene'
getR2(p, mod, mod0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.