mbglm: Fitting Bayesian GLMs for Many Responses

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/mbglm.R

Description

mbglm fits Bayesian GLMs separately for many responses, and summary.mbglm summarizes the fitted models.

Usage

1
2
3
4
5
  
mbglm(y, formula, data, family=NegBin(), prior=Student(0,1),
      min.p=0, verbose=TRUE)
      
summary.mbglm(object)

Arguments

y

a matrix of responses; each column is a response and rows are samples.

formula

a one-sided formula of the form ~ x (i.e., the respose is omitted); the right side of ~ is the same as in bglm.

data, family, prior, verbose

These arguments are the same as in bglm.

min.p

a value in [0, 1). The responses with the proportion of non-zero values > min.p are analyzed.

object

an object from mbglm.

Details

This function analyzes the responses in y by repeated calls to bglm.

Value

The function mbglm returns a list including fit, responses, variables, and call:

fit

fitted models for all the responses;

responses

names of all the responses;

variables

names of all covariates;

The function summary.mbglm returns a data frame consisting of responses, variables, estimates, standard deviations, p-vlaues and adjusted p-vlaues (using FDR method) for all coefficients.

Author(s)

Nengjun Yi, nyi@uab.edu

See Also

bglm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library(BhGLM)
library(NBZIMM)

# load data in NBZIMM
data(Romero)
names(Romero)

otu = Romero$OTU; dim(otu)
sam = Romero$SampleData; dim(sam)
colnames(sam)

Days = sam$GA_Days; Days = scale(Days)
Age = sam$Age; Age = scale(Age)
Race = sam$Race
preg = sam$pregnant; table(preg)

# calculate size factor using the cumulative sum scaling (CSS) method in metagenomeSeq
library(metagenomeSeq)
obj = newMRexperiment(counts=t(otu), phenoData=NULL, featureData=NULL,
                      libSize=NULL, normFactors=NULL)
obj = cumNorm(obj, p=cumNormStat(obj)) #set p=1: generate total reads
s = normFactors(obj)
s = unlist(s)

# analyze taxa with nonzero proportion > min.p
f = mbglm(y=otu, formula=~ Days + Age + Race + preg + offset(log(s)), 
          family=NegBin(), prior=Student(0, 1), min.p=0.1)

out = summary.mbglm(f)
out = out[out[,2]=="preg", ]
coefs = out[,3]; names(coefs) = out[,1]
sds = out[,4]
padj = out[,6]
plot.bh(coefs=coefs, sds=sds, pvalues=padj, threshold=0.001, gap=1000)

out = summary.mbglm(f)
df = out[,c(1:4, 6)]; colnames(df)[5] = "pvalue" 
g = NBZIMM::heat.p(df=df, p.breaks = c(0.001, 0.01, 0.05), 
           colors = c("black", "darkgrey", "grey", "lightgrey"),
           zigzag=c(T,F), abbrv=c(T,F), margin=c(2.5,0.5), y.size=8,
           legend=T)

nyiuab/BhGLM documentation built on Jan. 9, 2022, 3:31 p.m.