R/get_B_diagnostics.R
get_B_diagnostics.RdGenerates a comprehensive diagnostic report for B estimation results, including model fit statistics, outlier detection, method comparison (if applicable), and quality control flags.
get_B_diagnostics(
B_result,
show_plots = TRUE,
outlier_threshold = 4,
verbose = 1
)Object of class "glow_B_estimate" (from
get_B with return_full = TRUE) or
"glow_B_model" (from train_B_model).
When a glow_B_model is provided, prediction-based diagnostics
(method comparison) are skipped.
Logical. If TRUE (default), displays diagnostic plots
using plot.glow_B_estimate or plot.glow_B_model
Numeric. Cook's distance threshold multiplier for outlier detection. Outliers defined as Cook's D > outlier_threshold/n where n is sample size (default = 4, following standard statistical convention)
Integer. Verbosity level: 0=silent, 1=summary (default), 2=detailed output
A list of class "glow_B_diagnostics" containing:
model_fit: List with R^2, adj_R2, formula for each method
residual_stats: Summary of residuals (mean, SD, range, normality test)
outliers: Indices and details of potential outliers
method_comparison: Comparison metrics if both methods used
qc_flags: Quality control warnings and recommendations
summary_text: Human-readable summary
This function provides a comprehensive assessment of B estimation quality:
Model Fit Statistics:
R^2: Proportion of variance explained (higher is better, >0.5 preferred)
Adjusted R^2: R^2 adjusted for number of predictors
Formula: The selected model formula
Outlier Detection: Uses Cook's distance to identify influential observations that may affect model fit. Threshold is typically 4/n where n is sample size.
Method Comparison (if both methods used):
Correlation between methods
RMSE (root mean squared error)
Percent difference statistics
QC Flags: Automatic warnings for:
Low R^2 (<0.3)
Non-normal residuals
High number of outliers (>10\
Large method disagreement (if both methods used)
O(n) where n is the number of training variants
get_B for B estimation
train_B_model for training B estimation models
plot.glow_B_estimate for visualization
compare_B_models for comparing all candidate models
if (FALSE) { # \dontrun{
# Run get_B with full output
result <- get_B(
training_trait = "binary",
training_MAF = training_MAF,
training_BETA = training_BETA,
training_P = training_P,
training_N = training_N,
target_trait = "binary",
target_MAF = target_MAF,
target_case_prop = 0.1,
method = "both",
return_full = TRUE
)
# Generate diagnostics
diag <- get_B_diagnostics(result, show_plots = TRUE)
# View summary
print(diag)
# Access specific components
diag$model_fit$beta$R2
diag$outliers$indices
diag$qc_flags
} # }