Skip to content

Commit 8d7b7be

Browse files
committed
added gee.scale.fix argument to testDynamic() and marge2() -- related to #255
1 parent f6c2d5e commit 8d7b7be

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

R/marge2.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#' @param sandwich.var (Optional) Should the sandwich variance estimator be used instead of the model-based estimator? Default to FALSE.
2626
#' @param approx.knot (Optional) Should the set of candidate knots be subsampled in order to speed up computation? This has little effect on the final fit, but can improve computation time somewhat. Defaults to TRUE.
2727
#' @param n.knot.max (Optional) The maximum number of candidate knots to consider. Uses random sampling (don't worry, a random seed is set internally) to select this number of unique values from the reduced set of all candidate knots. Defaults to 50.
28-
#' @param glm.backend (Optional) Character specifying which GLM-fitting backend should be used. Must be one of "MASS" or "speedglm". Defaults to "MASS".
28+
#' @param glm.backend (Optional) Character specifying which GLM-fitting backend should be used. Must be one of "MASS" or "speedglm". Defaults to "MASS".
29+
#' @param gee.scale.fix (Optional) Boolean specifying whether the dispersion should be estimated from the data or held fixed at 1 when fitting in GEE mode. Defaults to FALSE.
2930
#' @param tols_score (Optional) The set tolerance for monitoring the convergence for the difference in score statistics between the parent and candidate model (this is the lack-of-fit criterion used for MARGE). Defaults to 0.00001.
3031
#' @param minspan (Optional) A set minimum span value. Defaults to NULL.
3132
#' @param return.basis (Optional) Whether the basis model matrix should be returned as part of the \code{marge} model object. Defaults to FALSE.
@@ -64,7 +65,8 @@ marge2 <- function(X_pred = NULL,
6465
sandwich.var = FALSE,
6566
approx.knot = TRUE,
6667
n.knot.max = 50,
67-
glm.backend = "MASS",
68+
glm.backend = "MASS",
69+
gee.scale.fix = FALSE,
6870
tols_score = 1e-5,
6971
minspan = NULL,
7072
return.basis = FALSE,
@@ -836,7 +838,7 @@ marge2 <- function(X_pred = NULL,
836838
id = id.vec,
837839
family = MASS::negative.binomial(theta_hat, link = log),
838840
corstr = cor.structure,
839-
scale.fix = FALSE,
841+
scale.fix = gee.scale.fix,
840842
sandwich = sandwich.var)
841843
} else {
842844
if (glm.backend == "MASS") {
@@ -849,12 +851,12 @@ marge2 <- function(X_pred = NULL,
849851
model = FALSE)
850852
final_mod <- stripGLM(glm.obj = final_mod)
851853
} else if (glm.backend == "speedglm") {
852-
final_mod <- speedglm::speedglm(model_formula,
853-
data = model_df,
854-
family = MASS::negative.binomial(theta_hat, link = "log"),
855-
trace = FALSE,
856-
model = FALSE,
857-
y = FALSE,
854+
final_mod <- speedglm::speedglm(model_formula,
855+
data = model_df,
856+
family = MASS::negative.binomial(theta_hat, link = "log"),
857+
trace = FALSE,
858+
model = FALSE,
859+
y = FALSE,
858860
fitted = TRUE)
859861
}
860862
}

R/testDynamic.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#' @param size.factor.offset (Optional) An offset to be included in the final model fit. Can be generated easily with \code{\link{createCellOffset}}. Defaults to NULL.
2525
#' @param is.gee Should a GEE framework be used instead of the default GLM? Defaults to FALSE.
2626
#' @param cor.structure If the GEE framework is used, specifies the desired working correlation structure. Must be one of "ar1", "independence", or "exchangeable". Defaults to "ar1".
27-
#' @param gee.bias.correction.method Specify which small-sample bias correction to be used on the sandwich variance-covariance matrix prior to test statistic estimation. Options are "kc" and "df". Defaults to NULL, indicating the use of the model-based variance.
27+
#' @param gee.bias.correction.method (Optional) Specify which small-sample bias correction to be used on the sandwich variance-covariance matrix prior to test statistic estimation. Options are "kc" and "df". Defaults to NULL, indicating the use of the model-based variance.
28+
#' @param gee.scale.fix (Optional) Boolean specifying whether the dispersion should be estimated from the data or held fixed at 1 when fitting in GEE mode. Defaults to FALSE.
2829
#' @param is.glmm Should a GLMM framework be used instead of the default GLM? Defaults to FALSE.
2930
#' @param id.vec If a GEE or GLMM framework is being used, a vector of subject IDs to use as input to \code{\link[geeM]{geem}} or \code{\link[glmmTMB]{glmmTMB}}. Defaults to NULL.
3031
#' @param glmm.adaptive (Optional) Should the basis functions for the GLMM be chosen adaptively? If not, uses 4 evenly spaced knots. Defaults to TRUE.
@@ -63,6 +64,7 @@ testDynamic <- function(expr.mat = NULL,
6364
is.gee = FALSE,
6465
cor.structure = "ar1",
6566
gee.bias.correction.method = NULL,
67+
gee.scale.fix = FALSE,
6668
is.glmm = FALSE,
6769
glmm.adaptive = TRUE,
6870
id.vec = NULL,
@@ -73,7 +75,7 @@ testDynamic <- function(expr.mat = NULL,
7375
random.seed = 312) {
7476
# check inputs
7577
if (is.null(expr.mat) || is.null(pt)) { stop("You forgot some inputs to testDynamic().") }
76-
78+
7779
# get raw counts from SingleCellExperiment or Seurat object & transpose to cell x gene dense matrix
7880
if (is.null(genes)) {
7981
genes <- rownames(expr.mat)
@@ -144,7 +146,7 @@ testDynamic <- function(expr.mat = NULL,
144146

145147
# build list of objects to prevent from being sent to parallel workers
146148
necessary_vars <- c("expr.mat", "genes", "pt", "n.potential.basis.fns", "approx.knot", "is.glmm", "gee.bias.correction.method",
147-
"verbose", "n_lineages", "id.vec", "cor.structure", "is.gee", "glmm.adaptive", "size.factor.offset")
149+
"verbose", "n_lineages", "id.vec", "cor.structure", "is.gee", "gee.scale.fix", "glmm.adaptive", "size.factor.offset")
148150
if (any(ls(envir = .GlobalEnv) %in% necessary_vars)) {
149151
no_export <- c(ls(envir = .GlobalEnv)[-which(ls(envir = .GlobalEnv) %in% necessary_vars)],
150152
ls()[-which(ls() %in% necessary_vars)])
@@ -186,11 +188,12 @@ testDynamic <- function(expr.mat = NULL,
186188
Y = expr.mat[lineage_cells, i],
187189
Y.offset = size.factor.offset[lineage_cells],
188190
is.gee = is.gee,
191+
gee.scale.fix = gee.scale.fix,
189192
id.vec = id.vec[lineage_cells],
190193
cor.structure = cor.structure,
191194
sandwich.var = ifelse(is.null(gee.bias.correction.method), FALSE, TRUE),
192195
M = n.potential.basis.fns,
193-
approx.knot = approx.knot,
196+
approx.knot = approx.knot,
194197
return.basis = TRUE)
195198
}, silent = TRUE)
196199
} else if (is.glmm) {
@@ -241,7 +244,7 @@ testDynamic <- function(expr.mat = NULL,
241244
data = null_mod_df,
242245
family = MASS::negative.binomial(theta_hat),
243246
corstr = cor.structure,
244-
scale.fix = FALSE,
247+
scale.fix = gee.scale.fix,
245248
sandwich = ifelse(is.null(gee.bias.correction.method), FALSE, TRUE))
246249
}, silent = TRUE)
247250
} else if (is.glmm) {

man/marge2.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/testDynamic.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)