| compute_gwas_weights | R Documentation |
Runs a per-SNP regression on the training split to obtain effect-size estimates used as polygenic score (PGS) weights in the forward scan.
compute_gwas_weights(
geno,
phenotype1,
this.sample,
this.df,
is_continuous,
covariate_formula = NULL
)
geno |
Matrix of genotype dosages ( |
phenotype1 |
Numeric vector of length |
this.sample |
Integer vector. Row indices of the training split in
|
this.df |
Data frame of covariates with rows aligned to |
is_continuous |
Logical. |
covariate_formula |
Character. The right-hand side of the regression
formula including the SNP term |
For continuous traits (is_continuous = TRUE) the function
fits lm(phenotype1 ~ this.x) for each SNP, excluding samples with
missing dosage via na.omit. The covariates are assumed to have
already been residualised from phenotype1 before this function is
called (as done in ras_scan).
For binary traits (is_continuous = FALSE) the function
builds a data frame combining the training-split rows of this.df
with the dosage column (this.x) and phenotype (phenotype1),
removes incomplete cases with na.omit, and fits
lm(phenotype1 ~ covariate_formula). Note that lm rather
than glm(family = binomial) is used at the GWAS weight stage
to obtain a linear probability approximation to the effect size; this is
consistent with standard GWAS practice for weight derivation.
Both branches are vectorised: instead of fitting one lm per SNP, all
NA-free SNPs are solved in closed form with a single BLAS cross-product
(continuous) or a batched Frisch-Waugh-Lovell residualisation (binary).
SNP columns that contain missing dosages are handled individually so the
result matches lm + na.omit exactly. A single
“Starting GWAS ...” message is printed.
A numeric matrix with N rows and 4 columns:
EstimatePer-SNP effect-size estimate (slope of the dosage
term). The first column is used as PGS weights by
compute_pgs_matrix.
Std. ErrorStandard error of the estimate.
t valuet-statistic.
Pr(>|t|)Two-sided p-value.
compute_pgs_matrix for the next step, which multiplies
these weights by the hold-out genotype matrix.
ras_scan for the recommended high-level entry point that
calls this function automatically.
set.seed(1)
n_samp <- 60; n_snp <- 10
geno <- matrix(sample(0:2, n_samp * n_snp, replace = TRUE,
prob = c(0.6, 0.3, 0.1)),
nrow = n_samp, ncol = n_snp)
pheno_train <- rnorm(n_samp)
coef_mat <- compute_gwas_weights(
geno = geno,
phenotype1 = pheno_train,
this.sample = seq_len(n_samp),
this.df = data.frame(row.names = seq_len(n_samp)),
is_continuous = TRUE
)
dim(coef_mat) # n_snp x 4
head(coef_mat, 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.