makeSparseMatrix | R Documentation |
makeSparseMatrix
is used to create a sparse block-diagonal matrix from a dense matrix or a table of pairwise values, using a user-specified threshold for sparsity. An object of class Matrix
will be returned. A sparse matrix may be useful for fitting the association test null model with fitNullModel
when working with very large sample sizes.
## S4 method for signature 'data.table'
makeSparseMatrix(x, thresh = NULL, sample.include = NULL, diag.value = NULL,
verbose = TRUE)
## S4 method for signature 'data.frame'
makeSparseMatrix(x, thresh = NULL, sample.include = NULL, diag.value = NULL,
verbose = TRUE)
## S4 method for signature 'matrix'
makeSparseMatrix(x, thresh = 2^(-11/2), sample.include = NULL, diag.value = NULL,
verbose = TRUE)
## S4 method for signature 'Matrix'
makeSparseMatrix(x, thresh = 2^(-11/2), sample.include = NULL, diag.value = NULL,
verbose = TRUE)
x |
An object to coerce to a sparse matrix. May be of class |
thresh |
Value threshold for clustering samples to make the output matrix sparse block-diagonal. When |
sample.include |
An optional vector of sample.id indicating all samples that should be included in the output matrix; see 'Details' for usage. |
diag.value |
When |
verbose |
A logical indicating whether or not to print status updates to the console; the default is TRUE. |
sample.include
has two primary functions: 1) It can be used to subset samples provided in x
. 2) sample.include
can include sample.id not in x
; these additional samples will be included in the output matrix, with a value of 0 for all off-diagonal elements, and the value provided by diag.value
for the diagonal elements. When left NULL
, the function will determine the list of samples from what is observed in x
.
thresh
sets a threhsold for clustering samples such that any pair with a value greater than thresh
is in the same cluster. All values within a cluster are kept, even if they are below thresh
. All values between clusters are set to 0, creating a sparse, block-diagonal matrix. When thresh
is NULL
, no clustering is done and all samples are returned in one block. This feature is useful when converting a data.frame of kinship estimates to a matrix.
An object of class 'Matrix
'. Samples may be in a different order than in the input x
, as samples are sorted by ID or rowname within each block (including within the block of unrelateds).
Matthew P. Conomos
kingToMatrix
and pcrelateToMatrix
for functions that use this function.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.