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

change function name of base_char #13

Merged
merged 15 commits into from
Jun 19, 2024
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
export(collect_baseline)
export(defmt_pct)
export(format_base_char)
export(format_disposition)
export(format_trt_compliance)
export(meta_sl)
export(meta_sl_example)
export(prepare_base_char)
export(prepare_disposition)
export(prepare_sl_summary)
export(prepare_trt_compliance)
export(react_base_char)
export(rtf_base_char)
export(rtf_disposition)
export(rtf_trt_compliance)
37 changes: 36 additions & 1 deletion R/format_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#' Prepare data for baseline characteristic table
#'
#' @param outdata A metadata object created by [prepare_base_char()].
#' @param outdata A metadata object created by [prepare_sl_summary()].
#' @param display_col Column wants to display on the table.
#' The term could be selected from `c("n", "prop", "total")`.
#' @param digits_prop Number of digits for proportion columns.
Expand Down Expand Up @@ -119,3 +119,38 @@ format_base_char <- function(

return(outdata)
}

#' Format Treatment Compliance Analysis
#'
#' @inheritParams format_base_char
#'
#' @return A list of analysis raw datasets.
#'
#' @export
#'
#' @examples
#' meta <- meta_sl_example()
#'
#' meta |>
#' prepare_trt_compliance(parameter = "comp8;comp16") |>
#' format_trt_compliance()
format_trt_compliance <- format_base_char


#' Format Disposition Analysis
#'
#' @inheritParams format_base_char
#'
#' @return A list of analysis raw datasets.
#'
#' @export
#'
#' @examples
#' meta <- meta_sl_example()
#'
#' meta |>
#' prepare_disposition(parameter = "disposition;medical-disposition") |>
#' format_disposition()
format_disposition <- format_base_char


75 changes: 61 additions & 14 deletions R/meta_sl_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,39 @@ meta_sl_example <- function() {
levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
labels = c("Placebo", "Low Dose", "High Dose")
)


# Create a variable EOSSTT indicating the end of end of study status
adsl$EOSSTT <- sample(x = c("Participants Ongoing", "Discontinued"),
size = length(adsl$USUBJID),
prob = c(0.8, 0.2), replace = TRUE)
# Create a variable EOTSTT1 indicating the end of treatment status part 1
adsl$EOTSTT1 <- sample(x = c("Completed", "Discontinued"),
size = length(adsl$USUBJID),
prob = c(0.85, 0.15), replace = TRUE)

plan <- metalite::plan(
analysis = "base_char", population = "apat",
observation = "apat", parameter = "age;gender;race"
) |>
metalite::add_plan(
analysis = "trt_compliance", population = "apat",
observation = "apat", parameter = "comp8;comp16;comp24"
) |>
metalite::add_plan(
analysis = "disp", population = "apat",
observation = "apat", parameter = "disposition;medical-disposition"
)

