| normalizeQuantile.list {aroma.light} | R Documentation |
Normalizes the empirical distribution of a set of samples to a target distribution. The samples may differ in size.
## S3 method for class 'list': normalizeQuantile(X, xTarget=NULL, ...)
X |
a list with numeric vectors. The vectors may be of
different lengths. |
xTarget |
The target empirical distribution. If NULL, the target
distribution is calculated as the average empirical distribution of
the samples. |
... |
Passed to normalizeQuantile.numeric(). |
Returns a list of normalized numeric vector of the same lengths as the
corresponding ones in the input matrix.
Missing values are excluded.
Values that are NA remain NA after normalization.
No new NAs are introduced.
Adopted from Gordon Smyth (http://www.statsci.org/) in 2002 & 2006. Original code by Ben Bolstad at Statistics Department, University of California.
The target empirical distribution is calculated as the average
using *averageQuantile().
Each vector is normalized toward this target disribution using
*normalizeQuantile.numeric().
# Simulate ten samples of different lengths
N <- 10000
X <- list()
for (kk in 1:8) {
rfcn <- list(rnorm, rgamma)[[sample(2, size=1)]]
size <- runif(1, min=0.3, max=1)
a <- rgamma(1, shape=20, rate=10)
b <- rgamma(1, shape=10, rate=10)
values <- rfcn(size*N, a, b)
# "Censor" values
values[values < 0 | values > 8] <- NA
X[[kk]] <- values
}
# Add 20% missing values
X <- lapply(X, FUN=function(x) {
x[sample(length(x), size=0.20*length(x))] <- NA;
x
})
# Normalize quantiles
Xn <- normalizeQuantile(X)
# Plot the data
layout(matrix(1:2, ncol=1))
xlim <- range(X, na.rm=TRUE);
plotDensity(X, lwd=2, xlim=xlim, main="The original distributions")
plotDensity(Xn, lwd=2, xlim=xlim, main="The normalized distributions")