Applies a trained B estimation model to new MAF values without re-training. This enables the "train once, predict many times" workflow needed by the GLOW testing integration pipeline.

For models trained via the beta method, the function predicts BETA^2 from MAF and back-transforms to B = sqrt(BETA^2).

For models trained via the p-value method, the function predicts h-squared from MAF and converts to B using trait-specific formulas:

  • Continuous traits: \(B = \sqrt{h^2} \times SE\)

  • Binary traits: \(B = \sqrt{h^2} / \sqrt{p_0 (1 - p_0)}\) where \(p_0\) is the case proportion

predict_B(
  model,
  target_MAF,
  target_trait = NULL,
  target_SE = NULL,
  target_case_prop = NULL,
  method = "auto"
)

Arguments

model

A glow_B_model object (from train_B_model), or a raw lm object with a model_id attribute indicating which of the 8 candidate models it represents. For glow_B_model objects, the function extracts the appropriate lm model based on the method parameter.

target_MAF

Numeric vector of MAF values to predict B for. Values should be in [0, 0.5]. Values > 0.5 are automatically folded to 1 - MAF with a warning. MAF = 0 returns B = 0.

target_trait

Character string or NULL (default NULL). Required when using a p-value method model: "binary" or "continuous". Ignored for beta method models.

target_SE

Numeric scalar or vector of standard errors for the target data. Required for p-value method with continuous traits. If scalar, recycled to match length of target_MAF. If vector, must have same length as target_MAF.

target_case_prop

Numeric scalar or vector of case proportions for binary traits. Required for p-value method with binary traits. Values must be in (0, 1). If scalar, recycled to match length of target_MAF. If vector, must have same length as target_MAF.

method

Character (default "auto"). For glow_B_model objects: "auto" uses the primary method from the model, "beta_method" forces the beta method model, "pvalue_method" forces the p-value method model. Ignored for raw lm objects.

Value

Numeric vector of predicted B values (same length as target_MAF). Non-negative (floored at 0).

Details

Beta Method Models:

The function handles all 8 candidate model transformations:

  • Models 1-4: Y response (B = sqrt(abs(predicted)))

  • Models 5-8: log(Y) response (B = sqrt(exp(predicted)))

Each model uses one of 4 predictor transformations:

  • X (MAF directly)

  • fX = MAF * (1 - MAF)

  • logX = log(MAF)

  • logfX = log(MAF * (1 - MAF))

P-value Method Models:

These models predict h-squared (heritability) rather than BETA^2. The h-squared predictions must be converted to B values using trait-specific formulas. This conversion was previously performed inside .estimate_B_pvalue() but has been moved here to support the train/predict separation.

If target_trait is not provided for a p-value method model, the function returns sqrt(h^2) with a warning (an approximation that ignores trait-specific scaling).

Method Selection for glow_B_model:

  • method = "auto": Uses the primary method. If the model was trained with a single method, that method is used. If trained with "both", uses the method selected at training time by criterion comparison (model$comparison$method_selected).

  • method = "beta_method": Forces the beta method model.

  • method = "pvalue_method": Forces the p-value method model.

See also

train_B_model for training B estimation models get_B for combined train + predict in one call save_B_model for saving trained models load_B_model for loading saved models

Examples

if (FALSE) { # \dontrun{
# Train a B model
b_model <- train_B_model(
  training_trait = "binary",
  training_MAF = known_snps$MAF,
  training_BETA = known_snps$BETA,
  method = "beta"
)

# Predict B for new MAF values (beta method -- no conversion needed)
new_maf <- c(0.001, 0.01, 0.05, 0.1, 0.2)
B_predicted <- predict_B(b_model, new_maf)

# P-value method with binary trait conversion
b_model_pval <- train_B_model(
  training_trait = "binary",
  training_MAF = known_snps$MAF,
  training_P = known_snps$P,
  training_N = known_snps$N,
  method = "pvalue"
)
B_binary <- predict_B(b_model_pval, new_maf,
                       target_trait = "binary",
                       target_case_prop = 0.3)

# P-value method with continuous trait conversion
B_continuous <- predict_B(b_model_pval, new_maf,
                           target_trait = "continuous",
                           target_SE = 0.5)
} # }