Skip to contents

Eigendecompose an LD reference, block by block, into the LdEigen that estimateH2 consumes for method = "lder" and method = "hdl". This is the supported route from an LD reference to an h2 input: LdEigen itself is the low-level constructor and expects the decompositions to have been computed already.

Usage

buildLdEigen(
  ldReference,
  ldBlocks = NULL,
  nSamples = NULL,
  inSample = FALSE,
  genome = NA_character_,
  eigenvalueTruncation = 1
)

Arguments

ldReference

The LD reference, block by block: a list of LdMatrix objects, one per LD block (a single LdMatrix is one block), or a genotype panel (see readGenotypes) together with ldBlocks. Blocks are kept in the order given, and that order defines the variant order of the result.

Block structure matters downstream: estimateH2 takes its standard error from a delete-one-block jackknife, so it requires at least two blocks and wants many more.

ldBlocks

With a genotype panel, the LD blocks to cut it into: a GRanges, or a data frame with columns chrom, start and end. Each block's LD is computed from the panel variants inside it; variants outside every block are left out. Not used with LdMatrix blocks.

nSamples

Integer, the number of samples the reference's LD was estimated from. Defaults to a panel's sample count (a stochastic sketch's effective size), or the size the LdMatrix blocks record; required when they record none, and an error when they disagree.

inSample

Logical, whether the reference is the GWAS cohort itself. Selects LDER's weighting and HDL's finite-reference correction.

genome

Character, genome build. Defaults to the build recorded by the reference's variants.

eigenvalueTruncation

Numeric in (0, 1]; the proportion of each block's eigenvalue mass to retain. 1 (the default) keeps every component; HDL conventionally uses 0.9.

Value

An LdEigen over every variant in the reference's blocks. One built from a genotype panel keeps the panel and decomposes each block when it is needed, rather than storing the decompositions.

See also

buildLdScore for the g-LDSC input, estimateH2, LdMatrix

Examples

panel <- readGenotypes(plink2Prefix = file.path(system.file("extdata",
  "ld_reference", "chr22", package = "pecotmr"),
  "protocol_example.LD.chr22"))
blocks <- data.frame(chrom = "chr22", start = c(10000000, 15000001),
  end = c(15000000, 19000000))
ldEigen <- buildLdEigen(panel, ldBlocks = blocks, genome = "hg38")
ldEigen
#> LdEigen: 175 SNPs across 2 blocks
#>   Eigenvalue truncation: 1.00
#>   Decompositions: computed from the genotype panel when needed
#>   Reference N: 57, In-sample: FALSE
length(eigenList(ldEigen))
#> [1] 2