Skip to content

Commit

Permalink
moved some functions to internal and rebuild GH pages
Browse files Browse the repository at this point in the history
  • Loading branch information
n8thangreen committed Dec 8, 2023
1 parent 989b857 commit 5bb3c3b
Show file tree
Hide file tree
Showing 75 changed files with 172 additions and 227 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions R/IPD_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions R/cor2cov.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, "*")
Expand Down
2 changes: 2 additions & 0 deletions R/gen_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions R/parse_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param formula Linear regression formula
#'
#' @return Effect modifiers names
#' @export
#' @keywords internal
#'
get_effect_modifiers <- function(formula) {

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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]
Expand Down
26 changes: 26 additions & 0 deletions R/performance_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#'
#' @param beta Beta
#' @param X X
#' @keywords internal
#'
Q <- function(beta, X) {
sum(exp(X %*% beta))
}
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)))
}
Expand All @@ -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
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions R/process_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 14 additions & 18 deletions docs/articles/Basic_example.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5bb3c3b

Please sign in to comment.