Description Usage Arguments Details Value Functions Caveats See Also Examples
Using the delta method, estimate the log-fold change from a state given by a vector contrast0 and the state(s) given by contrast1.
1 2 3 |
zlmfit |
ZlmFit output |
contrast0 |
vector of coefficients giving baseline contrast, or a |
contrast1 |
matrix of coefficients giving comparison contrasts, or a |
The log-fold change is defined as follows. For each gene, let u(x) be the expected value of the continuous component, given a covariate x and the estimated coefficients coefC
, ie, u(x)= crossprod(x, coefC)
.
Likewise, Let v(x)= 1/(1+exp(-crossprod(coefD, x)))
be the expected value of the discrete component.
The log fold change from contrast0 to contrast1 is defined as
u(contrast1)v(contrast1)-u(contrast0)v(contrast0).
Note that for this to be a log-fold change, then the regression for u must have been fit on the log scale. This is returned in the matrix logFC
.
An approximation of the variance of logFC
(applying the delta method to formula defined above) is provided in varLogFC
.
list of matrices 'logFC' and 'varLogFC', giving the log-fold-changes for each contrast (columns) and genes (rows) and the estimated sampling variance thereof
getLogFC
: Return results as a perhaps friendlier data.table
1. When method='bayesglm'
(the default), it's no longer necessarily true that the log fold change from condition A to B will be the inverse of the log fold change from B to A if the models are fit separately.
This is due to the shrinkage in bayesglm
.
2. The log fold change can be small, but the Hurdle p-value small and significant when the sign of the discrete and continuous model components are discordant so that the marginal log fold change cancels out. The large sample sizes present in many single cell experiments also means that there is substantial power to detect even small changes.
3. When there is no expression in a gene for a coefficient that is non-zero in either condition0
or condition1
we return NA
because there is not any information
to estimate the continuous component. Technically we might return plus or minus infinity,
but there is not a straightforward way to estimate a confidence interval in any case.
See https://support.bioconductor.org/p/99244/ for details
Hypothesis
summary,ZlmFit-method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | data(vbetaFA)
zz <- zlm( ~ Stim.Condition+Population, vbetaFA[1:5,])
##log-fold changes in terms of intercept (which is Stim(SEB) and CD154+VbetaResponsive)
lfcStim <- logFC(zz)
##If we want to compare against unstim, we can try the following
coefnames <- colnames(coef(zz, 'D'))
contrast0 <- setNames(rep(0, length(coefnames)), coefnames)
contrast0[c('(Intercept)', 'Stim.ConditionUnstim')] <- 1
contrast1 <- diag(length(coefnames))
rownames(contrast1)<-colnames(contrast1)<-coefnames
contrast1['(Intercept)',]<-1
lfcUnstim <- logFC(zz, contrast0, contrast1)
##log-fold change with itself is 0
stopifnot(all(lfcUnstim$logFC[,2]==0))
##inverse of log-fold change with Stim as reference
stopifnot(all(lfcStim$logFC[,1]==(-lfcUnstim$logFC[,1])))
##As a data.table:
getLogFC(zz)
|
Loading required package: SummarizedExperiment
Loading required package: GenomicRanges
Loading required package: stats4
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, sd, var, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, basename, cbind, colMeans, colSums, colnames,
dirname, 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,
rowMeans, rowSums, rownames, sapply, setdiff, sort, table, tapply,
union, unique, unsplit, which, which.max, which.min
Loading required package: S4Vectors
Attaching package: 'S4Vectors'
The following object is masked from 'package:base':
expand.grid
Loading required package: IRanges
Loading required package: GenomeInfoDb
Loading required package: Biobase
Welcome to Bioconductor
Vignettes contain introductory material; view with
'browseVignettes()'. To cite Bioconductor, see
'citation("Biobase")', and for packages 'citation("pkgname")'.
Loading required package: DelayedArray
Loading required package: matrixStats
Attaching package: 'matrixStats'
The following objects are masked from 'package:Biobase':
anyMissing, rowMedians
Attaching package: 'DelayedArray'
The following objects are masked from 'package:matrixStats':
colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges
The following object is masked from 'package:base':
apply
Attaching package: 'MAST'
The following object is masked from 'package:stats':
filter
Warning messages:
1: no function found corresponding to methods exports from 'DelayedArray' for: 'acbind', 'arbind'
2: no function found corresponding to methods exports from 'SummarizedExperiment' for: 'acbind', 'arbind'
Done!
primerid contrast logFC varLogFC
1: B3GAT1 Stim.ConditionUnstim -0.05717195 0.6324474
2: B3GAT1 PopulationCD154+VbetaUnresponsive -0.28467795 0.4957791
3: B3GAT1 PopulationCD154-VbetaResponsive NaN NaN
4: B3GAT1 PopulationCD154-VbetaUnresponsive -0.73597249 0.2502919
5: B3GAT1 PopulationVbetaResponsive -0.73713842 0.2645474
6: B3GAT1 PopulationVbetaUnresponsive -0.37754594 0.3765092
7: BAX Stim.ConditionUnstim -0.43275760 1.6497560
8: BAX PopulationCD154+VbetaUnresponsive -1.29197981 2.6550423
9: BAX PopulationCD154-VbetaResponsive -0.61352080 2.7503564
10: BAX PopulationCD154-VbetaUnresponsive -1.95097043 1.7282713
11: BAX PopulationVbetaResponsive 1.08078307 2.2660863
12: BAX PopulationVbetaUnresponsive 1.33097535 2.3109374
13: BCL2 Stim.ConditionUnstim -1.64819989 0.2828739
14: BCL2 PopulationCD154+VbetaUnresponsive 0.60475231 1.4007298
15: BCL2 PopulationCD154-VbetaResponsive NaN NaN
16: BCL2 PopulationCD154-VbetaUnresponsive -0.19121849 0.7824061
17: BCL2 PopulationVbetaResponsive 1.50241843 1.3773279
18: BCL2 PopulationVbetaUnresponsive 1.53341248 1.4119269
19: CCL2 Stim.ConditionUnstim 1.19557602 3.4427019
20: CCL2 PopulationCD154+VbetaUnresponsive 0.05906539 0.9221676
21: CCL2 PopulationCD154-VbetaResponsive -0.55337771 0.6023910
22: CCL2 PopulationCD154-VbetaUnresponsive -0.17770906 0.5511114
23: CCL2 PopulationVbetaResponsive -1.00620857 0.3483649
24: CCL2 PopulationVbetaUnresponsive -1.01896361 0.3446719
25: CCL3 Stim.ConditionUnstim -2.63059991 1.8149519
26: CCL3 PopulationCD154+VbetaUnresponsive -1.10842024 2.6128681
27: CCL3 PopulationCD154-VbetaResponsive -3.09883781 1.5361872
28: CCL3 PopulationCD154-VbetaUnresponsive -2.51342528 1.2828719
29: CCL3 PopulationVbetaResponsive -2.64108661 1.5307965
30: CCL3 PopulationVbetaUnresponsive -3.11787999 1.3236893
primerid contrast logFC varLogFC
z
1: -0.07189038
2: -0.40430559
3: NaN
4: -1.47108647
5: -1.43316857
6: -0.61529305
7: -0.33692625
8: -0.79290290
9: -0.36994299
10: -1.48403698
11: 0.71796010
12: 0.87553985
13: -3.09894170
14: 0.51097582
15: NaN
16: -0.21617914
17: 1.28018349
18: 1.29048477
19: 0.64435839
20: 0.06150751
21: -0.71298836
22: -0.23938110
23: -1.70478969
24: -1.73562443
25: -1.95264027
26: -0.68571825
27: -2.50021164
28: -2.21908702
29: -2.13463639
30: -2.70998176
z
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.