f_fit_ti: Model Fitting for Gap Times

View source: R/f_dispensing_models.R

f_fit_tiR Documentation

Model Fitting for Gap Times

Description

Fits a linear regression model to the gap time between two consecutive drug dispensing visits.

Usage

f_fit_ti(df, model, nreps, showplot = TRUE)

Arguments

df

The subject-level dosing data, including the following variables:

  • time: The gap time to the next drug dispensing visit.

  • skipped: The number of skipped visits.

  • k1: The covariate for the linear regression. It equals skipped for the gap time between randomization and the first drug dispensing visit and skipped + 1 for the gap time between two consecutive drug dispensing visits.

model

The model used to analyze the gap time. Options include "least squares" and "least absolute deviations".

nreps

The number of simulations for drawing posterior model parameter values.

showplot

A Boolean variable that controls whether or not to show the fitted gap time bar chart. It defaults to TRUE.

Value

A list with three components:

  • fit: A list of results from the model fit that includes

    • model: The specific model used in the analysis.

    • beta: The estimated regression coefficient for the covariate.

    • vbeta: The estimated variance of beta.

    • sigma: The estimated residual standard deviation.

    • df: The residual degrees-of-freedom.

    • aic: The Akaike Information Criterion value.

    • bic: The Bayesian Information Criterion value.

  • fit_plot: A fitted gap time bar chart.

  • theta: Posterior draws of model parameters.

Author(s)

Kaifeng Lu, kaifenglu@gmail.com

Examples

library(dplyr)

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

vf <- vf %>% left_join(dosing_schedule_df, by = "kit")

df_ti <- vf %>%
  mutate(time = lead(day) - day,
         skipped = pmax(floor((time - target_days/2)/target_days), 0),
         k1 = skipped + 1) %>%
  filter(row_id < n())

ti_fit <- f_fit_ti(df_ti, model = "least squares", nreps = 200)


drugDemand documentation built on May 29, 2024, 8:43 a.m.