Builds the model matrices for testing for differential expression by comparing a model with a grouping factor versus one without it. It adjusts for the confounders specified and the median coverage of each sample. The resulting models can be used in calculateStats.
makeModels(sampleDepths, testvars, adjustvars = NULL, testIntercept = FALSE)
Per sample library size adjustments calculated with sampleDepth.
A vector or matrix specifying the variables to test. For
example, a factor with the group memberships when testing for differences
across groups. It's length should match the number of columns used from
coverageInfo$coverage
.
Optional matrix of adjustment variables (e.g. measured confounders, output from SVA, etc.) to use in fitting linear models to each nucleotide. These variables have to be specified by sample and the number of rows must match the number of columns used. It will also work if it is a vector of the correct length.
If TRUE
then testvars
is ignored and mod0
will contain the column medians and any adjusting variables specified, but
no intercept.
A list with two components.
The alternative model matrix.
The null model matrix.
## Collapse the coverage information
collapsedFull <- collapseFullCoverage(list(genomeData$coverage),
verbose = TRUE
)
#> 2023-05-07 06:01:26.599598 collapseFullCoverage: Sorting fullCov
#> 2023-05-07 06:01:26.602183 collapseFullCoverage: Collapsing chromosomes information by sample
## Calculate library size adjustments
sampleDepths <- sampleDepth(collapsedFull,
probs = c(0.5), nonzero = TRUE,
verbose = TRUE
)
#> 2023-05-07 06:01:26.604328 sampleDepth: Calculating sample quantiles
#> 2023-05-07 06:01:26.610114 sampleDepth: Calculating sample adjustments
## Build the models
group <- genomeInfo$pop
adjustvars <- data.frame(genomeInfo$gender)
models <- makeModels(sampleDepths, testvars = group, adjustvars = adjustvars)
names(models)
#> [1] "mod" "mod0"
models
#> $mod
#> (Intercept) testvarsYRI sampleDepths adjustVar1male
#> 1 1 0 8.366322 0
#> 2 1 0 7.954196 0
#> 3 1 0 9.379378 1
#> 4 1 0 8.596190 0
#> 5 1 0 8.523562 0
#> 6 1 0 8.179909 0
#> 7 1 0 6.129283 1
#> 8 1 0 8.233620 0
#> 9 1 0 7.266787 0
#> 10 1 0 8.400879 0
#> 11 1 0 8.044394 0
#> 12 1 0 6.727920 1
#> 13 1 0 7.366322 0
#> 14 1 0 9.134426 0
#> 15 1 0 8.044394 0
#> 16 1 0 8.262095 0
#> 17 1 0 8.991522 0
#> 18 1 0 7.000000 0
#> 19 1 0 6.727920 1
#> 20 1 0 7.285402 0
#> 21 1 0 9.214319 1
#> 22 1 1 6.066089 0
#> 23 1 1 6.285402 0
#> 24 1 1 5.000000 0
#> 25 1 1 5.000000 0
#> 26 1 1 5.000000 0
#> 27 1 1 6.285402 0
#> 28 1 1 5.000000 0
#> 29 1 1 5.000000 0
#> 30 1 1 5.000000 0
#> 31 1 1 5.000000 0
#> attr(,"assign")
#> [1] 0 1 2 3
#> attr(,"contrasts")
#> attr(,"contrasts")$testvars
#> [1] "contr.treatment"
#>
#> attr(,"contrasts")$adjustVar1
#> [1] "contr.treatment"
#>
#>
#> $mod0
#> (Intercept) sampleDepths adjustVar1male
#> 1 1 8.366322 0
#> 2 1 7.954196 0
#> 3 1 9.379378 1
#> 4 1 8.596190 0
#> 5 1 8.523562 0
#> 6 1 8.179909 0
#> 7 1 6.129283 1
#> 8 1 8.233620 0
#> 9 1 7.266787 0
#> 10 1 8.400879 0
#> 11 1 8.044394 0
#> 12 1 6.727920 1
#> 13 1 7.366322 0
#> 14 1 9.134426 0
#> 15 1 8.044394 0
#> 16 1 8.262095 0
#> 17 1 8.991522 0
#> 18 1 7.000000 0
#> 19 1 6.727920 1
#> 20 1 7.285402 0
#> 21 1 9.214319 1
#> 22 1 6.066089 0
#> 23 1 6.285402 0
#> 24 1 5.000000 0
#> 25 1 5.000000 0
#> 26 1 5.000000 0
#> 27 1 6.285402 0
#> 28 1 5.000000 0
#> 29 1 5.000000 0
#> 30 1 5.000000 0
#> 31 1 5.000000 0
#> attr(,"assign")
#> [1] 0 1 2
#> attr(,"contrasts")
#> attr(,"contrasts")$adjustVar1
#> [1] "contr.treatment"
#>
#>