From 631ca2180aff26158fdd76fe789988146575eb7a Mon Sep 17 00:00:00 2001 From: gravesti Date: Thu, 13 Jul 2023 08:52:18 +0200 Subject: [PATCH] fix warnings --- R/data_generation.R | 2 +- R/matching.R | 16 +++++++++++----- man/check_weights.Rd | 2 +- man/generate_survival_data.Rd | 2 +- man/plot_weights.Rd | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/R/data_generation.R b/R/data_generation.R index ec702ea5..7d6c98b2 100644 --- a/R/data_generation.R +++ b/R/data_generation.R @@ -1,7 +1,7 @@ #' Generate time-to-event data #' #' Function generates time-to-event data. We follow the data-generating mechanism from -#' Bender et al. and Remiro-Azocar et al. 2021 to simulate Weibull-distribued survival times +#' Bender et al. and Remiro-Azocar et al. 2021 to simulate Weibull-distributed survival times #' under a proportional hazards parameterization. As per Remiro-Azocar et al, we set the #' default scale parameter (lambda) to 8.5 and shape parameter (nu) to 1.3 to reflect frequently #' observed mortality trends in metastatic cancer patients. Censoring times are generated from diff --git a/R/matching.R b/R/matching.R index aa695724..83f8c1ed 100644 --- a/R/matching.R +++ b/R/matching.R @@ -104,13 +104,13 @@ estimate_weights <- function(data, centered_colnames = NULL, start_val = 0, meth #' Generates a plot given the individuals weights with key summary in top right legend that includes #' median weight, effective sample size (ESS), and reduction percentage (what percent ESS is reduced from the #' original sample size). -#' There are two options of weights provided in \code{\link{cal_weights}}: unscaled or scaled. +#' There are two options of weights provided in \code{\link{estimate_weights}}: unscaled or scaled. #' Scaled weights are relative to the original unit weights of each individual. #' In other words, a scaled weight greater than 1 means that an individual carries more weight in the #' re-weighted population than the original data and a scaled weight less than 1 means that an individual carries #' less weight in the re-weighted population than the original data. #' -#' @param wt a numeric vector of individual MAIC weights (derived using \code{\link{cal_weights}}) +#' @param wt a numeric vector of individual MAIC weights (derived using \code{\link{estimate_weights}}) #' @param main_title a character string, main title of the plot #' #' @return a plot of unscaled or scaled weights @@ -153,7 +153,7 @@ plot_weights <- function(wt, main_title = "Unscaled Individual Weights") { #' This function checks to see if the optimization is done properly by checking the covariate averages #' before and after adjustment. #' -#' @param optimized object returned after calculating weights using \code{\link{cal_weights}} +#' @param optimized object returned after calculating weights using \code{\link{estimate_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) @@ -163,15 +163,21 @@ plot_weights <- function(wt, main_title = "Unscaled Individual Weights") { #' @export + check_weights <- function(optimized, match_cov, digits = 2) { + if (missing(match_cov)) stop("match_cov is missing. Covariates to check must be defined.") ipd_with_weights <- optimized$data arm_names <- c("Unweighted IPD", "Weighted IPD") ess <- c(nrow(ipd_with_weights), optimized$ess) - unweighted_cov <- sapply(ipd_with_weights[, match_cov], mean) + unweighted_cov <- sapply(ipd_with_weights[, match_cov, drop = FALSE], mean) - weighted_cov <- sapply(ipd_with_weights[, match_cov], weighted.mean, w = ipd_with_weights$weights) + weighted_cov <- sapply( + ipd_with_weights[, match_cov, drop = FALSE], + weighted.mean, + w = ipd_with_weights$weights + ) cov_combined <- rbind(unweighted_cov, weighted_cov) diff --git a/man/check_weights.Rd b/man/check_weights.Rd index 03d81c34..b4bdf9be 100644 --- a/man/check_weights.Rd +++ b/man/check_weights.Rd @@ -7,7 +7,7 @@ check_weights(optimized, match_cov, digits = 2) } \arguments{ -\item{optimized}{object returned after calculating weights using \code{\link{cal_weights}}} +\item{optimized}{object returned after calculating weights using \code{\link{estimate_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 diff --git a/man/generate_survival_data.Rd b/man/generate_survival_data.Rd index c428ee50..dc1e8370 100644 --- a/man/generate_survival_data.Rd +++ b/man/generate_survival_data.Rd @@ -50,7 +50,7 @@ data.frame with survival time, censor (event) status, treatment indicator, and c } \description{ Function generates time-to-event data. We follow the data-generating mechanism from -Bender et al. and Remiro-Azocar et al. 2021 to simulate Weibull-distribued survival times +Bender et al. and Remiro-Azocar et al. 2021 to simulate Weibull-distributed survival times under a proportional hazards parameterization. As per Remiro-Azocar et al, we set the default scale parameter (lambda) to 8.5 and shape parameter (nu) to 1.3 to reflect frequently observed mortality trends in metastatic cancer patients. Censoring times are generated from diff --git a/man/plot_weights.Rd b/man/plot_weights.Rd index 2b5635b1..684faee3 100644 --- a/man/plot_weights.Rd +++ b/man/plot_weights.Rd @@ -7,7 +7,7 @@ plot_weights(wt, main_title = "Unscaled Individual Weights") } \arguments{ -\item{wt}{a numeric vector of individual MAIC weights (derived using \code{\link{cal_weights}})} +\item{wt}{a numeric vector of individual MAIC weights (derived using \code{\link{estimate_weights}})} \item{main_title}{a character string, main title of the plot} } @@ -18,7 +18,7 @@ a plot of unscaled or scaled weights Generates a plot given the individuals weights with key summary in top right legend that includes median weight, effective sample size (ESS), and reduction percentage (what percent ESS is reduced from the original sample size). -There are two options of weights provided in \code{\link{cal_weights}}: unscaled or scaled. +There are two options of weights provided in \code{\link{estimate_weights}}: unscaled or scaled. Scaled weights are relative to the original unit weights of each individual. In other words, a scaled weight greater than 1 means that an individual carries more weight in the re-weighted population than the original data and a scaled weight less than 1 means that an individual carries