% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calculateNormFactors.R
\name{nfLogMedian,matrix-method}
\alias{nfLogMedian,matrix-method}
\alias{nfLogMedian}
\alias{nfLogMedian,SummarizedExperiment-method}
\alias{nfLogMedian,QFeatures-method}
\title{Methods to computes sample-specific normalization factors on the log scale
using conventional median summarisation.}
\usage{
\S4method{nfLogMedian}{matrix}(object, na.rm = TRUE)

\S4method{nfLogMedian}{SummarizedExperiment}(object, i, na.rm = TRUE)

\S4method{nfLogMedian}{QFeatures}(object, i, na.rm = TRUE)
}
\arguments{
\item{object}{\code{matrix}, \code{SummarizedExperiment} or
\code{QFeatures} object.}

\item{na.rm}{Logical; indicates if missing values are to be removed.
Default is \code{TRUE} as missing values typically occur in proteomics data.}

\item{i}{An integer or character specifying which assay to use,
only needed when object is \code{SummarizedExperiment} or \code{QFeatures}}
}
\value{
A numeric vector of log2-scale normalization factors,
one per sample (column).
}
\description{
Methods to computes sample-specific normalization factors on the log scale
using conventional median summarisation.
}
\details{
Implementation assumes that the assay values are already on the log scale.
The normalization factors are computed on the log scale.
}
\examples{
# Load example data
# The data are a Feature object with containing
# a SummarizedExperiment named "peptide" with MaxQuant peptide intensities
# The data are a subset of spike-in the human-ecoli study
# The variable condition in the colData of the Feature object
# contains information on the spike in condition a-e (from low to high)
data(pe)

###############################
### Example on QFeatures object
###############################

data(pe)

# Calculate log2 norm factor
nf_log <- nfLogMedian(pe, i="peptide")
nf_log

# Normalise peptide level data
pe <- sweep(pe, 
    MARGIN = 2, 
    STATS = nf_log, 
    i = "peptide", 
    name = "peptide_norm")
    
# Evaluate normalisation
par(mfrow=c(1,2))
boxplot(assay(pe,"peptide"))
boxplot(assay(pe,"peptide_norm"))

###############################
### Example on SummarizedExperiment object
###############################

data(pe)

# Extract a summarised experiment from QFeatures object pe
se <- getWithColData(pe, i="peptide")

# Calculate log2 norm factor
nf_log <- nfLogMedian(se, i=1)
nf_log

# Normalise peptide level data and store it as a new assay in
# the SummarizedExperiment object
assays(se)[["peptide_norm"]] <- sweep(assay(se), 
    MARGIN = 2, 
    STATS = nf_log) 
    
# Also give first assay a name     
assayNames(se)[1] <- "peptide"

# Evaluate normalisation
par(mfrow=c(1,2))
boxplot(assay(se,"peptide"))
boxplot(assay(se,"peptide_norm"))

###############################
### Example on matrix object
###############################

data(pe)

# Extract log2 transformed intensity  matrix from QFeatures object pe
mat <- assay(pe,"peptide")

# Calculate Norm factors
nf <- nfLogMedian(mat)
nf

# Normalise peptide level data
matnorm <- sweep(mat, 
    MARGIN = 2, 
    STATS = nf_log) 
# Evaluate normalisation
par(mfrow=c(1,2))
boxplot(mat)
boxplot(matnorm)

}
