Type: Package
Title: Automatic Estimation of the Most Likely Drug Combination using Smooth Algorithm
Version: 1.0.0
Description: A flexible moving average algorithm for modeling drug exposure in pharmacoepidemiology studies as presented in the article: Ouchi, D., Giner-Soriano, M., Gómez-Lumbreras, A., Vedia Urgell, C.,Torres, F., & Morros, R. (2022). "Automatic Estimation of the Most Likely Drug Combination in Electronic Health Records Using the Smooth Algorithm : Development and Validation Study." JMIR medical informatics, 10(11), e37976. <doi:10.2196/37976>.
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.2.3
Depends: R (≥ 4.3)
Imports: dplyr, tidyr (≥ 1.3.0), zoo (≥ 1.8), stringr
LazyData: true
Suggests: knitr, rmarkdown, ggplot2, gridExtra
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2023-08-10 06:01:59 UTC; douchi
Author: Dan Ouchi ORCID iD [aut, cre, cph], Alvaro Franquet ORCID iD [aut]
Maintainer: Dan Ouchi <dan.ouchi.vernet@gmail.com>
Repository: CRAN
Date/Publication: 2023-08-11 07:50:02 UTC

Drug Administration Data

Description

This dataset contains information about drug administration. Each row represents a unique drug administration event.

Usage

drugstreatment

Format

A data frame with the following columns:

id

Unique identifier for each drug administration event.

start_date

The start date of drug administration.

end_date

The end date of drug administration.

drug

The name of the drug administered.

Examples

data("drugstreatment")
head(drugstreatment)


Apply Smooth Algorithm in a Dataset

Description

Description part

Usage

smooth_algorithm(id, treatment, day, N, width = 61)

Arguments

id

Unique identifier of the patient.

treatment

Name of the drug used.

day

Day of the treatment.

N

Number of drugs used in the treatment.

width

An integer specifying the window width (in numbers of days, 61 by default).

Value

A data.frame with the following structure:

id

A character vector representing the unique identifier for each patient.

day

A character vector representing the date when the treatment was administered to the patients.

treatment

A character vector representing the type of treatment given to each patient.

smoothed_treatment

A character vector representing the smoothed treatment given to each patient.

Examples


library(smoothy)
library(dplyr)

data(drugstreatment)

df <- drugstreatment |>
  filter(id == "01f13c15-d9f1-4106-a04f-976c457edd0a")

structured_df <- smooth_parse(
  id = df$id,
  start_date = df$start_date,
  end_date = df$end_date,
  drug = df$drug,
  study_from = "1970-01-01",
  study_to = "1975-01-01"
)

head(structured_df)

id = structured_df$id
treatment = structured_df$treatment
day = structured_df$day
N = structured_df$N
width = 61

smoothed <- smooth_algorithm(id = id, treatment = treatment, day = day, N = N, width = width)
head(smoothed)


Deparse

Description

Transforms the Data with a Row by Date to a Row by Individual.

Usage

smooth_deparse(id, day, treatment)

Arguments

id

Unique identifier of the patient.

day

Day of the treatment.

treatment

A character vector representing the type of treatment given to each patient.

Value

A data.frame with the following structure:

id

A character vector representing the unique identifier for each patient.

start_date

Start date of the treatment.

end_date

End date of the treatment.

treatment

A character vector representing the type of treatment given to each patient.

Examples


library(smoothy)
library(dplyr)

data(drugstreatment)

my_data <- filter(drugstreatment, id == "01f13c15-d9f1-4106-a04f-976c457edd0a")

structured_df <- smooth_parse(
  id = my_data$id,
  start_date = my_data$start_date,
  end_date = my_data$end_date,
  drug = my_data$drug,
  study_from = "1970-01-01",
  study_to = "1975-01-01"
)

head(structured_df)

id = structured_df$id
treatment = structured_df$treatment
day = structured_df$day
N = structured_df$N
width = 61

smoothed <- smooth_algorithm(id = id, treatment = treatment, day = day, N = N, width = width)

head(smoothed)

deparsed_treatment <- smooth_deparse(smoothed$id, smoothed$day, smoothed$treatment)
deparsed_smothed <- smooth_deparse(smoothed$id, smoothed$day, smoothed$smoothed_treatment)


Compute the Difference Between Initial and Smoothed Treatment

Description

This function computes the differences between the initial treatment and the treatment when it's smoothed.

Usage

smooth_diff(treatment, smoothed_treatment)

Arguments

treatment

a character vector containing the original treatment data..

smoothed_treatment

a character vector containing the smoothed treatment return by smooth_algorithm function.

Value

A data.frame with three columns: diff_type , diff, change and treatment:

type

A character vector representing indicating the type of difference computed.

days_changed

The number of different items.

proportion_of_change

The proportion of difference computed as number of diferent rows over number of rows.

treatment

A character vector representing the type of treatment given to each patient.

Examples


library(smoothy)
library(dplyr)

data(drugstreatment)

my_data <- filter(drugstreatment, id == "01f13c15-d9f1-4106-a04f-976c457edd0a")

structured_df <- smooth_parse(
  id = my_data$id,
  start_date = my_data$start_date,
  end_date = my_data$end_date,
  drug = my_data$drug,
  study_from = "1970-01-01",
  study_to = "1975-01-01"
)

head(structured_df)

id = structured_df$id
treatment = structured_df$treatment
day = structured_df$day
N = structured_df$N
width = 61

smoothed <- smooth_algorithm(id = id, treatment = treatment, day = day, N = N, width = width)

head(smoothed)

smooth_diff(treatment = smoothed$treatment, smoothed_treatment = smoothed$smoothed_treatment)


Transform Data to be Used in smooth_algorithm() Function

Description

This function transforms the data to obtain the daily treatment.

Usage

smooth_parse(
  id,
  start_date,
  end_date,
  drug,
  study_from = min(start_date),
  study_to = max(end_date)
)

Arguments

id

Unique identifier of the patient.

start_date

Start date of the treatment.

end_date

End date of the treatment.

drug

Name of the drug used.

study_from

A date indicating when the study start.

study_to

A date indicating when the study finish.

Value

A data.frame with the following structure:

id

Unique identifier of the patient.

drug

Name of the drug used.

day

Day of the treatment.

N

Number of drugs used in the treatment

Examples

library(smoothy)
library(dplyr)

data(drugstreatment)

df <- drugstreatment |>
  filter(id == "01f13c15-d9f1-4106-a04f-976c457edd0a")

structured_df <- smooth_parse(
  id = df$id,
  start_date = df$start_date,
  end_date = df$end_date,
  drug = df$drug,
  study_from = "1970-01-01",
  study_to = "1975-01-01"
)

head(structured_df)