meta <- metalite::meta_adam(
population = adsl,
observation = adsl
) |>
metalite::define_plan(plan = metalite::plan(
analysis = "base_char", population = "apat",
observation = "apat", parameter = "age;gender;race"
)) |>
metalite::define_plan(plan) |>
metalite::define_population(
name = "apat",
group = "TRTA",
subset = quote(SAFFL == "Y"),
var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE")
) |>
metalite::define_observation(
name = "apat",
group = "TRTA",
subset = quote(SAFFL == "Y"),
var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE")
var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE", "EOSSTT", "EOTSTT1", "COMP8FL", "COMP16FL", "COMP24FL")
) |>
metalite::define_parameter(
name = "age",
Expand All @@ -71,11 +84,45 @@ meta_sl_example <- function() {
var = "RACE",
label = "Race"
) |>
metalite::define_parameter(
name = "disposition",
var = "EOSSTT",
label = "Trial Disposition"
) |>
metalite::define_parameter(
name = "medical-disposition",
var = "EOTSTT1",
label = "Participant Study Medication Disposition"
) |>
metalite::define_parameter(
name = "comp8",
var = "COMP8FL",
label = "Compliance (Week 8)",
) |>
metalite::define_parameter(
name = "comp16",
var = "COMP16FL",
label = "Compliance (Week 16)",
) |>
metalite::define_parameter(
name = "comp24",
var = "COMP24FL",
label = "Compliance (Week 24)",
) |>
metalite::define_analysis(
name = "base_char",
title = "Participant Baseline Characteristics by Treatment Group",
label = "baseline characteristic table",
var_name = c("AGEGR1", "SEX")
label = "baseline characteristic table"
) |>
metalite::define_analysis(
name = "trt_compliance",
title = "Summary of Treatment Compliance",
label = "treatment compliance table"
) |>
metalite::define_analysis(
name = "disp",
title = "Disposition of Participant",
label = "disposition table"
) |>
metalite::meta_build()
}
91 changes: 15 additions & 76 deletions R/prepare_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
# 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 baseline characteristic table
#' Prepare data for treatment compliance 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 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.
#'
Expand All @@ -35,78 +36,16 @@
#' @examples
#' meta <- meta_sl_example()
#' meta |> prepare_base_char()
prepare_base_char <- function(
meta,
population = "apat",
observation = "wk12",
analysis = "base_char",
parameter = paste(names(meta$parameter), collapse = ";")) {
parameters <- unlist(strsplit(parameter, ";"))

# obtain variables
pop_var <- metalite::collect_adam_mapping(meta, population)$var
obs_var <- metalite::collect_adam_mapping(meta, observation)$var
par_var <- metalite::collect_adam_mapping(meta, parameter)$var

pop_group <- metalite::collect_adam_mapping(meta, population)$group
obs_group <- metalite::collect_adam_mapping(meta, observation)$group

pop_id <- metalite::collect_adam_mapping(meta, population)$id
obs_id <- metalite::collect_adam_mapping(meta, observation)$id

# obtain data
pop <- metalite::collect_population_record(meta, population, var = pop_var)

# obtain group names
group <- unique(pop[[pop_group]])

# count the number of subjects in each arms
n_pop <- metalite::n_subject(id = pop[[pop_id]], group = pop[[pop_group]])
names(n_pop) <- do.call(
c,
lapply(
factor(names(n_pop), levels = levels(pop[[pop_group]])) |> as.numeric(),
function(x) {
paste0("n_", x)
}
prepare_base_char <- function(meta,
analysis = "base_char",
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
)
)
n_pop$n_9999 <- sum(n_pop[1, ])
n_pop$name <- "Participants in population"
n_pop <- n_pop[, c(length(group) + 2, 1:(length(group) + 1))]
n_pop$var_label <- "-----"

# Get the baseline characteristics variables in adsl
# char_var <- collect_adam_mapping(meta, analysis)$var_name
char_var <- do.call(c, lapply(parameters, function(x) {
metalite::collect_adam_mapping(meta, x)$var
}))

# Get the baseline characteristics counts
char_n <- lapply(parameters, function(x) {
collect_baseline(meta, population, x)[[2]]
})

# Get the baseline characteristics propositions
char_prop <- lapply(parameters, function(x) {
collect_baseline(meta, population, x)[[3]]
})

# Get the variable date type
var_type <- lapply(parameters, function(x) {
collect_baseline(meta, population, x)[[4]]
})

ans <- metalite::outdata(
meta, population, observation, parameter,
n = n_pop,
order = NULL, group = pop_group, reference_group = NULL,
char_n = char_n,
char_var = char_var,
char_prop = char_prop,
var_type = var_type,
group_label = unique(pop[[pop_group]])
)

return(ans)
}
}
51 changes: 51 additions & 0 deletions R/prepare_disposition.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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 treatment compliance 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_example()
#' meta |> prepare_base_char()
prepare_disposition <- function(meta,
analysis = "disp",
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
Loading