Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
svteichman committed Jul 10, 2024
1 parent 4cc32d4 commit 8d35d69
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 19 deletions.
8 changes: 0 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

export(fastEmuTest)
export(old_fastEmuTest)
import(MASS)
import(Matrix)
import(radEmu)
importFrom(stats,cov)
importFrom(stats,median)
importFrom(stats,model.matrix)
importFrom(stats,optim)
importFrom(stats,pchisq)
importFrom(stats,qnorm)
importFrom(stats,rbinom)
importFrom(stats,rnbinom)
importFrom(stats,rnorm)
importFrom(stats,rpois)
importFrom(stats,weighted.mean)
16 changes: 10 additions & 6 deletions R/fastEmuTest.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#' Fit radEmu model after collapsing data into smaller joint model, runs score tests
#'
#' @param model either "full" to run score tests with the full joint model, "drop" to run score tests with
#' a conditional joint model, or "agg" to run score tests with a joint marginal model
#' @param constraint_cats a vector of category indices for categories that should be involved in the constraint
#' and retained in any smaller joint model
#' @param Y an n x J matrix or dataframe of nonnegative observations, or a phyloseq object containing an otu table and sample data.
Expand Down Expand Up @@ -72,6 +70,10 @@
#' information matrix computed from full model fit and from null model fits? Default is
#' FALSE. This parameter is used for simulations - in any applied analysis, type of
#' p-value to be used should be chosen before conducting tests.
#' @param model deprecated argument, default is "drop" to run the reduced model that drops
#' all categories not in the constraint or being tested for each score test, "full" to run tests
#' with the full joint model (equivalent to radEmu), or "agg" to run a different version of the reduced
#' model in which all categories not in the constraint or being tested are aggregated together
#'
#' @return A list containing elements 'coef', 'B', 'penalized', 'Y_augmented',
#' 'I', and 'Dy'. Parameter estimates by
Expand All @@ -88,8 +90,7 @@
#'
#' @export
#'
fastEmuTest <- function(model = "full",
constraint_cats,
fastEmuTest <- function(constraint_cats,
Y,
X = NULL,
formula = NULL,
Expand Down Expand Up @@ -125,7 +126,8 @@ fastEmuTest <- function(model = "full",
max_step = 1,
trackB = FALSE,
return_nullB = FALSE,
return_both_score_pvals = FALSE) {
return_both_score_pvals = FALSE,
model = NULL) {

if (sum(rowSums(Y) == 0) > 0) {
stop("There is at least one sample with no counts in any category. Please remove samples that have no counts in any category.")
Expand Down Expand Up @@ -190,7 +192,9 @@ fastEmuTest <- function(model = "full",
}
}


if (is.null(model)) {
model = "drop"
}
# update model based on model chosen and categories to use
if (model == "full") {
mod_Y <- Y[, new_order]
Expand Down
12 changes: 7 additions & 5 deletions man/fastEmuTest.Rd

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

57 changes: 57 additions & 0 deletions tests/testthat/test-fastEmuTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,60 @@ test_that("test-fastEmuTest works", {
return_both_score_pvals = TRUE)
expect_false(is.na(res_drop$p_vals$score_pval_null_info))
})

test_that("new updates to fastEmuTest work the same as old version", {

library(fastEmu)
library(radEmu)

# simulate data
n <- 100
J <- 200
b0 <- rnorm(J)
b1 <- rnorm(J)
X <- cbind(1, rep(c(0, 1), each = n/2),
rnorm(n))
Y <- radEmu:::simulate_data(n = n,
J = J,
b0 = b0,
b1 = b1,
distn = "Poisson",
zinb_size = 5,
zinb_zero_prop = 0.6,
mean_count_before_ZI = 50)
colnames(Y) <- paste0("category", 1:ncol(Y))

# test 100th category
# randomly select 25 categories to use as constraint
cats <- sample((1:ncol(Y))[-100], 25)

# run dropped model
# run dropped model, cat categories as constraint, test 100th
res_drop <- fastEmuTest(constraint_cats = cats,
Y = Y,
X = X,
test_kj = data.frame(k = 2, j = 100),
tau = 2,
B_null_tol = 0.005,
tolerance = 0.005,
constraint_tol = 0.001,
return_wald_p = TRUE,
use_both_cov = FALSE,
use_fullmodel_info = TRUE,
return_both_score_pvals = TRUE)
old_res_drop <- old_fastEmuTest(model = "drop",
constraint_cats = cats,
Y = Y,
X = X,
test_kj = data.frame(k = 2, j = 100),
tau = 2,
B_null_tol = 0.005,
tolerance = 0.005,
constraint_tol = 0.001,
return_wald_p = TRUE,
use_both_cov = FALSE,
use_fullmodel_info = TRUE,
return_both_score_pvals = TRUE)
expect_true(all.equal(res_drop$coef[26, ], old_res_drop$coef[26, ]))

})

0 comments on commit 8d35d69

Please sign in to comment.