matrix_glmNB: Fit Negative Binomial Generalized Linear Models on a matrix...

View source: R/matrix_glmNB.r

matrix_glmNBR Documentation

Fit Negative Binomial Generalized Linear Models on a matrix of observations

Description

Takes a matrix of observations, and fits the specified Negative Binomial GLM on each species, returning the matrix of coefficients.

Usage

matrix_glmNB(x, ...)

## Default S3 method:
matrix_glmNB(
  x = NULL,
  Map = NULL,
  formula = NULL,
  response.name = "Count",
  verbose = FALSE,
  ...
)

## S3 method for class 'Dataset'
matrix_glmNB(x, formula = NULL, response.name = "Count", verbose = FALSE, ...)

Arguments

x

Either a matrix of abundances with samples as columns and species as rows or a Dataset object

...

Other parameters for the glm.nb function like control.

Map

A data.frame containing the variables to be modelled as columns and samples as rows. The rows should be named with sample IDs and must correspond to the column names from x if an abundance matrix was passed

formula

A formula specifying the model to be fit. Only the right hand side of the equation must be passed, and anything on the left side wild be silently ignored

response.name

String indicating the name to be used for the response (dependent) variable in the GLM

verbose

Logical value. If true the taza name is printed while the fit is in progress.

Details

This function will take each species (row) in the abundance matrix and fit the specified (via the formula option) Negative binomial GLM independently on each one, using the glm.nb function from then MASS package.

Value

Returns a matrix.glm object which is a list containing the following elements:

coefficients

A matrix of coefficients for the glm fit. The matix has dimensions S x p, where S is the number of species in the abundance matrix, and p the number of parameters in the specified GLM. Each row corresponds to an independent fit of the model with glm() function and the specified formula

SE

Similar to Coef, but this matrix contains the estimated Standard Errors (ie. the Standard deviation of the coefficients).

AIC

A named vector containing the Akaike Information Criteria (AIC) of each independent fit. The names of the vector correspond to the species IDs in the input abundance matrix

theta

A vector of theta (ie. the overdispersion parameter) for each taxon

SE.theta

A vector of standard errorrs for the overdispersion parameter.

call

Function call via match.call

family

GLM model family. An object of class family

X

Design matrix of the model fit.

Author(s)

Sur Herrera Paredes

See Also

matrix_glm

Examples

data(Rhizo)
data(Rhizo.map)
data(Rhizo.tax)
Dat <- create_dataset(Rhizo,Rhizo.map,Rhizo.tax)

m1.nb <- matrix_glmNB(x=Dat$Tab,Map=Dat$Map,
                      formula=~accession + plate)
m1.nb <- matrix_glmNB(Dat,formula=~accession + plate,
                      control=glm.control(epsilon=1e-5,maxit=25),
                      verbose=TRUE)

surh/AMOR documentation built on Feb. 21, 2023, 6:31 a.m.