From dc0b2f0e75e4e5ccbc45dce62539dcda6b8683ae Mon Sep 17 00:00:00 2001 From: niup0 Date: Tue, 9 Jul 2024 09:11:26 -0400 Subject: [PATCH] Create prepare function and example for exposure duration --- R/meta_sl_example.R | 61 ++++++++++++++++++++++++++++++++++++++++ R/prepare_exp_duration.R | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 R/prepare_exp_duration.R diff --git a/R/meta_sl_example.R b/R/meta_sl_example.R index 59bbd4f..59dbc96 100644 --- a/R/meta_sl_example.R +++ b/R/meta_sl_example.R @@ -126,3 +126,64 @@ meta_sl_example <- function() { ) |> metalite::meta_build() } + +#' Create an example `meta_sl_exposure_example` object +#' +#' This function is only for illustration purpose. +#' r2rtf is required. +#' +#' @return A metadata object. +#' +#' @export +#' +#' @examples +#' meta_sl_exposure_example() +meta_sl_exposure_example <- function() { + adsl <- r2rtf::r2rtf_adsl + + # Create ADEXSUM dataset + adexsum <- data.frame(USUBJID=adsl$USUBJID) + adexsum$TRTA <- factor(adsl$TRT01A, + levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"), + labels = c("Placebo", "Low Dose", "High Dose") + ) + + adexsum$APERIODC <- "Base" + adexsum$APERIOD <- 1 + adexsum$AVAL <- sample(x = 0:(24*7), size = length(adexsum$USUBJID), replace = TRUE) + adexsum$EXDURGR <- "not treated" + adexsum$EXDURGR[adexsum$AVAL>=1] <- ">=1 day" + adexsum$EXDURGR[adexsum$AVAL>=7] <- ">=7 days" + adexsum$EXDURGR[adexsum$AVAL>=28] <- ">=28 days" + adexsum$EXDURGR[adexsum$AVAL>=12*7] <- ">=12 weeks" + adexsum$EXDURGR[adexsum$AVAL>=24*7] <- ">=24 weeks" + + plan <- metalite::plan( + analysis = "exp_dur", population = "apat", + observation = "apat", parameter = "expdur" + ) + + meta <- metalite::meta_adam( + population = adexsum, + observation = adexsum + ) |> + metalite::define_plan(plan) |> + metalite::define_population( + name = "apat", + group = "TRTA", + subset = quote(APERIOD==1 & AVAL>0), + var = c("USUBJID", "TRTA", "EXDURGR", "AVAL"), + ) |> + metalite::define_parameter( + name = "expdur", + var = "AVAL", + label = "Exposure Duration (Days)", + vargroup = "EXDURGR" + )|> + metalite::define_analysis( + name = "exp_dur", + title = "Summary of Exposure Duration", + label = "exposure duration table" + ) |> + metalite::meta_build() +} \ No newline at end of file diff --git a/R/prepare_exp_duration.R b/R/prepare_exp_duration.R new file mode 100644 index 0000000..e308e9c --- /dev/null +++ b/R/prepare_exp_duration.R @@ -0,0 +1,52 @@ +# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the metalite.sl program. +# +# metalite.sl is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Prepare data for exposure duration table +#' +#' @param meta A metadata object created by metalite. +#' @param population A character value of population term name. +#' The term name is used as key to link information. +# @param observation A character value of observation term name. +# The term name is used as key to link information. +#' @param analysis A character value of analysis term name. +#' The term name is used as key to link information. +#' @param parameter A character value of parameter term name. +#' The term name is used as key to link information. +# @param display_total A logic value of displaying the total group. +#' +#' @return A list of analysis raw datasets. +#' +#' @export +#' +#' @examples +#' meta <- meta_sl_exposure_example() +#' meta |> prepare_exp_duration() +prepare_exp_duration <- function(meta, + analysis = "exp_dur", + population = meta$plan[meta$plan$analysis==analysis,]$population, + parameter = paste(meta$plan[meta$plan$analysis==analysis,]$parameter, collapse = ";") +) { + return( + prepare_sl_summary(meta, + analysis = analysis, + population = population, + parameter = parameter + ) + ) + +} \ No newline at end of file