octopus.glm.nb: Fit a Negative Binomial Generalized Linear Model

Description Usage Arguments Value Examples

Description

Fit glm.nb , add anova to result, add lsm to result.

Before fitting, data and factors will be merged by row.names, mismatching rows will be removed.

If formula start with ~, will fit model with each data column of data as respond y.

Usage

1
octopus.glm.nb(formula, data, factors, specs4lsmeans = NULL)

Arguments

formula

formula

data

normalized reads, expecting gene as column, sample as row

factors

factors, expecting factor name as column, sample as row

specs4lsmeans

specs for lsmeans

Value

model if formula has respond y; flattened anova table, lsm table and se table if formula starts with ~.

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
42
{
    data(sample_keys) # facotrs
    for(cur_col in colnames(sample_keys)){ sample_keys[,cur_col] <- as.factor(sample_keys[,cur_col]) }

    data(sample_reads) # reads
    # reads normalization
    norm.reads <- octopus.normalize(sample_reads)

    print(row.names(sample_keys))
    print(row.names(norm.reads))
    # transpose it to meet input requirements of founction octopus.glm.nb()
    norm.reads <- data.frame(t(norm.reads))
    print(row.names(norm.reads))

    # fit model with first gene column, column name is Bcin01g00040.1
    result <- octopus.glm.nb(Bcin01g00040.1 ~ Experiment + Experiment/GrowingFlat + Experiment/GrowingFlat/AgarFlat + Isolate + HostGenotype + HostGenotype*Isolate
                             ,norm.reads
                             ,sample_keys)
    print(result$anova)

    # calculate LSMean
    result$lsmeans <- lsmeans(result,~ Isolate | HostGenotype)
    summary(result$lsmeans)

    # fit model and pull LSMean in one call
    result <- octopus.glm.nb(Bcin01g00040.1 ~ Experiment + Experiment/GrowingFlat + Experiment/GrowingFlat/AgarFlat + Isolate + HostGenotype + HostGenotype*Isolate
                             ,norm.reads
                             ,sample_keys
                             ,specs4lsmeans = ~ Isolate | HostGenotype)
    print(result$anova)
    summary(result$lsmeans)

    # iterate through all data
    result <- octopus.glm.nb( ~ Experiment + Experiment/GrowingFlat + Experiment/GrowingFlat/AgarFlat + Isolate + HostGenotype + HostGenotype*Isolate
                              ,norm.reads
                              ,sample_keys
                              ,specs4lsmeans = ~ Isolate | HostGenotype)
    print(result$anova)
    print(result$lsm)
    print(result$se)

  }

WeiZhang317/octopus documentation built on May 20, 2019, 4:26 p.m.