Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create prepare function and example for exposure duration #25

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions R/meta_sl_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
52 changes: 52 additions & 0 deletions R/prepare_exp_duration.R
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

#' 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
)
)

}
Loading