Wrap an LD correlation matrix, or combine several into a
mixture, for use as an LD reference. See LdMatrix-class.
One panel's LD. Pass the matrix and the variants it covers.
The variants may be given as a GRanges (metadata columns
A1, A2, and optionally SNP and AF), as a
data frame with columns chrom, pos, A1, A2
(and optionally SNP, AF), or omitted when the matrix's
dimnames are chrom:pos:A2:A1 ids, from which they are parsed. The
correlations must be signed by the dosage of A1.
A mixture. Pass a list of LdMatrix objects and their
mixtureWeights. The result is their weighted average
\(\sum_k w_k R_k\), computed once here, over the variants every
component covers; a variant some component lacks is left out, with a
message. Components are matched by position and alleles and put into
the first component's allele coding, so they need not share variant ids
or allele orientation. The mixture's AF is \(\sum_k w_k AF_k\)
when every component records AF, and its nSamples is
\(1 / \sum_k w_k^2 / n_k\) when every component records a size.
Arguments
- correlation
A numeric correlation matrix, or a list of
LdMatrixobjects to combine into a mixture.- variants
The variants the matrix covers, in its row order: a
GRangesor a data frame (see Description), orNULLto parse them from the matrix's dimnames. Not used for a mixture.- nSamples
The size of the panel the LD was estimated from, or
NAwhen unknown. Not used for a mixture.- mixtureWeights
For a mixture, one non-negative weight per component, summing to 1.
Examples
data(eqtlRegionExample)
X <- eqtlRegionExample$X[, 1:8]
ld <- LdMatrix(cor(X), nSamples = nrow(X))
ld
#> LdMatrix: 8 variants, panel size 415
#> no allele frequencies
ldMatrix(ld)[1:3, 1:3]
#> chr22:32119788:T:C chr22:32119867:T:G chr22:32119961:T:G
#> chr22:32119788:T:C 1.0000000 1.0000000 -0.3896071
#> chr22:32119867:T:G 1.0000000 1.0000000 -0.3896071
#> chr22:32119961:T:G -0.3896071 -0.3896071 1.0000000
# A mixture of two panels' LD, weighted 3:1.
half <- seq_len(nrow(X) / 2)
ldA <- LdMatrix(cor(X[half, ]), nSamples = length(half))
ldB <- LdMatrix(cor(X[-half, ]), nSamples = nrow(X) - length(half))
LdMatrix(list(ldA, ldB), mixtureWeights = c(0.75, 0.25))
#> LdMatrix: 8 variants, panel size 331
#> mixture of 2 panels, weights 0.75, 0.25
#> no allele frequencies