% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/de_util.R
\name{diff_expr_fit}
\alias{diff_expr_fit}
\title{Function to compute linear model fit and optionally apply 'voom' beforehand}
\usage{
diff_expr_fit(
  counts,
  d,
  design,
  do.voom = TRUE,
  voom.fun = edgeR::voomLmFit,
  norm.method = c("quantile", "tmm"),
  use_weights = FALSE,
  quasi.likelihood = TRUE,
  bayes.trend = FALSE,
  bayes.robust = FALSE,
  pairs = NULL,
  pairs_col = NULL,
  block = FALSE,
  contrasts = NULL,
  disp = "tagwise.dispersion"
)
}
\arguments{
\item{counts}{Count matrix.}

\item{d}{Passed to \code{voom.fun}: a numeric matrix containing raw counts, or an ExpressionSet containing raw counts,
or a DGEList object.}

\item{design}{Numeric design matrix.}

\item{do.voom}{Logical; should data be "voomed"?}

\item{voom.fun}{Voom function: one of "voom", "voomWithQualityWeights" or voomLmFit.}

\item{norm.method}{Character; one of "quantile", "tmm".}

\item{use_weights}{\code{logical}. Should sample-specific quality weights be estimated?}

\item{quasi.likelihood}{Logical; should quasi-likelihood methods be used? See \emph{Details} section.
If \code{TRUE}, the default, then the quasi-likelihood methods are used, if \code{FALSE}, then the
likelihood ratio test is used. Please note the main wrapper function \code{diffExpr()} will set this parameter.}

\item{bayes.trend}{Logical passed to \code{eBayes()}: should an intensity-dependent trend be allowed for the prior variance?
If FALSE then the prior variance is constant.
Alternatively, trend can be a row-wise numeric vector, which will be used as the covariate for the prior variance.}

\item{bayes.robust}{Logical passed to \code{eBayes()}: should the estimation of df.prior and var.prior be robustified
against outlier sample variances?}

\item{pairs}{Factor of identifiers specifying paired samples for paired or other block designs, or batch effects.}

\item{pairs_col}{\code{character}. Name of the column in 'samp.info' containing paired sample information.}

\item{block}{\code{logical}. Are the comparisons to be made within AND between subjects? See Details section.}

\item{contrasts}{Contrast matrix as generated by \code{makeContrasts()}. If \code{NULL}, the default, the design matrix
is expected to describe simple pair-wise comparisons, i.e., with the contrasts already included in the matrix.
Consequently, in that case, no contrasts will be fitted.}

\item{disp}{Character; one of "tagwise.dispersion", "trended.dispersion", "bin.dispersion"}
}
\value{
A named \code{list}. If \code{do.voom=TRUE} the elements are \code{v} (the \code{EList} of
  voom-transformed counts), \code{fit} (the \code{MArrayLM} linear model fit) and \code{fit2} (the
  \code{MArrayLM} fit after \code{eBayes()}, with contrasts applied if these were supplied). Otherwise
  they are \code{d} (the input \code{DGEList}), \code{d2} (the \code{DGEList} with estimated
  dispersions) and \code{fit} (the \code{DGEGLM} generalised linear model fit).
}
\description{
Function to compute linear model fit and optionally apply 'voom' beforehand
}
\details{
For experimental designs involving comparisons within as well as between subjects inter-subject needs to be computed.
    In this case, the column specified in the 'pairs' argument must assign the subjects to the treatment/tissue/etc groups.
    For example, if we have two treatments the effects of which are to be observed in each two tissues, this design would apply.
    The 'pairs' factor is passed to the functions \code{duplicateCorrelation()} and \code{lmFit()}.
    Quasi-likelihood pipeline:
    While the likelihood ratio test is a more obvious choice for inferences with GLMs, the QL
    F-test is preferred as it reflects the uncertainty in estimating the dispersion for each gene. It
    provides more robust and reliable error rate control when the number of replicates is small.
    The QL dispersion estimation and hypothesis testing is done by using the functions
    glmQLFit() and glmQLFTest().
}
\examples{
si <- diff_expr_get_samp_info(diffwrap_samp_info, "SampleName", "Group")
counts <- diff_expr_filter_counts(diff_expr_read_counts(diffwrap_counts, si), si)
groups <- stats::relevel(si$Groups, ref = "control")
d <- edgeR::calcNormFactors(edgeR::DGEList(counts, group = groups))
design <- diff_expr_make_design(si, groups)
fit <- diff_expr_fit(counts, d, design, do.voom = FALSE, quasi.likelihood = TRUE)
class(fit$fit)
}
