
Extract Machine Learning Feature Matrix from OMOP CDM
Source:R/features.R
extract_patient_features.RdBuilds vectorized patient feature matrices anchored to cohort index date T0 (cohort_start_date).
Computes baseline demographics and prior observation lookback window event counts (e.g. 30d, 180d, 365d),
directly connecting OMOP DuckDB cohorts to predictive modeling workflows.
Usage
extract_patient_features(
con,
cohort_id = NULL,
outcome_cohort_id = NULL,
lookback_days = c(30, 180, 365),
include_demographics = TRUE,
include_conditions = TRUE,
include_drugs = TRUE,
include_procedures = TRUE,
include_measurements = TRUE,
format = "df",
offset_anchor = c("visit_start_date", "visit_end_date", "index_date"),
anchor = NULL,
stream_to_parquet = NULL,
partition_by = NULL,
cohort_table = "cohort",
measurement_concept_ids = NULL,
lookahead_days = 0,
...
)
extract_features(
con,
cohort_id = NULL,
outcome_cohort_id = NULL,
lookback_days = c(30, 180, 365),
include_demographics = TRUE,
include_conditions = TRUE,
include_drugs = TRUE,
include_procedures = TRUE,
include_measurements = TRUE,
format = "df",
offset_anchor = c("visit_start_date", "visit_end_date", "index_date"),
anchor = NULL,
stream_to_parquet = NULL,
partition_by = NULL,
cohort_table = "cohort",
measurement_concept_ids = NULL,
lookahead_days = 0,
...
)Arguments
- con
Active DuckDB DBI connection.
- cohort_id
Integer cohort definition ID defining the target population.
- outcome_cohort_id
Optional integer cohort definition ID defining binary outcome Y.
- lookback_days
Integer vector of days for prior observation windows (default
c(30, 180, 365)).- include_demographics
Logical. Include age at index, gender, race, ethnicity, and index year.
- include_conditions
Logical. Include condition occurrence counts across lookback windows.
- include_drugs
Logical. Include drug exposure counts across lookback windows.
- include_procedures
Logical. Include procedure occurrence counts across lookback windows.
- include_measurements
Logical. Include measurement counts across lookback windows.
- format
Output format:
"df"(data.frame),"arrow", or"sparse".- offset_anchor
Milestone date to anchor lookback windows ('visit_start_date' | 'visit_end_date' | 'index_date').
- anchor
Alias for offset_anchor ('start' | 'end' | 'index').
- stream_to_parquet
Optional file path to stream feature matrix directly to Parquet out-of-core.
- partition_by
Optional column(s) to partition streamed Parquet files by (e.g. 'site').
- cohort_table
Table name containing cohort entries (default 'cohort').
- measurement_concept_ids
Specific measurement concept IDs to extract aggregated features for.
- lookahead_days
Days after anchor date to include in measurement extraction (default 0).
- ...
Additional arguments.