compute_pgs_matrix: Build the Per-Individual PGS Contribution Matrix

View source: R/gwas.R

compute_pgs_matrixR Documentation

Build the Per-Individual PGS Contribution Matrix

Description

Multiplies each hold-out individual's genotype dosages by the per-SNP PGS weights to produce a matrix of weighted dosage contributions used in the forward scan.

Usage

compute_pgs_matrix(geno, this.leftout, pgs.weights)

Arguments

geno

Matrix of genotype dosages (n samples \times N variants). NA values are replaced with 0 in-place before multiplication.

this.leftout

Integer vector. Row indices of the hold-out split in geno.

pgs.weights

Numeric vector of length N. Per-SNP effect-size weights, typically the Estimate column from compute_gwas_weights.

Details

Missing genotype values (NA) in geno are imputed to zero before computing the product. This is a simple mean-imputation equivalent under a centred dosage scale and is sufficient for the forward scan, where the primary goal is to aggregate regional signals rather than obtain individual-level accuracy.

The caller's geno object is not modified: the NA-replacement assignment triggers R's copy-on-modify semantics, so a local copy of geno is made inside the function. Callers working with very large genotype matrices should be aware that this temporarily doubles the memory footprint of geno during the call; use ras_memory to check feasibility before running.

Value

A numeric matrix of dimensions |\texttt{this.leftout}| \times N, where entry [i, j] is the weighted dosage contribution of SNP j for hold-out individual i (i.e., geno[this.leftout[i], j] * pgs.weights[j]).

See Also

compute_gwas_weights for the step that produces pgs.weights. screen_forward_max_region for the step that consumes this matrix. ras_memory for pre-flight memory estimation.

Examples

set.seed(2)
geno    <- matrix(sample(0:2, 50 * 20, replace = TRUE), nrow = 50, ncol = 20)
weights <- rnorm(20)
leftout <- 1:15

pgs_mat <- compute_pgs_matrix(geno, leftout, weights)
dim(pgs_mat)   # 15 x 20

## Entry [i, j] equals geno[leftout[i], j] * weights[j]
stopifnot(pgs_mat[1, 1] == geno[leftout[1], 1] * weights[1])

RAS documentation built on July 24, 2026, 5:06 p.m.