Skip to content

Compensation

Every fluorophore leaks signal into detectors that belong to other fluorophores. The amount of leakage is the spillover, and it is a property of the instrument and the panel, not of the sample. Compensation subtracts the leaked signal so that a fluorescent signal on one detector reflects only the fluorophore bound to that detector’s antibody.

Spillover is linear. If fluorophore A spills 10 percent of its signal into detector B, then the correction is a matrix multiplication on the raw intensities. Logicle and arcsinh transforms are nonlinear, and a linear correction applied after a nonlinear transform is no longer the correct correction. The order is fixed: compensate on the linear scale, then transform.

A log amplifier is a nonlinear transform too. The fluorescence detectors of the FACSCalibur that wrote these files sit behind one, and the FCS I/O page prints the keyword that records it. read.FCS undoes the amplifier by default, so this page reads the files without transformation = FALSE and every value it compensates is a linear intensity.

The spillover matrix is a square matrix with one row per fluorophore and one column per detector, and each fluorophore’s own detector sits on the diagonal. The diagonal is 1, and each off-diagonal entry is the fraction of that fluorophore’s signal that appears in another detector. By convention each row is named after the detector its fluorophore is read in, so the matrix printed below carries detector names on both sides.

A digital instrument stores raw values. Its software computes the matrix from single-stain control tubes and writes it into the FCS file beside them, under $SPILLOVER in the FCS 3.1 standard or under the older SPILL keyword. The FACSCalibur that wrote these files is an analog instrument, and it worked the other way. When the operator set compensation, its electronics subtracted the spillover from the linear signal before the log amplifier, and the file kept only the result. The files follow FCS 2.0, which has no keyword for a spillover matrix.

The FACSCalibur example files and compdata compensation matrix come from the flowCore 2.24.0 source archive. Its Artistic 2.0 license covers the distributed file collection. The fixture source notice identifies the package authors, original files, and derived lesson results. The complete license accompanies that notice.

library(flowCore)
extdata_dir <- system.file("extdata", package = "flowCore")
fcs_files <- list.files(extdata_dir, pattern = "0877408774", full.names = TRUE)
# The default read undoes the log amplifier on the fluorescence detectors.
frames <- lapply(fcs_files, read.FCS)
#' Return the spillover matrix a flowFrame stores, if it stores one.
#'
#' `spillover()` looks for the `SPILL`, `spillover` and `$SPILLOVER` keywords.
#' It returns one list element per keyword, NULL where the keyword is absent,
#' and it stops with an error when all three are absent.
#'
#' @param frame A `flowFrame`.
#' @return The first stored matrix, or NULL when the file stores none.
StoredSpill <- function(frame) {
spill_keys <- c("SPILL", "spillover", "$SPILLOVER")
if (!any(spill_keys %in% names(keyword(frame)))) {
return(NULL)
}
Filter(Negate(is.null), spillover(frame))[[1]]
}
stored <- lapply(frames, StoredSpill)
has_spill <- !vapply(stored, is.null, logical(1))
has_spill
if (any(has_spill)) {
# Compensate the first file that stores a matrix, with its own matrix.
first <- which(has_spill)[1]
frame <- frames[[first]]
spill <- stored[[first]]
} else {
# FCS 2.0 has no spillover keyword. Load the matrix in flowCore's compdata
# folder, computed from the single-stain controls of a later FACSCalibur run.
frame <- frames[[1]]
comp_path <- file.path(extdata_dir, "compdata", "compmatrix")
lines <- readLines(comp_path)
lines <- lines[nzchar(lines)]
chan <- strsplit(lines[3], "\t")[[1]]
spill <- do.call(rbind, lapply(lines[4:length(lines)], function(l) {
as.numeric(strsplit(l, "\t")[[1]])
}))
colnames(spill) <- chan
rownames(spill) <- chan
}
spill
[1] FALSE FALSE FALSE
FL1-H FL2-H FL3-H FL4-H
FL1-H 1.000000 0.240000 0.03200 0.00113
FL2-H 0.007770 1.000000 0.14000 0.00274
FL3-H 0.008690 0.170000 1.00000 0.21000
FL4-H 0.000795 0.000995 0.00323 1.00000

None of the three files carries a stored matrix, so the example loads the one in flowCore’s compdata folder. That matrix was computed from the single-stain controls of a later FACSCalibur experiment, and its detectors match these files. The files do not record their dyes, so nothing ties the matrix to this panel. With a digital instrument you read the matrix from the keyword, where the instrument wrote it, or compute it from your own single-stain controls with the spillover() method that flowStats adds for a flowSet. The controls page computes one on a deposited panel.

Compensation is a matrix multiplication. flowCore provides the compensate() generic, which works on a flowFrame or a flowSet and uses the spillover matrix to correct every event.

# Compensate the frame using the matrix above.
compensated <- compensate(frame, spill)
# The first rows before and after correction.
head(exprs(frame)[, colnames(spill)], 3)
head(exprs(compensated)[, colnames(spill)], 3)
FL1-H FL2-H FL3-H FL4-H
[1,] 259.455272 1.00000 7.566695 13.09747
[2,] 9.057978 48.26071 10.273508 28.13318
[3,] 537.611747 56.23413 6.915821 310.59002
FL1-H FL2-H FL3-H FL4-H
[1,] 259.864266 -62.73831 7.997916 11.29617
[2,] 8.651649 45.55699 3.530636 27.25714
[3,] 537.941555 -72.99687 -1.081369 310.40925

