R/get_B_user_interfaces.R
get_B_auto.RdA beginner-friendly wrapper for get_B that automatically
detects data format, selects appropriate methods, and uses sensible defaults.
This function minimizes the number of required parameters and handles most
common use cases automatically.
get_B_auto(
training_data,
target_MAF,
training_trait = NULL,
target_trait = NULL,
target_SE = NULL,
target_case_prop = NULL,
verbose = 1
)Either:
A data.frame with columns: MAF, BETA or (P/P_mlog10, N), and optionally rsID, CHR, POS. P_mlog10 represents -log10(p-value) and is preferred for extreme p-values.
An object of class glow_training_data from prepare_B_training_data
Numeric vector of target MAF values for which to predict effect sizes. Values should be in (0, 1)
Character string specifying training trait type:
"binary" or "continuous". If NULL and training_data is a
glow_training_data object, automatically extracted. For data.frame
input, this parameter is required
Character string specifying target trait type:
"binary" or "continuous". If NULL (default), uses training_trait
Numeric value or vector of standard errors for target data.
Required when target_trait == "continuous" and p-value method is used.
Can be a single value (applied to all variants) or a vector matching
length of target_MAF
Numeric value or vector specifying the proportion of
cases in target case-control study. Required when target_trait == "binary"
and p-value method is used. This is the study case proportion
(cases / total sample size), not population prevalence. Can be a single
value or a vector matching length of target_MAF
Integer controlling verbosity: 0=silent, 1=warnings and summary (default), 2=detailed progress messages
Numeric vector of predicted effect sizes (B) for each variant in
target_MAF
Automatic Features:
This function automatically:
Detects available data (BETA vs P-values) and chooses appropriate method
Extracts trait type from glow_training_data objects
Uses target_trait = training_trait if not specified
Selects best model using R-squared criterion
Detects both statistical and biological outliers (but keeps them)
Default Settings:
method = "auto" (use both methods if same trait + both data available, else pvalue)
selection_criterion = "R2" (maximize explained variance)
outlier_method = "both" (detect statistical + biological outliers)
outlier_action = "flag" (report but don't remove outliers)
return_full = FALSE (return simple vector)
When to Use:
Use this function when:
You're new to the GLOW framework
You want quick results with minimal setup
You trust automatic method selection
You don't need detailed diagnostics
For more control, use get_B_advanced or get_B
directly.
O(8 * n_train + n_test) where n_train = number of training variants, n_test = number of target variants
get_B for the main B estimation function
get_B_advanced for advanced interface with full control
prepare_B_training_data for preparing training data
if (FALSE) { # \dontrun{
# Example 1: Using glow_training_data object
training_data <- prepare_B_training_data(
data = "gwas_results.csv",
trait_type = "binary"
)
target_mafs <- seq(0.01, 0.4, by = 0.01)
B_estimates <- get_B_auto(
training_data = training_data,
target_MAF = target_mafs,
target_case_prop = 0.5
)
# Example 2: Using data.frame directly
my_gwas <- data.frame(
MAF = runif(100, 0.01, 0.5),
BETA = rnorm(100, 0, 0.1),
P = runif(100, 1e-8, 0.1),
N = rep(5000, 100)
)
B_estimates <- get_B_auto(
training_data = my_gwas,
training_trait = "continuous",
target_MAF = seq(0.01, 0.4, by = 0.01),
target_SE = 0.05 # Single value for all variants
)
# Example 3: Cross-trait estimation (continuous to binary)
B_estimates <- get_B_auto(
training_data = my_gwas,
training_trait = "continuous",
target_trait = "binary",
target_MAF = seq(0.01, 0.4, by = 0.01),
target_case_prop = 0.1
)
} # }