Last data update: 2014.03.03

R: Deviance and Pearson Residuals for the Negative Binomial...
residuals.DGEGLMR Documentation

Deviance and Pearson Residuals for the Negative Binomial Model of edgeR

Description

This function implements the residuals method for the edgeR function glmFit.

Usage

## S3 method for class 'DGEGLM'
residuals(object, type = c("deviance", "pearson"), ...)

Arguments

object

An object of class DGEGLM as created by the glmFit function of edgeR.

type

Compute deviance or Pearson residuals.

...

Additional arguments to be passed to the generic function.

Value

A genes-by-samples numeric matrix with the negative binomial residuals for each gene and sample.

Author(s)

Davide Risso

References

McCullagh P, Nelder J (1989). Generalized Linear Models. Chapman and Hall, New York.

Venables, W. N. and Ripley, B. D. (1999). Modern Applied Statistics with S-PLUS. Third Edition. Springer.

Examples

library(edgeR)
library(zebrafishRNASeq)
data(zfGenes)

## run on a subset genes for time reasons 
## (real analyses should be performed on all genes)
genes <- rownames(zfGenes)[grep("^ENS", rownames(zfGenes))]
spikes <- rownames(zfGenes)[grep("^ERCC", rownames(zfGenes))]
set.seed(123)
idx <- c(sample(genes, 1000), spikes)
seq <- newSeqExpressionSet(as.matrix(zfGenes[idx,]))

x <- as.factor(rep(c("Ctl", "Trt"), each=3))
design <- model.matrix(~x)
y <- DGEList(counts=counts(seq), group=x)
y <- calcNormFactors(y, method="upperquartile")
y <- estimateGLMCommonDisp(y, design)
y <- estimateGLMTagwiseDisp(y, design)

fit <- glmFit(y, design)
res <- residuals(fit, type="deviance")
head(res)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(RUVSeq)
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: EDASeq
Loading required package: ShortRead
Loading required package: BiocParallel
Loading required package: Biostrings
Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: XVector
Loading required package: Rsamtools
Loading required package: GenomeInfoDb
Loading required package: GenomicRanges
Loading required package: GenomicAlignments
Loading required package: SummarizedExperiment
Loading required package: edgeR
Loading required package: limma

Attaching package: 'limma'

The following object is masked from 'package:BiocGenerics':

    plotMA

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/RUVSeq/residuals.DGEGLM.Rd_%03d_medium.png", width=480, height=480)
> ### Name: residuals.DGEGLM
> ### Title: Deviance and Pearson Residuals for the Negative Binomial Model
> ###   of 'edgeR'
> ### Aliases: residuals.DGEGLM
> 
> ### ** Examples
> 
> library(edgeR)
> library(zebrafishRNASeq)
> data(zfGenes)
> 
> ## run on a subset genes for time reasons 
> ## (real analyses should be performed on all genes)
> genes <- rownames(zfGenes)[grep("^ENS", rownames(zfGenes))]
> spikes <- rownames(zfGenes)[grep("^ERCC", rownames(zfGenes))]
> set.seed(123)
> idx <- c(sample(genes, 1000), spikes)
> seq <- newSeqExpressionSet(as.matrix(zfGenes[idx,]))
> 
> x <- as.factor(rep(c("Ctl", "Trt"), each=3))
> design <- model.matrix(~x)
> y <- DGEList(counts=counts(seq), group=x)
> y <- calcNormFactors(y, method="upperquartile")
> y <- estimateGLMCommonDisp(y, design)
> y <- estimateGLMTagwiseDisp(y, design)
> 
> fit <- glmFit(y, design)
> res <- residuals(fit, type="deviance")
> head(res)
                            [,1]          [,2]          [,3]          [,4]
ENSDARG00000043686 -0.4451085505  0.6419776552 -0.5013664759 -0.0001414214
ENSDARG00000089089 -0.0001414214 -0.0001414214 -0.0001414214 -0.0001414214
ENSDARG00000060813 -0.0306521830 -0.2307841132  0.2297720295 -0.4940380472
ENSDARG00000092245 -1.4574454937  0.6847358009 -0.1636637476 -1.7267788266
ENSDARG00000094339 -0.0001414214 -0.0001414214 -0.0001414214 -0.0001414214
ENSDARG00000007918  0.7764421556 -0.5915569355 -0.5516327888 -0.2458070838
                            [,5]          [,6]
ENSDARG00000043686 -0.0001414214 -0.0001414214
ENSDARG00000089089 -0.0001414214 -0.0001414214
ENSDARG00000060813 -0.9166316142  0.8705669273
ENSDARG00000092245  1.0161154062 -0.8659257909
ENSDARG00000094339 -0.0001414214 -0.0001414214
ENSDARG00000007918  0.4078691456 -0.2456914590
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>