Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export(Stack)
export(add_class)
export(analyse)
export(ancova)
export(as_analysis)
export(as_class)
export(as_simple_formula)
export(as_vcov)
export(control_bayes)
export(delta_template)
Expand All @@ -57,11 +59,13 @@ export(extract_imputed_dfs)
export(fill_locf)
export(getStrategies)
export(get_example_data)
export(get_pool_components)
export(has_class)
export(impute)
export(jackknife_se)
export(locf)
export(longDataConstructor)
export(lsmeans)
export(make_rbmi_cluster)
export(mcse)
export(mcse_combine_all_pars)
Expand All @@ -70,8 +74,10 @@ export(method_approxbayes)
export(method_bayes)
export(method_bmlmi)
export(method_condmean)
export(parametric_ci)
export(pool)
export(pool_internal)
export(rubin_rules)
export(set_simul_pars)
export(set_vars)
export(simulate_data)
Expand All @@ -80,6 +86,7 @@ export(strategy_CR)
export(strategy_JR)
export(strategy_LMCF)
export(strategy_MAR)
export(transpose_results)
export(validate)
export(validate_analyse_pars)
import(R6)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# rbmi (development version)

## Added

* Exported internal helper functions: `extract_covariates`, `as_simple_formula`, `lsmeans`, `as_analysis`, `transpose_results`, `get_pool_components`, `rubin_rules`, and `parametric_ci`.


## Bug Fixes
* Added en-GB spell-check and a corresponding test to the package
* Fixed numerous spelling errors and standardised nomenclature for missing not
Expand Down
1 change: 1 addition & 0 deletions R/analyse.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ extract_imputed_df <- function(imputation, ld, delta = NULL, idmap = FALSE) {
#' @param fun The analysis function that was used.
#' @param fun_name The character name of the analysis function (used for printing)
#' purposes.
#' @export
as_analysis <- function(
results,
method,
Expand Down
1 change: 1 addition & 0 deletions R/lsmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#' lsmeans(mod, Species = "versicolor", Petal.Length = 1)
#' }
#' @importFrom stats model.matrix terms reformulate
#' @export
lsmeans <- function(
model,
...,
Expand Down
4 changes: 4 additions & 0 deletions R/pool.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pool <- function(
#'
#' @param x Character name of the analysis method, must one of
#' either `"rubin"`, `"jackknife"`, "`bootstrap"` or `"bmlmi"`.
#' @export
get_pool_components <- function(x) {
switch(
x,
Expand Down Expand Up @@ -383,6 +384,7 @@ rubin_df <- function(v_com, var_b, var_t, M) {
#' Roderick J. A. Little and Donald B. Rubin. Statistical Analysis with Missing
#' Data, Second Edition. John Wiley & Sons, Hoboken, New Jersey, 2002. \[Section 5.4\]
#' @importFrom stats var
#' @export
rubin_rules <- function(ests, ses, v_com) {
M <- length(ests)
est_point <- mean(ests)
Expand Down Expand Up @@ -568,6 +570,7 @@ pool_bootstrap_normal <- function(est, conf.level, alternative) {
#'
#' @param ... additional arguments passed on `qfun` and `pfun` i.e. `df = 102`.
#'
#' @export
parametric_ci <- function(point, se, alpha, alternative, qfun, pfun, ...) {
ci <- switch(
alternative,
Expand Down Expand Up @@ -652,6 +655,7 @@ parametric_ci <- function(point, se, alpha, alternative, qfun, pfun, ...) {
#' )
#' )
#' ```
#' @export
transpose_results <- function(results, components) {
elements <- names(results[[1]])
results_transpose <- list()
Expand Down
1 change: 1 addition & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ has_class <- function(x, cls) {
#' @param covars character (vector). Name of covariates
#' @return
#' A formula
#' @export
as_simple_formula <- function(outcome, covars) {
frm <- stats::as.formula(
paste0(
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library(testthat)

test_that("utilities exports behave sensibly", {
expect_true(is.character(extract_covariates(c("v1", "v2:v3"))))
expect_setequal(extract_covariates(c("v1", "v2:v3")), c("v1", "v2", "v3"))
f <- as_simple_formula("y", c("a", "b"))
expect_s3_class(f, "formula")
})

test_that("pool helpers and CI functions", {
expect_equal(get_pool_components("rubin"), c("est", "df", "se"))
rr <- rubin_rules(ests = c(1, 2, 3), ses = c(1, 1, 1), v_com = 10)
expect_named(rr, c("est_point", "var_t", "df"))
pc <- parametric_ci(1, 1, 0.05, "two.sided", qnorm, pnorm)
expect_named(pc, c("est", "ci", "se", "pvalue"))
tr_in <- list(list(a = list(est = 1, se = 2)), list(a = list(est = 3, se = 4)))
tr_out <- transpose_results(tr_in, c("est", "se"))
expect_true(is.list(tr_out))
expect_named(tr_out, "a")
})

test_that("as_analysis constructs analysis object", {
method <- list(n_samples = 3, D = 1)
class(method) <- c("method", "bayes")
results <- list(
list(par1 = list(est = 1, df = 1, se = 2)),
list(par1 = list(est = 2, df = 1, se = 2)),
list(par1 = list(est = 3, df = 1, se = 2))
)
ana <- as_analysis(results, method = method, delta = NULL, fun = NULL, fun_name = "fn")
expect_s3_class(ana, "analysis")
})