| preflight | R Documentation |
**Bird note**: Before a long migration, birds enter a physiological state called
*hyperphagia* — they systematically assess and load up on resources, checking
body condition before committing to the journey. preflight() is that
pre-migration check for your data: a structured, systematic audit of both
datasets before committing to probabilistic linkage with murmuration().
Skipping it is like a shorebird launching across the Pacific without first
checking its fat reserves.
Runs a battery of pre-linkage data quality checks on two datasets and returns
a structured report. Checks cover: completeness of linkage variables, date
plausibility, uniqueness of identifier columns, consistency of factor levels
across datasets (e.g. gender coding), Medicare validity (if present), name
length and character distribution, duplicate record detection, and dataset
overlap summaries. Optionally runs check_medicare if a Medicare
column is identified.
The report is printed to the console and returned invisibly as a named list so it can be saved, embedded in a Quarto report, or passed to downstream checks.
preflight(
data1,
data2,
linkage_vars = NULL,
id_col1 = "id_var",
id_col2 = "id_var",
blocking_vars = NULL,
date_cols = NULL,
medicare_col = NULL,
name_cols = NULL,
min_name_length = 2L,
verbose = TRUE
)
data1 |
First data frame (typically the case/index dataset, |
data2 |
Second data frame (typically the vaccination/hospitalisation dataset,
|
linkage_vars |
Character vector of column names that will be used as
|
id_col1 |
Name of the unique record identifier in |
id_col2 |
Name of the unique record identifier in |
blocking_vars |
Character vector of planned blocking variable names to check
for completeness. If |
date_cols |
Character vector of date column names to check for plausibility
(no future dates, no dates before 1900). |
medicare_col |
Name of the Medicare number column if present and to be
validated. |
name_cols |
Character vector of name columns to check for short strings
(potential initials or truncations), all-numeric entries, and excessive
punctuation. Default checks |
min_name_length |
Integer. Names shorter than this are flagged as
potentially truncated or coded. Default |
verbose |
Logical. Print the full report to console? Default |
Invisibly, a named list with the following elements:
completenessA data frame: variable, dataset, n_present, n_missing, pct_missing for each linkage variable.
duplicatesA data frame: dataset, n_records, n_unique_ids, n_duplicate_ids, pct_duplicate.
blocking_completenessCompleteness of blocking variables, or
NULL if not checked.
date_checksDate plausibility results, or NULL if not
checked.
medicareMedicare validity results from check_medicare(),
or NULL if not checked.
name_checksName quality results, or NULL if not checked.
factor_consistencyComparison of factor levels for shared categorical columns.
overlap_summaryApproximate overlap statistics for key demographic variables.
flagsCharacter vector of warning-level flags raised during the checks. Empty if no issues found.
check_medicare, murmuration,
flock
## Not run:
# Basic pre-flight check before v2c linkage
report <- preflight(
data1 = cases_clean,
data2 = vax_clean,
linkage_vars = c("lettername1", "lettername2", "dob", "medicare10"),
id_col1 = "id_var",
id_col2 = "id_var",
blocking_vars = "gender",
date_cols = c("dob", "onset_date"),
medicare_col = "medicare"
)
# Access the completeness table programmatically
report$completeness
# Save the report to a CSV for documentation
write.csv(report$completeness, "preflight_completeness.csv", row.names = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.