Analyzes text annotations to identify and count instances where different codes overlap or co-occur in the same text regions. Handles edge cases and provides error-safe operation.
calculate_co_occurrences(annotations)Table object containing frequencies of code pairs that co-occur, with code pair names as "code1 & code2"
Data frame containing annotations with columns:
start: numeric, starting position of annotation
end: numeric, ending position of annotation
code: character, code identifier
Co-occurrences are identified by finding overlapping text regions between different code annotations. The function sorts annotations by position and checks for overlaps between each pair of annotations.