impute_duration: Replace missing or implausible prescription durations

Description Usage Arguments Details Value Examples

View source: R/impute.R

Description

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

Usage

1
2
3
4
5
6
7
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

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.

Value

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

Examples

1
2
example_duration <- transform(example_therapy, duration = qty / ndd)
impute_duration(example_duration, method = 'mean', group = 'patid')

belayb/drugprepr documentation built on Dec. 19, 2021, 7:44 a.m.