f_dose_draw_1 {drugDemand}R Documentation

Drug Dispensing Data Simulation for One Iteration

Description

Simulates drug dispensing data for one iteration.

Usage

f_dose_draw_1(
  i,
  common_time_model,
  k0_fit,
  t0_fit,
  t1_fit,
  ki_fit,
  ti_fit,
  di_fit,
  vf_ongoing,
  vf_ongoing1,
  vf_new,
  vf_new1,
  vf_kit,
  l,
  t
)

Arguments

i

The iteration number.

common_time_model

A Boolean variable that indicates whether a common time model is used for drug dispensing visits.

k0_fit

The model fit for the number of skipped visits between randomization and the first drug dispensing visit.

t0_fit

The model fit for the gap time between randomization and the first drug dispensing visit when there is no visit skipping.

t1_fit

The model fit for the gap time between randomization and the first drug dispensing visit when there is visit skipping.

ki_fit

The model fit for the number of skipped visits between two consecutive drug dispensing visits.

ti_fit

The model fit for the gap time between two consecutive drug dispensing visits.

di_fit

The model fit for the dispensed doses at drug dispensing visits.

vf_ongoing

A data frame for the observed drug dispensing data for ongoing patients with drug dispensing records. It includes the following variables: draw, kit, kit_name, usubjid, day, dose, arrivalTime, treatment, treatment_description, time, and totalTime.

vf_ongoing1

A data frame for the last observed drug dispensing date for ongoing patients with drug dispensing records. For the common time model, it includes the following variables: draw, usubjid, arrivalTime, treatment, treatment_description, time, totalTime, V, C, and D. For separate time models, it includes the following variables: draw, kit, kit_name, usubjid, arrivalTime, treatment, treatment_description, time, totalTime, V, C, and D.

vf_new

A data frame for the randomization date for new patients and ongoing patients with no drug dispensing records. It includes the following variables: draw, kit, kit_name, usubjid, arrivalTime, treatment, treatment_description, time, and totalTime.

vf_new1

A data frame for the randomization date for new patients and ongoing patients with no drug dispensing records. For the common time model, it includes the following variables: draw, usubjid, arrivalTime, treatment, treatment_description, time, totalTime, V, C, and D. For separate time models, it includes the following variables: draw, kit, kit_name, usubjid, arrivalTime, treatment, treatment_description, time, totalTime, V, C, and D.

vf_kit

A data frame indicating the kit names for each subject by draw. It includes the following variables: draw, usubjid, kit, and kit_name.

l

Number of kit types.

t

A vector of new time points for drug dispensing prediction.

Value

A list of two components:

Author(s)

Kaifeng Lu, kaifenglu@gmail.com

See Also

f_fit_t0, f_fit_ki, f_fit_ti, f_fit_di

Examples



set.seed(431)
library(dplyr)

pred <- eventPred::getPrediction(
  df = df2,
  to_predict = "event only",
  target_d = 250,
  event_model = "log-logistic",
  dropout_model = "none",
  pilevel = 0.95,
  nyears = 3,
  nreps = 200,
  showsummary = FALSE,
  showplot = FALSE,
  by_treatment = TRUE)

observed <- f_dose_observed(df2, visitview2, showplot = FALSE)

fit <- f_dispensing_models(
  observed$vf, dosing_schedule_df,
  model_k0 = "zero-inflated poisson",
  model_t0 = "log-logistic",
  model_t1 = "least squares",
  model_ki = "zero-inflated poisson",
  model_ti = "least squares",
  model_di = "linear mixed-effects model",
  nreps = 200, showplot = FALSE)

trialsdt = df2$trialsdt[1]
cutoffdt = df2$cutoffdt[1]
t0 = as.numeric(cutoffdt - trialsdt + 1)
nyears = 3
t1 = t0 + nyears*365
t = c(seq(t0, t1, 30), t1)

l = nrow(observed$kit_description_df)

vf_ongoing_new <- f_ongoing_new(
  pred$event_pred$newEvents,
  observed$kit_description_df,
  observed$treatment_by_drug_df,
  observed$vf)

vf_ongoing <- vf_ongoing_new$vf_ongoing
vf_new <- vf_ongoing_new$vf_new

vf_kit <- vf_ongoing %>%
  select(-c("day", "dose")) %>%
  bind_rows(vf_new) %>%
  group_by(draw, usubjid, kit, kit_name) %>%
  slice(1) %>%
  select(c("draw", "usubjid", "kit", "kit_name"))

vf_ongoing1 <- vf_ongoing %>%
  group_by(draw, usubjid) %>%
  slice(n()) %>%
  mutate(V = day - 1,
         C = as.numeric(t0 - arrivalTime),
         D = pmin(time - 1, t1 - arrivalTime)) %>%
  select(-c("kit", "kit_name", "day", "dose"))

### new patients and ongoing patients with no dosing records ###
vf_new1 <- vf_new %>%
  group_by(draw, usubjid) %>%
  slice(n()) %>%
  mutate(V = 0,
         C = as.numeric(t0 - arrivalTime),
         D = pmin(time - 1, t1 - arrivalTime)) %>%
  select(-c("kit", "kit_name"))

# first iteration to extract subject and summary data
list1 <- f_dose_draw_1(
  1, fit$common_time_model,
  fit$k0_fit, fit$t0_fit, fit$t1_fit,
  fit$ki_fit, fit$ti_fit, fit$di_fit,
  vf_ongoing, vf_ongoing1, vf_new, vf_new1,
  vf_kit, l, t)

head(list1$dosing_subject_newi)
head(list1$dosing_summary_newi)



[Package drugDemand version 0.1.3 Index]