Every channel is corrected, and FL2-H moves most. The first event drops from 1.00 to -62.74 on FL2-H and the third from 56.23 to -73.00, because both are bright on FL1-H and this matrix subtracts about 0.24 of the FL1-H signal from FL2-H. FL1-H itself barely changes, from 259.46 to 259.86 on the first event, because the other detectors spill very little into it.

The numbers above show the correction on three events. The figure shows it on all ten thousand, which is where you can judge whether the matrix did the right thing.

library(ggplot2)
dir.create("outputs", showWarnings = FALSE, recursive = TRUE)
#' Put two channels of a frame into a plain data frame for plotting.
#'
#' @param frame A `flowFrame`.
#' @param state A label for the compensation state, used as a facet title.
#' @return A data frame with the two channel columns and the state label.
ChannelPair <- function(frame, state) {
values <- as.data.frame(exprs(frame)[, c("FL1-H", "FL2-H")])
names(values) <- c("fl1", "fl2")
values$state <- state
values
}
pair <- rbind(
ChannelPair(frame, "as stored"),
ChannelPair(compensated, "compensated")
)
pair$state <- factor(pair$state,
levels = c("as stored", "compensated"))
# The values stay linear. The axes are pseudo-log, logarithmic far from zero
# and linear near it, so the negative values compensation makes stay visible.
display_axis <- scales::transform_pseudo_log(sigma = 1, base = 10)
axis_breaks <- c(-1000, -100, -10, 0, 10, 100, 1000, 10000)
comp_plot <- ggplot(pair, aes(x = fl1, y = fl2)) +
geom_hex(bins = 70) +
facet_wrap(~state) +
scale_x_continuous(transform = display_axis, breaks = axis_breaks) +
scale_y_continuous(transform = display_axis, breaks = axis_breaks) +
labs(title = "FL1-H against FL2-H", x = "FL1-H", y = "FL2-H")
ggsave("outputs/cyto-compensation.png", plot = comp_plot,
width = 8, height = 4, dpi = 110, bg = "white")

FL1-H against FL2-H on pseudo-log axes, as stored and compensated. As stored, two populations sit side by side, an FL1 dim one near 10 and an FL1 bright one near 250 on the FL1 axis, both centred near 20 on FL2, above a flat floor of events at 1 on FL2. Compensated, the FL1 dim population stays where it was, while the densest part of the FL1 bright population drops below zero, to between -10 and -100 on FL2.

The left panel holds the values the file stores, and it shows no FL1 spillover to remove. A dye read on FL1 leaks into FL2 on this instrument, and the controls the matrix came from put the leak at about 0.24 of the FL1 signal, so on raw values the FL1 bright population would sit well above the dim one on FL2. It sits at the same height. The compensated panel leaves the dim population in place and pulls most of the bright one below zero, under the cells that carry no FL1 signal at all. That is over-compensation, the pattern the panel design page describes.

# Split the events between the two FL1-H peaks, then compare the FL2-H
# median of the FL1 dim and FL1 bright events before and after.
fl1_bright <- exprs(frame)[, "FL1-H"] > 50
fl2_medians <- data.frame(
as_stored = tapply(exprs(frame)[, "FL2-H"], fl1_bright, median),
compensated = tapply(exprs(compensated)[, "FL2-H"], fl1_bright, median)
)
rownames(fl2_medians) <- c("FL1 dim", "FL1 bright")
round(fl2_medians, 1)
as_stored compensated
FL1 dim 23.7 21.3
FL1 bright 20.7 -32.2

The split at 50 on FL1-H falls in the gap between the two populations in the figure. As stored, the FL1 bright events sit at 20.7 on FL2-H and the dim ones at 23.7, so the stored values carry no measurable FL1 signal on FL2. Correct compensation leaves the two medians level, and they are level before this matrix touches them. The matrix leaves the dim events at 21.3 and drives the bright ones to -32.2.

The most likely reason is that the instrument had compensated these files already, at acquisition. The FACSCalibur subtracts spillover in its electronics when the operator sets compensation, so level medians on the stored values are what hardware compensation leaves behind. The evidence is indirect, because the files carry no standard keyword that records what the electronics subtracted. If that is what happened, the matrix removes the same spillover a second time. Before you compensate a file from an analog instrument, check the stored values the way this table does. A bright population that sits level with the dim one on a detector its dye is known to spill into was most likely compensated before the file was written.

A compensated signal carries a spread, not a fixed offset, because the spillover is subtracted from a noisy count. A 10 percent spillover from a bright fluorophore into a dim one can add more variance to the dim channel than its own signal carries. This is the spreading error, and it is why panel design matters: a dim marker read in a detector that takes heavy spillover from a bright, co-expressed marker can disappear into that spread. The transformation and QC page picks up from the compensated object.

The flowCore package by Ellis and colleagues supplies the basic data structures for flow cytometry in R.

The FCS 3.1 standard paper explains compensation keywords across file versions. The flowCore documentation describes compensation objects and matrix application. The compensation sections of the 2019 flow cytometry guidelines explain the controls needed to assess a matrix before interpreting corrected populations.