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)
}

Try the PowerExplorer package in your browser

Any scripts or data that you put into this service are public.

PowerExplorer documentation built on April 28, 2020, 9:03 p.m.