check_medicare: Validate Australian Medicare Numbers Using the Modulus 10...

View source: R/check_medicare.R

check_medicareR Documentation

Validate Australian Medicare Numbers Using the Modulus 10 Checksum

Description

**Bird note**: Starlings are famously alert to impostors – a murmuration will immediately eject a bird that does not move quite right. check_medicare() plays the same sentinel role before linkage: it identifies impostors hiding in your Medicare number field before they corrupt the match scores. A single transposed digit in a Medicare number silently destroys a linkage pair; catching it here costs nothing compared to auditing a linked dataset afterwards.

Validates Australian Medicare numbers using the official Services Australia check-digit algorithm: a Modulus 10 weighted checksum on digits 1-8, verified against the 9th digit. The 10-digit Medicare card number has the structure XXXXXXXXX C I, where digits 1-8 form the individual identifier, digit 9 (C) is the check digit derived from those 8 digits, and digit 10 (I) is the Individual Reference Number (IRN) identifying family members on the same card. Only the check digit (position 9) is validated here; the IRN is not part of the checksum algorithm.

Usage

check_medicare(
  data,
  medicare_col = "medicare10",
  output_col = "medicare_valid",
  verbose = TRUE,
  keep_digits = 10L
)

Arguments

data

A data frame containing a Medicare number column.

medicare_col

Character. Name of the column containing Medicare numbers. Values may include spaces or hyphens (stripped before validation). Default "medicare10" (the standardised name from mudnester::clean_the_nest()).

output_col

Character. Name of the new validation flag column added to data. Default "medicare_valid". Values: 1L for a valid checksum, 0L for an invalid checksum, NA for a missing or non-numeric entry.

verbose

Logical. If TRUE (default), prints a summary report to the console showing total records, valid count and percentage, invalid count, missing count, and a warning if the valid rate falls below 95%.

keep_digits

Integer. Either 9 or 10 (default). Length of a valid Medicare number string after stripping spaces and hyphens. Use 10 for the full card number including IRN; use 9 for numbers stored without the IRN.

Details

## The Modulus 10 check-digit algorithm

The 9th digit of an Australian Medicare number is computed from the first 8 digits using positional weights 1, 3, 7, 9, 1, 3, 7, 9 (repeating 1-3-7-9). The check digit C is:

C = (d1*1 + d2*3 + d3*7 + d4*9 + d5*1 + d6*3 + d7*7 + d8*9) mod 10

If the computed value equals position 9 of the submitted number, the number passes validation.

## Interpreting the output flag

A flag of NA means the field was missing, blank, or non-numeric – these records cannot be linked on Medicare number but may still link via other variables. A flag of 0L means the number is present and numeric but the checksum fails – at least one digit is wrong and the number should not be used as a linkage variable. A flag of 1L means the checksum passes – the number is internally consistent, though it may still be wrong (e.g. a different person's valid card number).

A valid-checksum rate below 95% usually signals a systematic data entry or export issue and should be investigated before linkage.

Value

The input data frame with two new columns appended: medicare_clean (the Medicare number with spaces, hyphens, and dots stripped; NA for missing or empty entries) and the column named by output_col (integer flag: 1L valid, 0L invalid, NA missing or non-numeric).

References

Services Australia (2024). Medicare card number format and check digit. https://www.servicesaustralia.gov.au/

See Also

preflight for a full pre-linkage audit. flock for blocking variable construction. murmuration for the linkage step. murmuration_plot for threshold visualisation.

Examples

## Not run: 
# Basic usage
cases_checked <- check_medicare(cases_clean)

# Custom column name
cases_checked <- check_medicare(cases_clean,
  medicare_col = "medicare_number",
  output_col   = "mcn_valid")

# Suppress console report
cases_checked <- check_medicare(cases_clean, verbose = FALSE)

# Exclude invalid Medicare numbers before linkage
cases_clean$medicare10 <- ifelse(
  cases_checked$medicare_valid == 1L,
  cases_clean$medicare10,
  NA_character_
)

# Validate 9-digit numbers (no IRN appended)
cases_checked <- check_medicare(cases_clean,
  medicare_col = "medicare9",
  keep_digits  = 9L)

## End(Not run)


starling documentation built on July 10, 2026, 9:07 a.m.