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

improve documentation #176

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions R/avg.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -18,14 +18,16 @@

#' Average number of events
#'
#' Calculates average number of records per group and, if requested, parameter.
#' Returns a list of means and sd of counts of records per group, ordered in
#' Calculates average number of records per group and, if requested, parameter
#' returns a list of means and SD of counts of records per group, ordered in
#' the same way as the input datasets.
#'
#' @inheritParams n_subject
#'
#' @importFrom stats sd reshape
#'
#' @return A list of means and SD of counts of records per group.
#'
#' @noRd
#'
#' @examples
Expand Down Expand Up @@ -83,7 +85,7 @@ avg_event <- function(id, group, par = NULL) {
tmp <- merge(data.frame(par = unique(db$par)), tmp, by = "par", sort = FALSE)
if (any(unique(tmp$par) != unique(db$par))) stop("sorting is broken, try again")

# Remove rownames.
# Remove row names.
rownames(tmp) <- NULL

# Extract avg and se into separate datasets.
Expand All @@ -106,7 +108,7 @@ avg_event <- function(id, group, par = NULL) {
#' the same way as the input datasets.
#'
#' @inheritParams n_subject
#' @param dur A numeric vector of AE duration.
#' @param dur A numeric vector of adverse event duration.
#'
#' @importFrom stats sd reshape
#'
Expand Down Expand Up @@ -156,11 +158,11 @@ avg_duration <- function(id, group, dur, par = NULL) {
tmp <- merge(data.frame(par = unique(db$par)), tmp, by = "par", sort = FALSE)
if (any(unique(tmp$par) != unique(db$par))) stop("sorting is broken, try again")

# Set rownames to null.
# Set row names to null.
rownames(tmp) <- NULL


# Extract avg and se into separate datasets.
# Extract avg and se into a separate datasets.
avg <- cbind(par = tmp$par, tmp[, grepl(names(tmp), pattern = "^avg")])
names(avg) <- sub(names(avg), pattern = "avg\\.", replacement = "")
# Reorder columns (group) to be as input.
Expand Down
2 changes: 2 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
#'
#' @format A data frame with 591 rows and 41 variables.
#'
#' @return An analysis data frame.
#'
#' @source \url{https://github.com/phuse-org/phuse-scripts/tree/master/data/sdtm/cdiscpilot01}
"metalite_ae_adex"
24 changes: 12 additions & 12 deletions R/extend_ae_specific.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -14,7 +14,7 @@
# 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/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#' Add inference information for AE specific analysis
#'
Expand Down Expand Up @@ -95,8 +95,8 @@ extend_ae_specific_inference <- function(outdata, ci = 0.95) {
#' Add average duration information for AE specific analysis
#'
#' @param outdata An `outdata` object created by [prepare_ae_specific()].
#' @param duration_var A character value of variable name for AE duration.
#' @param duration_unit A character value of AE duration unit.
#' @param duration_var A character value of variable name for adverse event duration.
#' @param duration_unit A character value of adverse event duration unit.
#'
#' @return A list of analysis raw datasets.
#'
Expand Down Expand Up @@ -140,7 +140,7 @@ extend_ae_specific_duration <- function(outdata,
par_var <- collect_adam_mapping(meta, parameter)$var
par_soc <- collect_adam_mapping(meta, parameter)$soc

# Obtain Data
# Obtain data
pop <- collect_population_record(meta, population, var = pop_var)
obs <- collect_observation_record(meta, population, observation, parameter,
var = unique(c(obs_var, par_var, par_soc, obs_dur))
Expand Down Expand Up @@ -181,7 +181,7 @@ extend_ae_specific_duration <- function(outdata,
u_group <- levels(pop[[pop_group]])
n_group <- length(u_group)

# Overall Duration
# Overall duration
obs_duration <- avg_duration(obs[[obs_id]], obs[[obs_group]], obs[[obs_dur]])
obs_order <- 1e2

Expand All @@ -204,7 +204,7 @@ extend_ae_specific_duration <- function(outdata,
se <- rbind(se, par_duration$se)
}

# Define Order and add blank row
# Define order and add a blank row
index <- c(obs_order, soc_order, par_order)
blank_order <- setdiff(outdata$order, index)
blank_row <- data.frame(matrix(NA, nrow = length(blank_order), ncol = n_group))
Expand Down Expand Up @@ -255,7 +255,7 @@ extend_ae_specific_events <- function(outdata) {
par_var <- collect_adam_mapping(meta, parameter)$var
par_soc <- collect_adam_mapping(meta, parameter)$soc

# Obtain Data
# Obtain data
pop <- collect_population_record(meta, population, var = pop_var)
obs <- collect_observation_record(meta, population, observation, parameter,
var = unique(c(obs_var, par_var, par_soc))
Expand Down Expand Up @@ -296,7 +296,7 @@ extend_ae_specific_events <- function(outdata) {
u_group <- levels(pop[[pop_group]])
n_group <- length(u_group)

# Overall Duration
# Overall duration
obs_events <- avg_event(obs[[obs_id]], obs[[obs_group]])
obs_order <- 1e2

Expand All @@ -319,7 +319,7 @@ extend_ae_specific_events <- function(outdata) {
se <- rbind(se, par_events$se)
}

# Define Order and add blank row
# Define order and add a blank row
index <- c(obs_order, soc_order, par_order)
blank_order <- setdiff(outdata$order, index)
blank_row <- data.frame(matrix(NA, nrow = length(blank_order), ncol = n_group))
Expand All @@ -339,9 +339,9 @@ extend_ae_specific_events <- function(outdata) {
outdata
}

#' Add Subgroup analysis in AE specific analysis
#' Add subgroup analysis in AE specific analysis
#'
#' @param subgroup a character string for subgroup variable name
#' @param subgroup A character string for subgroup variable name.
#'
#' @export
extend_ae_specific_subgroup <- function(outdata, subgroup) {
Expand Down
4 changes: 2 additions & 2 deletions R/fmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand Down Expand Up @@ -48,7 +48,7 @@ fmt_pct <- function(x, digits = 1, pre = "(", post = ")") {
#' Decimals will understand the number will be formatted as x.x (x.xx).
#'
#' @param mean A numeric vector of mean value.
#' @param sd A numeric vector of sd value.
#' @param sd A numeric vector of standard deviation value.
#' @param digits Digits of each column, i.e., format as x.x (x.xx).
#' @param width Width of each column.
#'
Expand Down
14 changes: 7 additions & 7 deletions R/format_ae_specific.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -23,18 +23,18 @@
#' @param digits_ci A numeric value of number of digits for confidence interval.
#' @param digits_p A numeric value of number of digits for p-value.
#' @param digits_dur A numeric value of number of digits for average
#' duration of AE.
#' duration of adverse event.
#' @param digits_events A numeric value of number of digits for average of
#' number of AE per subjects.
#' number of adverse event per subjects.
#' @param display A character vector of measurement to be displayed:
#' - `n`: Number of subjects with AE.
#' - `prop`: Proportion of subjects with AE.
#' - `n`: Number of subjects with adverse event.
#' - `prop`: Proportion of subjects with adverse event.
#' - `total`: Total columns.
#' - `diff`: Risk difference.
#' - `diff_ci`: 95% confidence interval of risk difference using M&N method.
#' - `diff_p`: p-value of risk difference using M&N method.
#' - `dur`: Average of AE duration.
#' - `events`: Average number of AE per subject.
#' - `dur`: Average of adverse event duration.
#' - `events`: Average number of adverse event per subject.
#' @param mock A boolean value to display mock table.
#'
#' @return A list of analysis raw datasets.
Expand Down
24 changes: 12 additions & 12 deletions R/format_ae_specific_subgroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -16,25 +16,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#' Format AE specific analysis
#' Format AE specific subgroup analysis
#'
#' @inheritParams format_ae_specific
#' @param digits_prop A numeric value of number of digits for proportion value.
#' @param digits_ci A numeric value of number of digits for confidence interval
#' @param digits_p A numeric value of number of digits for p-value .
#' @param digits_ci A numeric value of number of digits for confidence interval.
#' @param digits_p A numeric value of number of digits for p-value.
#' @param digits_dur A numeric value of number of digits for
#' average duration of AE.
#' average duration of adverse event.
#' @param digits_events A numeric value of number of digits for
#' average of number of AE per subjects.
#' average of number of adverse event per subjects.
#' @param display A character vector of measurement to be displayed.
#' - `n`: Number of subjects with AE.
#' - `prop`: Proportion of subjects with AE.
#' - `n`: Number of subjects with adverse event.
#' - `prop`: Proportion of subjects with adverse event.
#' - `total`: Total columns.
#' - `dur`: Average of AE duration.
#' - `events`: Average number of AE per subject.
#' - `dur`: Average of adverse event duration.
#' - `events`: Average number of adverse event per subject.
#' @param mock Logical. Display mock table or not.
#'
#' @return A list of analysis raw datasets.
#' @return A list of analysis raw datasets for subgroup analysis.
#'
#' @export
#'
Expand Down Expand Up @@ -100,7 +100,7 @@ format_ae_specific_subgroup <- function(
}
}

# Need order column from Total Column for Ordering properly across tables
# Need order column from total column for ordering properly across tables
tbl <- tbl[order(tbl$order), ]

# If outdata$display_subgroup_total = FALSE, remove that part
Expand Down
2 changes: 1 addition & 1 deletion R/meta_ae_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand Down
10 changes: 6 additions & 4 deletions R/outdata.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' Evaluate a call using outdata
#'
#' @param outdata a outdata object.
#' @param call a function call that require `outdata` object as an input.
#' @param outdata An outdata object.
#' @param call A function call that require `outdata` object as an input.
#'
#' @return outdata object
#'
#' @noRd
outdata_eval_extend_call <- function(outdata, call) {
Expand All @@ -11,8 +13,8 @@ outdata_eval_extend_call <- function(outdata, call) {

#' Evaluate a call using outdata
#'
#' @param outdata a outdata object.
#' @param call a function call that require `outdata` object as an input.
#' @param outdata An outdata object.
#' @param call A function call that require `outdata` object as an input.
#'
#' @noRd
outdata_eval_prepare_call <- function(outdata) {
Expand Down
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand Down
6 changes: 3 additions & 3 deletions R/prepare_ae_exp_adj.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -16,7 +16,7 @@
# 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 datasets for AE specific analysis
#' Prepare datasets for exposure adjusted AE analysis
#'
#' @param meta A metadata object created by metalite.
#' @param population A character value of population term name.
Expand All @@ -30,7 +30,7 @@
#' @param adj_unit A character value of exposure adjusted unit.
#' It could be select from `"year"`, `"month"`, `"week"`, and `"day"`.
#'
#' @return A list of analysis raw datasets.
#' @return A list of analysis datasets needed for AE exposure adjusted.
#'
#' @export
#'
Expand Down
6 changes: 3 additions & 3 deletions R/prepare_ae_listing.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -16,7 +16,7 @@
# 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 datasets for AE specific analysis
#' Prepare datasets for AE listing
#'
#' @param meta A metadata object created by metalite.
#' @param analysis Analysis name from `meta`.
Expand All @@ -27,7 +27,7 @@
#' @param parameter A character value of parameter term name.
#' The term name is used as key to link information.
#'
#' @return A list of analysis raw datasets.
#' @return A list of analysis datasets needed for AE listing.
#'
#' @import metalite
#'
Expand Down
4 changes: 2 additions & 2 deletions R/prepare_ae_specific.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# metalite.ae is a 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.
Expand All @@ -29,7 +29,7 @@
#' @param reference_group An integer to indicate reference group.
#' Default is 2 if there are 2 groups, otherwise, the default is 1.
#'
#' @return A list of analysis raw datasets.
#' @return A list of analysis datasets needed for AE specific analysis.
#'
#' @import metalite
#'
Expand Down
Loading