data: Matrix of data with genes in rows and cells in columns.
ndims: Number of dimensions to return
nsig: For automatic sigma calculation
removeFirst: Default TRUE. Removes the first eigenvector
useARPACK: Default TRUE. Uses Arnoldi algorithm for eignvector calculations
distfun: A different distance function that returns the squared
distance
sigmas: Manually provide sigma
sqdistmat: Squared distance matrix. Give your own squared distance matrix.
Returns
List output containing:
values
Eigenvalues, excluding the first eigenvalue, which should
always be 1.|
|vectors|Matrix of eigen vectors in columns, first eigen vector
removed.|
|nconv|Number of eigen vectors/values that converged.|
|niter|Iterations taken for Arnoldi algorithm to converge.|
|nops|Number of operations.|
|val0|1st eigen value - should be 1. If not be suspicious!|
|vec0|1st eigen vector - should be 1/sqrt(n) ,
where n is the number of cells/samples.|
|usedARPACK|Predicates use of ARPACK for spectral decomposition.|
|distfun|Function used to calculate the squared distance.|
|nn|Number of nearest neighbours used for calculating sigmas .|
|d2|Matrix of squared distances, returned from distfun .|
|sigmas|Vector of sigmas. Same length as number of cells if individual|
||sigmas were calculated, otherwise a scalar if was supplied.|
|gaussian|Unnormalised transition matrix after applying Gaussian.|
|markov|Normalised gaussian matrix.|
|densityCorrected|Matrix after applying density correction to
markov .|
Details
Generic diffusion function using automated individualised sigma calculation.
A Gaussian kernel is applied to the chosen distance metric producing an n×n square unnormalised symmetric transition matrix, A. Let D be an n×n diagonal matrix with row(column) sums of A as entries. The density corrected transition matrix will now be:
D−1AD−1D−1∗A∗D−1
and can be normalised:
B−1D−1AD−1B−1∗D−1∗A∗D−1
where B is an n×n diagonal matrix with row sums of the density corrected transition matrix as entries. The eigen decomposition of this matrix can be simplified by solving the symmetric system:
B−21D−1AD−1B−21R′=
where R′ is a matrix of the right eigenvectors that solve the system and L′ is the corresponding eigenvalue diagonal matrix. Now the solution of:
B−1D−1AD−1R=Rλ
in terms of R′ and B−21 is:
B−1D−1AD−1B−21R′=
and
R=B−21R\primeR=B−0.5∗R′
This R without the first eigen vector is returned as the diffusion map.
Examples
## Not run:xx <- diffuseMat(x)## End(Not run)
References
Haghverdi, L., Buettner, F., Theis, F.J., 2015. Diffusion maps for high-dimensional single-cell analysis of differentiation data. Bioinformatics 31, 2989–2998.
Angerer, P., Haghverdi, L., Büttner, M., Theis, F.J., Marr, C., Buettner, F., 2016. destiny: diffusion maps for large-scale single-cell data in R. Bioinformatics 32, 1241–1243.