diff --git a/R/data_generation.R b/R/data_generation.R index 7b34c1ca..ec702ea5 100644 --- a/R/data_generation.R +++ b/R/data_generation.R @@ -9,6 +9,7 @@ #' of 35% under the active treatment at baseline (with the values of the covariates set to zero). #' #' @param N sample size +#' @param ncov number of covariates to generate #' @param lambda scale parameter in baseline hazard function #' @param nu shape parameter in baseline hazard function #' @param censor_rate rate parameter of the exponential distribution of censoring times diff --git a/R/matching.R b/R/matching.R index 2f3383e4..aa695724 100644 --- a/R/matching.R +++ b/R/matching.R @@ -4,8 +4,9 @@ #' Derive individual weights in the matching step of MAIC #' -#' Assuming data is properly processed, this function takes individual patient data (IPD) with centered covariates (effect modifiers and/or prognostic variables) as input, -#' and generates weights for each individual in IPD trial that matches the chosen statistics of those covariates in Aggregated Data (AgD) trial. +#' Assuming data is properly processed, this function takes individual patient data (IPD) with centered covariates +#' (effect modifiers and/or prognostic variables) as input, and generates weights for each individual in IPD trial that +#' matches the chosen statistics of those covariates in Aggregated Data (AgD) trial. #' #' @param data a numeric matrix, centered covariates of IPD, no missing value in any cell is allowed #' @param centered_colnames a character or numeric vector (column indicators) of centered covariates @@ -17,9 +18,11 @@ #' @return a list with the following 4 elements, #' \describe{ #' \item{data}{a data.frame, includes the input \code{data} with appended column 'weights' and 'scaled_weights'. -#' Scaled weights has a summation to be the number of rows in \code{data} that has no missing value in any of the effect modifiers} +#' Scaled weights has a summation to be the number of rows in \code{data} that has no missing value in any of the +#' effect modifiers} #' \item{centered_colnames}{column names of centered effect modifiers in \code{data}} -#' \item{nr_missing}{number of rows in \code{data} that has at least 1 missing value in specified centered effect modifiers} +#' \item{nr_missing}{number of rows in \code{data} that has at least 1 missing value in specified centered effect +#' modifiers} #' \item{ess}{effective sample size, square of sum divided by sum of squares} #' \item{opt}{R object returned by \code{base::optim()}, for assess convergence and other details} #' } @@ -32,10 +35,10 @@ estimate_weights <- function(data, centered_colnames = NULL, start_val = 0, meth if (!ch1) stop("'data' is not a data.frame") ch2 <- (!is.null(centered_colnames)) - if (ch2 & is.numeric(centered_colnames)) { + if (ch2 && is.numeric(centered_colnames)) { ch2b <- any(centered_colnames < 1 | centered_colnames > ncol(data)) if (ch2b) stop("specified centered_colnames are out of bound") - } else if (ch2 & is.character(centered_colnames)) { + } else if (ch2 && is.character(centered_colnames)) { ch2b <- !all(centered_colnames %in% names(data)) if (ch2b) stop("1 or more specified centered_colnames are not found in 'data'") } else { @@ -45,7 +48,9 @@ estimate_weights <- function(data, centered_colnames = NULL, start_val = 0, meth ch3 <- sapply(seq_along(centered_colnames), function(ii) { !is.numeric(data[, centered_colnames[ii]]) }) - if (any(ch3)) stop(paste0("following columns of 'data' are not numeric for the calculation:", paste(which(ch3), collapse = ","))) + if (any(ch3)) { + stop(paste0("following columns of 'data' are not numeric for the calculation:", paste(which(ch3), collapse = ","))) + } # prepare data for optimization if (is.null(centered_colnames)) centered_colnames <- seq_len(ncol(data)) @@ -149,8 +154,9 @@ plot_weights <- function(wt, main_title = "Unscaled Individual Weights") { #' before and after adjustment. #' #' @param optimized object returned after calculating weights using \code{\link{cal_weights}} -#' @param match_cov covariates that should be checked to see if the IPD weighted average matches the aggregate data average -#' This could be same set of variables that were used to match or it can include variables that were not included to match (i.e. stratification variables) +#' @param match_cov covariates that should be checked to see if the IPD weighted average matches the aggregate data +#' average. This could be same set of variables that were used to match or it can include variables that were not +#' included to match (i.e. stratification variables) #' @param digits number of digits for rounding summary table #' #' @return data.frame of weighted and unweighted covariate averages of the IPD diff --git a/R/process_data.R b/R/process_data.R index 60ab9cce..74a84349 100644 --- a/R/process_data.R +++ b/R/process_data.R @@ -226,6 +226,7 @@ complete_agd <- function(use_agd) { #' #' @param dd data frame, ADTTE read via haven::read_sas #' @param time_scale a character string, 'year', 'month', 'week' or 'day', time unit of median survival time +#' @param trt values to include in treatment column #' #' @return a data frame that can be used as input to survival::Surv ext_tte_transfer <- function(dd, time_scale = "month", trt = NULL) { diff --git a/man/check_weights.Rd b/man/check_weights.Rd index bcb61209..03d81c34 100644 --- a/man/check_weights.Rd +++ b/man/check_weights.Rd @@ -9,8 +9,9 @@ check_weights(optimized, match_cov, digits = 2) \arguments{ \item{optimized}{object returned after calculating weights using \code{\link{cal_weights}}} -\item{match_cov}{covariates that should be checked to see if the IPD weighted average matches the aggregate data average -This could be same set of variables that were used to match or it can include variables that were not included to match (i.e. stratification variables)} +\item{match_cov}{covariates that should be checked to see if the IPD weighted average matches the aggregate data +average. This could be same set of variables that were used to match or it can include variables that were not +included to match (i.e. stratification variables)} \item{digits}{number of digits for rounding summary table} } diff --git a/man/estimate_weights.Rd b/man/estimate_weights.Rd index 8295cdf8..d3d1151c 100644 --- a/man/estimate_weights.Rd +++ b/man/estimate_weights.Rd @@ -28,14 +28,17 @@ The default is \code{"BFGS"}, other options are \code{"Nelder-Mead"}, \code{"CG" a list with the following 4 elements, \describe{ \item{data}{a data.frame, includes the input \code{data} with appended column 'weights' and 'scaled_weights'. -Scaled weights has a summation to be the number of rows in \code{data} that has no missing value in any of the effect modifiers} +Scaled weights has a summation to be the number of rows in \code{data} that has no missing value in any of the +effect modifiers} \item{centered_colnames}{column names of centered effect modifiers in \code{data}} -\item{nr_missing}{number of rows in \code{data} that has at least 1 missing value in specified centered effect modifiers} +\item{nr_missing}{number of rows in \code{data} that has at least 1 missing value in specified centered effect +modifiers} \item{ess}{effective sample size, square of sum divided by sum of squares} \item{opt}{R object returned by \code{base::optim()}, for assess convergence and other details} } } \description{ -Assuming data is properly processed, this function takes individual patient data (IPD) with centered covariates (effect modifiers and/or prognostic variables) as input, -and generates weights for each individual in IPD trial that matches the chosen statistics of those covariates in Aggregated Data (AgD) trial. +Assuming data is properly processed, this function takes individual patient data (IPD) with centered covariates +(effect modifiers and/or prognostic variables) as input, and generates weights for each individual in IPD trial that +matches the chosen statistics of those covariates in Aggregated Data (AgD) trial. } diff --git a/man/ext_tte_transfer.Rd b/man/ext_tte_transfer.Rd index 1ab0ab4b..588cc50d 100644 --- a/man/ext_tte_transfer.Rd +++ b/man/ext_tte_transfer.Rd @@ -10,6 +10,8 @@ ext_tte_transfer(dd, time_scale = "month", trt = NULL) \item{dd}{data frame, ADTTE read via haven::read_sas} \item{time_scale}{a character string, 'year', 'month', 'week' or 'day', time unit of median survival time} + +\item{trt}{values to include in treatment column} } \value{ a data frame that can be used as input to survival::Surv diff --git a/man/generate_survival_data.Rd b/man/generate_survival_data.Rd index eb5ab5e5..c428ee50 100644 --- a/man/generate_survival_data.Rd +++ b/man/generate_survival_data.Rd @@ -22,6 +22,8 @@ generate_survival_data( \arguments{ \item{N}{sample size} +\item{ncov}{number of covariates to generate} + \item{lambda}{scale parameter in baseline hazard function} \item{nu}{shape parameter in baseline hazard function}