R/WaldTest.R

Defines functions WaldTest

# Wald statistical test
# fit count data to Negative Binomial Generalized Linear Model
# and obtain the Wald statistics (z value)

# nbdata - simulated read counts from simNB
# formula - design formula for NB GLM model
# Author: Xu Qiao
# Created: 19th, Sep, 2017
# Last Modifed: 28th, Dec, 2017
#' @importFrom MASS glm.nb
WaldTest <- function(nbdata, formula=data ~ group) {
  # fit a NB generalized linear model
  tmp <- suppressWarnings(glm.nb(data=nbdata, formula=formula))
  if (!inherits(tmp,"try-error")) {
    GLMfit <- tmp
    statistics <- summary(GLMfit)$coefficients[2,"z value"]
    return(statistics^2)
  }
  else return(0)
}
xuqiao93/PowerExplorer documentation built on May 16, 2019, 9:13 p.m.