Skip to content
Open
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
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: enviromtx
Title: Predicting Species-Species Interactions from Environmental Metatranscriptomics Data
Version: 1.1.0
Version: 1.1.1
Authors@R:
c(person("Amy D", "Willis", email = "adwillis@uw.edu", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2802-4317")),
person("Sarah", "Teichman", role = "aut"),
Expand All @@ -15,9 +15,9 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports:
dplyr,
geepack,
geeasy,
lazyeval,
raoBust (>= 1.1.1),
tibble
tibble,
geeasy,
geepack
Remotes: statdivlab/raoBust
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
export(fit_mgx_model)
import(geeasy)
import(geepack)
import(stats)
importFrom(dplyr,bind_cols)
importFrom(lazyeval,as_call)
importFrom(lazyeval,f_new)
importFrom(raoBust,gee_test)
importFrom(raoBust,glm_test)
importFrom(tibble,tibble)
36 changes: 16 additions & 20 deletions R/fit_mgx_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@
#' Users can override some or all of these.
#' If \code{center = TRUE}, then covariates will be centered before being included in the model.
#'
#' @importFrom tibble tibble
#' @importFrom dplyr bind_cols
#' @importFrom lazyeval f_new as_call
#' @importFrom raoBust glm_test
#' @import stats
#' @import geepack
#' @importFrom raoBust glm_test gee_test
#' @import geeasy
#' @import geepack
#'
#' @examples
#' my_df <- data.frame(xx = rpois(20, lambda = 400),
Expand Down Expand Up @@ -163,7 +159,7 @@ fit_mgx_model <- function(
stop("At least one replicate provided is infinite. Please fix this and then rerun.")
}
}
covs <- all.vars(update(formula, . ~ .))[-1]
covs <- all.vars(stats::update(formula, . ~ .))[-1]
for (i in 1:length(covs)) {
if (any(is.infinite(my_df[[covs[i]]]))) {
stop(paste0("At least one value of covariate ", covs[i], " is infinite. Please fix this and rerun."))
Expand All @@ -178,7 +174,7 @@ fit_mgx_model <- function(
# center covariates if desired
if (control$center) {
# get variable names from the formula
vars <- setdiff(all.vars(update(formula, . ~ .))[-1], "predictor")
vars <- setdiff(all.vars(stats::update(formula, . ~ .))[-1], "predictor")

# copy data so we don't overwrite
data_centered <- my_df
Expand Down Expand Up @@ -222,11 +218,11 @@ fit_mgx_model <- function(
## E[Y]/X = gamma0 * (X^*/X)^beta1 * e^(beta2*salinity + beta3*iron)

if (is.null(replicates)) {
raoBust_out <- raoBust::glm_test(formula = formula,
offset = offset,
family = stats::poisson(link = "log"),
data = my_df,
weights = wts)$coef_tab
raoBust_out <- glm_test(formula = formula,
offset = offset,
family = stats::poisson(link = "log"),
data = my_df,
weights = wts)$coef_tab
} else {
if (!all(my_df[[wts]] == 1L)) {
warning("Run this by Amy; not sure what this is doing off-the-cuff")
Expand All @@ -239,13 +235,13 @@ fit_mgx_model <- function(
id <- "id"
}

raoBust_out <- raoBust::gee_test(formula = formula,
offset = offset,
family = stats::poisson(link="log"),
id = id,
data = my_df,
use_jack_se = use_jack_se,
cluster_corr_coef = cluster_corr_coef)$coef_tab
raoBust_out <- gee_test(formula = formula,
offset = offset,
family = stats::poisson(link="log"),
id = id,
data = my_df,
use_jack_se = use_jack_se,
cluster_corr_coef = cluster_corr_coef)$coef_tab
}


Expand Down
2 changes: 1 addition & 1 deletion man/fit_mgx_model.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-accuracy-correlated.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_that("reasonably accurate estimates with covariates and correlation", {
# yy1 <- rpois(n, lambda=eta)
yy1 <- rnbinom(n, mu=eta, size=eta^2)

my_df <- tibble(yy1, xx1, xstar1, xx_covariates1, xx_covariates2, id)
my_df <- tibble::tibble(yy1, xx1, xstar1, xx_covariates1, xx_covariates2, id)

output10 <- fit_mgx_model(enviro_df = my_df,
yy = "yy1",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-accuracy-uncorrelated.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test_that("reasonably accurate estimates with covariates and correlation", {
# yy1 <- rpois(n, lambda=eta)
yy1 <- rnbinom(n, mu=eta, size=eta^2)

my_df <- tibble(yy1, xx1, predictor = log((xstar1 + 1)/(xx1 + 1)), xx_covariates1, xx_covariates2, id)
my_df <- tibble::tibble(yy1, xx1, predictor = log((xstar1 + 1)/(xx1 + 1)), xx_covariates1, xx_covariates2, id)

output9 <- fit_mgx_model(data.frame(yy = yy1,
xstar = xstar1,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-fit_mgx_model_centering.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_that("with small parameter values, centering does not affect results", {
eta <- xx1 * beta0 * (xstar1/xx1)^beta1 * exp(beta2 * xx_covariates1 + beta3 * xx_covariates2 + b[id])
yy1 <- rnbinom(n, mu=eta, size=eta^2)

my_df <- tibble(yy1, xx1, predictor = log((xstar1 + 1)/(xx1 + 1)), xx_covariates1, xx_covariates2, id)
my_df <- tibble::tibble(yy1, xx1, predictor = log((xstar1 + 1)/(xx1 + 1)), xx_covariates1, xx_covariates2, id)

output3 <- fit_mgx_model(data.frame(yy = yy1,
xstar = xstar1,
Expand Down Expand Up @@ -245,7 +245,7 @@ test_that("reasonably accurate estimates with covariates and correlation", {
# yy1 <- rpois(n, lambda=eta)
yy1 <- rnbinom(n, mu=eta, size=eta^2)

my_df <- tibble(yy1, xx1, xstar1, xx_covariates1, xx_covariates2, id)
my_df <- tibble::tibble(yy1, xx1, xstar1, xx_covariates1, xx_covariates2, id)

output9 <- fit_mgx_model(yy = "yy1",
xstar = "xstar1",
Expand Down
Loading