Extracts a specific field (coefficients, t-values, or p-values) from a list of model statistics and combines them into a matrix with targets as rows and predictors as columns. Handles missing fields, NULL values, and targets with different sets of predictors by filling missing values with NA.

safe_extract_matrix(stats_list, field_name, all_predictors)

Arguments

stats_list

A named list where each element contains model statistics for one target. Each element should be a list with fields like 'coefs', 't_vals', 'p_vals'

field_name

A character string specifying which field to extract (e.g., 'coefs', 't_vals', 'p_vals')

all_predictors

A character vector of all predictor names that should appear as columns in the output matrix

Value

A numeric matrix with targets as rows and predictors as columns, with NA values where predictors are missing for specific targets