Learn R Programming

drugprepr (version 0.0.4)

impute_duration: Replace missing or implausible prescription durations

Description

Instead of replacing missing stop dates, we impute the durations and then infer the stop dates from there.

Usage

impute_duration(
  data,
  method,
  where = is.na,
  group = c("patid", "start_date"),
  ...
)

Arguments

data

A data frame containing columns prodcode, pracid, patid

method

Method for imputing the values. See details.

where

Logical vector, or function applied to variable returning such a vector, indicating which elements to impute. Defaults to is.na

group

Level of structure for imputation. Defaults to whole study population.

...

Extra arguments, currently ignored

Value

A data frame of the same structure as data, with values imputed

Details

We can fix clashing start dates by setting group to start_date and patid, i.e. average over groups with more than one member; any metric should return the original values if the group size is one.

Examples

Run this code
# NOT RUN {
example_duration <- transform(example_therapy, duration = qty / ndd)
impute_duration(example_duration, method = 'mean', group = 'patid')

# }

Run the code above in your browser using DataLab