Recode Missing or Ambiguous UDS in a Subject Use Pattern
Source:R/recode_missing_visits.R
recode_missing_visits.Rd
Replace all missing UDS "o"
in a use pattern string
Usage
recode_missing_visits(
use_pattern,
missing_is = "o",
missing_becomes = c("+", "", "-")
)
Arguments
- use_pattern
A character string showing the daily, by visit, or weekly substance use pattern for a single subject
- missing_is
Which single character is used to mark missing UDS in a use pattern string? Defaults to
"o"
.- missing_becomes
How should missing UDS be treated? Defaults to marking the subject as positive for that missing period. Options are
"+"
for positive,""
for ignore, or"-"
for negative (note that this last option should only be used in case where the "missing" UDS is a regular and expected artefact of the study design and the preceding and following UDS are both negative).
Value
A character string with all missing UDS values (marked as "o"
unless a different value is supplied to missing_is
) replaces by the
value supplied to missing_becomes
.
Details
At current, we allow for many symbols in the use pattern "word", such as "_" for missing by study design, "o" missing for protocol non-compliance (the most common form of missing), "+" for positive, "-" for negative, and "*" for mixed positive and negative results (this usually comes up when the visit represents multiple days and there are both positive and negative results in those days; for example, a subject is tested weekly; they provided a positive test on Tuesday but came back to provide a negative test the following day).
Examples
pattern_char <- "__++++*o-------+--+-o-o-o+o+"
# Default: change all missing weeks to positive
recode_missing_visits(pattern_char)
#> [1] "__++++*+-------+--+-+-+-++++"
# Other example: remove all weeks with no UDS by design
recode_missing_visits(pattern_char, missing_is = "_", missing_becomes = "")
#> [1] "++++*o-------+--+-o-o-o+o+"