Skip to contents

Simulates multivariate GWAS summary statistics given a genetic covariance structure. Drop-in replacement for GenomicSEM::simLDSC(): writes the same per-trait sumstats files (iter<r>GWAS<i>.sumstats[.gz]) and PopCovMat.RData to the working directory that R's upstream produces, and prints the same "Writing sumstats for Phenotype i" banner. The simulated k x n_snps Z-score matrix is returned invisibly as a gsemr extension — assign the call to capture it, or ignore it to match R's NULL-returning behaviour exactly.

Usage

simLDSC(
  covmat,
  N,
  seed = 1234,
  ld,
  rPheno = NULL,
  int = NULL,
  N_overlap = 0.99,
  r = 1,
  gzip_output = TRUE,
  parallel = FALSE,
  cores = NULL
)

Arguments

covmat

Population genetic covariance matrix (matrix or data.frame)

N

Sample size: either a scalar (applied to all traits via diag(N, k, k)), a length-k vector (per-trait), or a k x k sample-size matrix with sample overlap on the off-diagonal. Matches GenomicSEM::simLDSC(), which also accepts scalar or matrix N.

seed

Random seed (ignored in gsemr – Rust uses its own RNG)

ld

Path to LD score directory

rPheno

Phenotypic correlation matrix (default NULL = no environmental correlation)

int

LDSC intercept matrix (default NULL = identity)

N_overlap

Sample overlap proportion (default 0.99)

r

Replication index — feeds into the output filename pattern iter<r>GWAS<i>.sumstats. gsemr returns a single replication; values r > 1 are accepted for API compatibility but only the single replication is written (under the given r).

gzip_output

Compress output with gzip (default TRUE)

parallel

Accepted for API compatibility; gsemr's simLDSC is currently single-threaded so this has no effect.

cores

Accepted for API compatibility; see parallel.

Value

Invisibly, a matrix of simulated Z-statistics with shape k traits x n_snps. Side-effects: writes iter<r>GWAS<i>.sumstats[.gz] for each trait and PopCovMat.RData to the current working directory, matching R upstream.

Examples

if (FALSE) { # \dontrun{
# Simulate per-trait sumstats from a target genetic covariance matrix.
covmat <- matrix(c(0.60, 0.42, 0.42, 0.50), 2, 2,
                 dimnames = list(c("T1","T2"), c("T1","T2")))
sim <- simLDSC(
  covmat = covmat,
  N = 1e5,
  ld = "eur_w_ld_chr/"
)
# Writes iter1GWAS1.sumstats.gz, iter1GWAS2.sumstats.gz, PopCovMat.RData.
} # }