From 5bb3c3b20f57b28281556068c01911b8b07a0ac3 Mon Sep 17 00:00:00 2001 From: Dr Nathan Green Date: Fri, 8 Dec 2023 17:00:27 +0000 Subject: [PATCH] moved some functions to internal and rebuild GH pages --- NAMESPACE | 5 - R/IPD_stats.R | 8 +- R/cor2cov.R | 1 + R/gen_data.R | 2 + R/parse_formula.R | 10 +- R/performance_measures.R | 26 +++++ R/process_metrics.R | 2 + _pkgdown.yml | 21 ---- docs/404.html | 2 +- docs/LICENSE.html | 2 +- docs/articles/Basic_example.html | 32 +++--- docs/articles/index.html | 4 +- docs/authors.html | 2 +- docs/index.html | 4 +- docs/news/index.html | 2 +- docs/pkgdown.yml | 2 +- docs/reference/ALD_stats.html | 2 +- docs/reference/IPD_stats.html | 2 +- docs/reference/Q.html | 21 +++- docs/reference/bias.html | 21 +++- docs/reference/bias.mcse.html | 2 +- docs/reference/cor2cov.html | 2 +- docs/reference/coverage.html | 2 +- docs/reference/coverage.mcse.html | 2 +- docs/reference/empse.html | 2 +- docs/reference/empse.mcse.html | 2 +- docs/reference/gcomp_ml.boot.html | 2 +- docs/reference/gcomp_ml_log_odds_ratio.html | 2 +- docs/reference/gcomp_stan.html | 2 +- docs/reference/gen_data.html | 2 +- docs/reference/get_covariate_names.html | 2 +- docs/reference/get_effect_modifiers.html | 2 +- docs/reference/get_mean_names.html | 2 +- docs/reference/get_sd_names.html | 2 +- docs/reference/get_treatment_name.html | 2 +- docs/reference/hat_Delta_stats.html | 4 +- docs/reference/index.html | 107 +----------------- docs/reference/mae.html | 2 +- docs/reference/maic.boot.html | 2 +- docs/reference/maic_weights.html | 2 +- docs/reference/marginal_treatment_effect.html | 2 +- docs/reference/marginal_variance.html | 2 +- docs/reference/mcse.estimate.html | 2 +- docs/reference/mse.html | 2 +- docs/reference/mse.mcse.html | 2 +- docs/reference/process_metrics.html | 2 +- docs/reference/strategy.html | 13 +-- docs/reference/trial_treatment_effect.html | 2 +- docs/reference/trial_variance.html | 2 +- docs/reference/var.ratio.html | 2 +- docs/reference/var.ratio.mcse.html | 2 +- docs/search.json | 2 +- man/Q.Rd | 10 +- man/bias.Rd | 10 +- man/bias.mcse.Rd | 1 + man/cor2cov.Rd | 1 + man/coverage.Rd | 1 + man/coverage.mcse.Rd | 1 + man/empse.Rd | 1 + man/empse.mcse.Rd | 1 + man/gen_data.Rd | 1 + man/get_covariate_names.Rd | 1 + man/get_effect_modifiers.Rd | 1 + man/get_mean_names.Rd | 1 + man/get_sd_names.Rd | 1 + man/get_treatment_name.Rd | 1 + man/hat_Delta_stats.Rd | 2 +- man/mae.Rd | 1 + man/mcse.estimate.Rd | 1 + man/mse.Rd | 1 + man/mse.mcse.Rd | 1 + man/process_metrics.Rd | 1 + man/strategy.Rd | 5 +- man/var.ratio.Rd | 1 + man/var.ratio.mcse.Rd | 1 + 75 files changed, 172 insertions(+), 227 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 1b98176..8e15120 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,11 +9,6 @@ export(IPD_stats) export(gcomp_ml.boot) export(gcomp_ml_log_odds_ratio) export(gcomp_stan) -export(get_covariate_names) -export(get_effect_modifiers) -export(get_mean_names) -export(get_sd_names) -export(get_treatment_name) export(hat_Delta_stats) export(marginal_treatment_effect) export(marginal_variance) diff --git a/R/IPD_stats.R b/R/IPD_stats.R index e70e279..e125211 100644 --- a/R/IPD_stats.R +++ b/R/IPD_stats.R @@ -14,7 +14,7 @@ #' } #' #' @param formula Linear regression formula object -#' @param R +#' @param R The number of resamples used for the non-parametric bootstrap #' @param ald Aggregate-level data #' #' @return `maic` class object @@ -45,9 +45,7 @@ strategy_maic <- function(formula = as.formula("y ~ X3 + X4 + trt*X1 + trt*X2"), #' @export # strategy_stc <- function(formula = - as.formula("y ~ X3 + X4 + - trt*I(X1 - mean(X1)) + - trt*I(X2 - mean(X2))")) { + as.formula("y ~ X3 + X4 + trt*I(X1 - mean(X1)) + trt*I(X2 - mean(X2))")) { default_args <- formals() args <- as.list(match.call())[-1] args <- modifyList(default_args, args) @@ -64,7 +62,7 @@ strategy_stc <- function(formula = #' } #' #' @param formula Linear regression formula object -#' @param R +#' @param R The number of resamples used for the non-parametric bootstrap #' #' @return `gcomp_ml` class object #' @export diff --git a/R/cor2cov.R b/R/cor2cov.R index 85fd653..a9226a7 100644 --- a/R/cor2cov.R +++ b/R/cor2cov.R @@ -4,6 +4,7 @@ #' @param R correlation matrix #' @param S vector of standard deviations covariance matrix #' @return Required input for \code{mvrnorm}. +#' @keywords internal #' cor2cov <- function(R, S) { sweep(sweep(R, 1, S, "*"), 2, S, "*") diff --git a/R/gen_data.R b/R/gen_data.R index be45b1c..a6ac475 100644 --- a/R/gen_data.R +++ b/R/gen_data.R @@ -13,6 +13,8 @@ #' @param allocation Allocation #' @return Data frame of `X`, `trt` and `y` #' +#' @keywords internal +#' gen_data <- function(N, b_trt, b_X, b_EM, b_0, meanX, sdX, event_rate, corX, allocation) { diff --git a/R/parse_formula.R b/R/parse_formula.R index a8b57a4..23b0347 100644 --- a/R/parse_formula.R +++ b/R/parse_formula.R @@ -4,7 +4,7 @@ #' @param formula Linear regression formula #' #' @return Effect modifiers names -#' @export +#' @keywords internal #' get_effect_modifiers <- function(formula) { @@ -22,7 +22,7 @@ get_effect_modifiers <- function(formula) { #' @param formula Linear regression formula #' #' @return Treatment name -#' @export +#' @keywords internal #' get_treatment_name <- function(formula) { formula <- as.formula(formula) @@ -39,7 +39,7 @@ get_treatment_name <- function(formula) { #' @param var_names Variable names #' #' @return Mean names -#' @export +#' @keywords internal #' get_mean_names <- function(dat, var_names) { dat_names <- names(dat) @@ -56,7 +56,7 @@ get_mean_names <- function(dat, var_names) { #' @param var_names #' #' @return SD names -#' @export +#' @keywords internal #' get_sd_names <- function(dat, var_names) { dat_names <- names(dat) @@ -72,7 +72,7 @@ get_sd_names <- function(dat, var_names) { #' @param formula Linear regression formula #' #' @return covariate names -#' @export +#' @keywords internal #' get_covariate_names <- function(formula) { all.vars(formula)[-1] diff --git a/R/performance_measures.R b/R/performance_measures.R index c9b0784..5c3d509 100644 --- a/R/performance_measures.R +++ b/R/performance_measures.R @@ -5,6 +5,8 @@ #' #' @param beta Beta #' @param X X +#' @keywords internal +#' Q <- function(beta, X) { sum(exp(X %*% beta)) } @@ -13,6 +15,8 @@ Q <- function(beta, X) { #' #' @param theta.hat Theta hat #' @param theta Theta +#' @keywords internal +#' bias <- function(theta.hat, theta) { nsim <- length(theta.hat) sum(theta.hat)/nsim - theta @@ -21,6 +25,8 @@ bias <- function(theta.hat, theta) { #' Monte Carlo SE of bias estimate #' @param theta.hat theta hat #' @return \eqn{sqrt(1/(nsim*(nsim-1))*tmp)} +#' @keywords internal +#' bias.mcse <- function(theta.hat) { nsim <- length(theta.hat) tmp <- sum((theta.hat - mean(theta.hat))^2) @@ -33,6 +39,8 @@ bias.mcse <- function(theta.hat) { #' @param upp Upper #' @param theta Theta #' @return \eqn{sum(in_range)/nsim} +#' @keywords internal +#' coverage <- function(low, upp, theta) { nsim <- length(low) theta_inside_range <- theta >= low & theta <= upp @@ -45,6 +53,8 @@ coverage <- function(low, upp, theta) { #' @param coverage Coverage #' @param nsim Number of simulations #' @return \eqn{sqrt((coverage*(1 - coverage))/nsim)} +#' @keywords internal +#' coverage.mcse <- function(coverage, nsim) { sqrt((coverage*(1 - coverage))/nsim) } @@ -54,6 +64,8 @@ coverage.mcse <- function(coverage, nsim) { #' @param theta.hat Theta hat #' @param theta Theta #' @return \eqn{sum((theta.hat - theta)^2)/nsim} +#' @keywords internal +#' mse <- function(theta.hat, theta) { nsim <- length(theta.hat) sum((theta.hat - theta)^2)/nsim @@ -64,6 +76,8 @@ mse <- function(theta.hat, theta) { #' @param theta.hat Theta hat #' @param theta Theta #' @return \eqn{sqrt(sum((tmp - mse.est)^2)/(nsim*(nsim-1)))} +#' @keywords internal +#' mse.mcse <- function(theta.hat, theta) { nsim <- length(theta.hat) tmp <- (theta.hat - theta)^2 @@ -76,6 +90,8 @@ mse.mcse <- function(theta.hat, theta) { #' @param theta.hat Theta hat #' @param theta Theta #' @return \eqn{sum(abs(theta.hat - theta))/nsim} +#' @keywords internal +#' mae <- function(theta.hat, theta) { nsim <- length(theta.hat) sum(abs(theta.hat - theta))/nsim @@ -85,6 +101,8 @@ mae <- function(theta.hat, theta) { #' #' @param pm pm #' @return \eqn{sqrt(sum((pm - pm_mean)^2)/(nsim*(nsim-1)))} +#' @keywords internal +#' mcse.estimate <- function(pm) { nsim <- length(pm) pm_mean <- sum(pm)/nsim @@ -95,6 +113,8 @@ mcse.estimate <- function(pm) { #' #' @param theta.hat Theta #' @return \eqn{sqrt(tmp/(nsim-1))} +#' @keywords internal +#' empse <- function(theta.hat) { nsim <- length(theta.hat) tmp <- sum((theta.hat - mean(theta.hat))^2) @@ -106,6 +126,8 @@ empse <- function(theta.hat) { #' @param empse EMPSE #' @param nsim Number of simulations #' @return \eqn{empse/(sqrt(2*(nsim-1)))} +#' @keywords internal +#' empse.mcse <- function(empse, nsim) { empse/(sqrt(2*(nsim-1))) } @@ -115,6 +137,8 @@ empse.mcse <- function(empse, nsim) { #' @param theta.hat Theta hat #' @param std.err Standard error #' @return Ratio +#' @keywords internal +#' var.ratio <- function(theta.hat, std.err) { nsim <- length(theta.hat) num <- sum(std.err)/nsim @@ -135,6 +159,8 @@ var.ratio <- function(theta.hat, std.err) { #' @references #' \insertRef{wolter2007}{mimR} #' +#' @keywords internal +#' var.ratio.mcse <- function(avg.se, emp.se, var.avg.se, var.emp.se) { sqrt((1/emp.se^2)*var.avg.se + (((avg.se^2)/(emp.se^4))*var.emp.se)) diff --git a/R/process_metrics.R b/R/process_metrics.R index 6212835..ffde896 100644 --- a/R/process_metrics.R +++ b/R/process_metrics.R @@ -5,6 +5,8 @@ #' @param variances Variances #' @param truth Truth #' +#' @keywords internal +#' process_metrics <- function(means, variances, truth) { # remove NAs (an issue for MAIC in Scenario 7, separation issues) NAs <- is.na(means) diff --git a/_pkgdown.yml b/_pkgdown.yml index e9c6933..35d1c66 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -24,36 +24,15 @@ reference: desc: "Helper functions" contents: - ALD_stats - - bias.mcse - - bias - - cor2cov - - coverage.mcse - - coverage - - empse.mcse - - empse - gcomp_ml.boot - gcomp_ml_log_odds_ratio - gcomp_stan - - gen_data - - get_covariate_names - - get_effect_modifiers - - get_mean_names - - get_sd_names - - get_treatment_name - IPD_stats - - mae - maic.boot - maic_weights - marginal_treatment_effect - marginal_variance - - mcse.estimate - - mse.mcse - - mse - - process_metrics - - Q - strategy_maic - trial_treatment_effect - trial_variance - - var.ratio.mcse - - var.ratio \ No newline at end of file diff --git a/docs/404.html b/docs/404.html index e5f7c70..d6b7480 100644 --- a/docs/404.html +++ b/docs/404.html @@ -39,7 +39,7 @@