Spatial statistics

Analysis › Measure · version 2 · can run once per region

Whether the localizations are clustered, and at what scale: the pair

What it does

Asks whether the localizations are clustered – closer together than chance would put them – and at what distance. It writes nothing to the table; it draws curves and, per region, gives numbers.

The curves all come from one count: how many pairs of localizations lie at each distance r from each other. Divided by what complete spatial randomness (CSR: every place in the window equally likely, independently of the others) would give in the same window, it is the pair correlation : 1 for random positions, above 1 at the distances where localizations come together, below 1 where they keep apart. Added up from 0 to r it is Ripley's K(r), the mean number of neighbours within r over the density (Ripley 1977); made straight, is 0 for random positions and above 0 for clusters (many papers call it ). g shows each distance on its own, and so which distances matter; L - r adds up all the distances below r, which makes it smoother and is why its maximum is the usual estimate of a cluster's size (Kiskowski et al. 2009). These are the radial approaches: they average every direction into one curve.

Two directional approaches keep the direction, for what is periodic along one – rings of spectrin every 190 nm along an axon, the bands of a sarcomere, layers in z – or shifted between two channels:

With a line ROI – drawn, or one of an ROI's named lines in the ROI manager – x runs along the line and y across it, so a structure is measured in its own directions however it lies.

Tick the approaches to see; each has its own settings, shown while it is on.

Every visible layer is measured as it shows – with its filter, with or without merged blinks – and with two or more, also every pair: the cross-correlation of two channels is the same count with one end of each pair in each, 1 when the two are independent and above 1 at the distances where they meet. This is the pair correlation of Veatch et al. 2012 and PC-PALM (Sengupta et al. 2011), counted without a picture.

Blinking is clustering. One molecule seen ten times is ten localizations within a few tens of nm of each other: g is far above 1 at small r even for molecules placed at random. Either measure a layer that merges blinks, or compare with the keep blinks envelope (below), which blinks the way the data do – and still remember that a molecule that blinks again after a long dark time is two blinks.

Use it on a region with a uniform background – a patch of membrane, a nucleus – or on every ROI or cluster as a per-region step. The radial approaches are lateral (x and y) only; the directional ones can use z.

How it works

1. The window. Where localizations could have been: the region's shape when it runs in an ROI; else the ROI drawn in the view; else, as without an ROI says, the occupied area – the localizations binned in squares of about 200 nm, a square kept when it holds one, the gaps between molecules closed – or their bounding box. The window matters: g compares the data with random positions in the window, and a window larger than the cell (the field of view around a cell, which is what SMAP used) makes any cell look clustered, since all its localizations are in one part of it.

2. The pairs. The distance of every pair of localizations closer than up to r, counted in rings bin width wide. A localization is never paired with itself. Each file is counted on its own.

3. What chance expects. The same number of localizations placed at random in the window would give, in each ring, a number of pairs that depends on the window's shape: near the edge part of every ring is outside it. This expected count is worked out exactly for any window shape (In detail), and g is the count over it.

4. The envelope. The localizations are placed at random in the window again and again – 99 simulations – and the same curves computed each time. The shaded band holds the middle 95 % of them at each r; the dotted lines are the band of the global test, which takes all distances at once: the data leave it somewhere only one time in 20 by chance, so a curve outside it is clustered (or dispersed) with a 5 % error, where a curve that pokes out of the shaded band at one r out of 60 means little. Envelope says how they are placed: random (CSR) puts every row the layer shows anywhere; random, keep blinks moves each blink – the localizations one molecule gave in consecutive frames – as a whole, so the simulations blink like the data and only the arrangement of the molecules is tested. For a cross-correlation the first layer stays where it is and the second is placed at random.

Clusters of radius 60 nm: g (left) is far above 1 up to about twice the radius, L - r (right) peaks at 100 nm, between one and two radii. Both leave the envelope of whole blinks placed at random (shaded: pointwise 95 %; dotted: the global test).

Molecules at random, each seen in a few consecutive frames. Against random localizations (left) the blinks alone make the curve leave the envelope: it looks clustered at 20 nm. Against random blinks (right) it stays inside: the molecules are random.

The directional approaches take the same layers and window, in the frame of a line ROI when there is one (x along it, y across).

1. Binning. The localizations are counted in bins of bin on the axes measured: an image of x and y (or x and z, y and z) for the correlation image, a profile along x, y or z for the line. z runs over the range the data have – from their 0.5th to their 99.5th percentile, clipped to -500 .. 500 nm – so a few far-out mislocalizations do not stretch it.

2. Correlating. For every shift up to shifts up to, the pairs of localizations that far apart (by Fourier transform), divided by what the same number placed at random in the window would give at that shift: 1 for random positions, in every direction.

3. The period. Along a line, the peaks of the correlation at positive shifts: the one nearest the period guess, or without a guess the first that is at least half as high as the highest. The spectrum of the profile gives a second estimate, from its strongest frequency.

Rings every 190 nm across an axon that runs at 35° to x, measured along a line ROI on it. The correlation image (left) shows them as stripes every 190 nm along the axon, the same all across it (beyond 400 nm across, the axon has no width left: no value). Along the line (right): the profile, its correlation with a peak at 190 nm (the peak at 0 is each molecule's own blinks), and the spectrum's peak at 5.3 per µm.

In detail

The estimator. With localizations in a window of area , the count of ordered pairs at distances between and (each pair twice for a layer with itself, a localization never with itself) is divided by its expectation under CSR,

where is the window's set covariance, the area the window shares with itself shifted by . For two layers the numerator is , less the rows the two layers share. So

This is the translation edge correction averaged over directions, and it is what Veatch's normalisation does in Fourier space – the picture's autocorrelation divided by the mask's. is the autocorrelation of the window's mask, by FFT: on a raster of 512 pixels along the longer side for a drawn shape (a rectangle exactly), on the occupied area's own 200 nm squares, padded so no lag up to up to r wraps. The set covariance of a raster is exactly bilinear between whole-pixel lags, so it is read there at 90 directions over half a turn () and averaged. K is summed ring by ring and read at the bin centres; L - r is shown there. Rings beyond the window's size, where nothing can be expected, are NaN. Several files are pooled: their counts and expectations are added, and g is the ratio of the sums.

The window's correction on random points in a disc: divided by what an infinite plane would give (grey), g falls with r because the pairs that would cross the edge are missing; divided by the disc's set covariance (black) it stays at 1.

The pairs come from Neighbourhood's index: the localizations sorted into square cells up to r wide, each one testing the nine cells around it, on every core, the distances binned as they are found and never stored. A million localizations over 40 µm to 500 nm – half a billion pairs – take about 1.6 s on four cores. A run is estimated before it starts (the simulations repeat the count each time), and one expected to take more than 5 s asks first, offering to run without the envelope or with 19 simulations.

The occupied area is the localizations of all the layers binned on a grid from their smallest to their largest x and y, squares of about occupied bin; a square holding a localization is in, and the mask is closed (dilated and eroded twice by one square), so the gaps between molecules are not holes. A uniform rectangle's occupied area is the rectangle.

Simulations. CSR places points uniformly in the window's raster. Keep blinks takes the blinks from group_id (merge blinks once on the layer, so the attribute exists), and puts each blink's centre uniformly in the window, its localizations keeping their offsets from it; a blink that then sticks out of the window is placed again, up to 30 times. A layer that shows merged blinks has one row per blink, and keep blinks is CSR.

The tests. Pointwise: the 2.5th and 97.5th percentiles (at level 0.95) of the simulated curves at each r. Globally, Diggle's maximum absolute deviation (MAD) test on L - r, over r from from r: $T = \max_r

|\hat{L}(r) - r - \bar{L}(r) + r|$, the deviation from the simulations' mean ; each simulation's is taken from the mean of the others, and . The global band is the mean the -th smallest , so the curve leaves it exactly when (Baddeley et al. 2014). With 99 simulations the smallest p is 0.01; with 19, 0.05. The test is on L - r rather than g because its spread is about the same at every r, while g's is largest at small r.

The first maximum of a curve is read off the curve smoothed over 5 bins: the first local maximum at r from from r (the first bin counts when the curve falls from it) that rises at least half as far above the random value (1 for g, 0 for L - r) as the highest one does. So a small bump of noise before the real peak is passed over, and of two equal peaks – rings of a periodic structure – the first is taken.

The directional normalisation. With and the two layers' counts in the bins and the window's weight in each, the correlation at a shift (a vector of whole bins) is

by FFT with enough padding that nothing wraps. It is 17a's estimator not averaged over directions: the window's autocorrelation in place of its set covariance, as in Veatch's normalisation before its radial sum. For an x-y image is the window's mask; for x-z it is the window's width across x at each x, times 1 inside the z range; along x alone, that width; along z alone, the window's area in each z bin. An auto-correlation leaves out each localization's pair with itself ( at ); its numerator is . A shift at which the window overlaps itself in less than a thousandth of its largest overlap is NaN. Files are counted apart, and their numerators and denominators added.

The frame. A drawn line ROI turns x along it (from its first end) and y across (positive to the left), and its rectangle is the window. In an ROI of the ROI manager, its named line ROI line (the first it has when left on that) turns the axes and the ROI's shape is the window; an ROI without lines and a cluster keep the table's x and y. The window is binned at bin in the frame, a bin in when its centre is; without a region or drawn ROI it is the occupied area or the bounding box, as for the radial ones.

The period is read off the correlation at positive shifts: its local maxima beyond 2 bins, each refined by a parabola through it and its two neighbours; with a period guess the nearest, else the first whose height above 1 is at least half the highest's. The spectrum is the one-sided magnitude of the profile's Fourier transform, doubled between 0 and the Nyquist frequency, and its period at the peak chosen the same way (zero frequency and periods under 2 bins left out). A cross-correlation's shift is the position of its highest point, refined the same way.

Parameters

settingdefaultwhat it does
pair correlation g(r)
pair_correlation
onPairs at distance r over what chance gives.

The one to read for a distance: g's peaks are where the localizations come together, and for a periodic structure each period gives one.

Ripley's K(r)
ripley_k
offNeighbours within r over the density.

K grows as for random positions, so its curve says little by eye; it is here for comparison with other software. L - r is the same information, drawn readably.

L(r) - r
ripley_l
onK made linear: 0 for random, above it clustered.

The smooth one, and the usual measure of a cluster's size: for clusters of radius R its maximum lies between R and 2R, depending on how dense the clusters are against the background.

radial approaches
   up to r
   radial.r_max_nm
500 nmThe largest distance; pairs farther apart are not counted.

A few times the size of the structures; the time grows with its square. Beyond about a third of the window's size few pairs fit and the curves are noisy.

at least 1 nm
   bin width
   radial.dr_nm
5 nmThe width of the rings the pairs are counted in.

About the localization precision. Finer bins hold fewer pairs each and the curve is noisier; K and L - r, being sums, are not affected much.

at least 0.1 nm
   cross-correlations
   radial.cross
onAlso every pair of visible layers, not only each layer with itself.

Off, only each layer with itself.

   at distances
   radial.at_nm
–G and L - r at these distances as values, e.g. '95, 190'.

Distances to read g and L - r at, as numbers for the region table – the expected period of a structure, the radius of a cluster – so ROIs or conditions can be compared at one distance.

   without an ROI
   radial.window
the occupied areaThe window when neither a region nor a drawn ROI gives one.

The occupied area for a cell or a tissue, whose edge is the edge of the data; the bounding box for data that fill a rectangle (a simulation, or a field cut to a rectangle). With a region or a drawn ROI, that shape is the window and this is not used.

Choices: the occupied area; the bounding box
   occupied bin (more)
   radial.occupied_bin_nm
200 nmThe pixel of the occupied area's mask.

Large enough that most squares inside the cell hold a localization (a few times the typical distance between neighbours), small enough to follow the outline. Too small and the gaps between molecules count as outside: the window shrinks to the localizations and g drops below 1.

at least 1 nm
   envelope
   radial.null
random (CSR)What the curves are compared with: points placed at random in the window, or whole blinks placed at random.

Random (CSR) on a layer that merges blinks; random, keep blinks on one that does not. None to see the curves fast.

Choices: none; random (CSR); random, keep blinks
   simulations
   radial.simulations
99Random placements for the envelope.

99 gives a test at 1 % and a smooth band; 19 is the fewest for a 5 % test. Each costs as long as the measurement.

at least 1
   level (more)
   radial.level
0.95Of the envelope and the test.

0.95: a 5 % test. 0.99 needs at least 99 simulations.

0.5 to 0.999
   from r (more)
   radial.r_min_nm
0 nmThe maxima and the test look from here on.

Raise it past the blinking (two or three times the precision) to look for the first maximum and test only at the distances above it.

   seed (more)
   radial.seed
0Of the random placements.

The same seed gives the same envelope.

correlation image
image
offThe 2D auto- and cross-correlation, every direction apart.

Needs a few hundred localizations per period in the window to show rows of spots; for a weak structure the line, which adds up a whole direction, sees more.

along a line
line
offThe correlation along one axis, its period and spectrum.

With a line ROI along the structure: rings, bands or a filament's repeat. Along z, a structure stacked in layers.

directional approaches
   image plane
   directional.plane
x-yX along a line ROI, y across it; z from z_nm.

x-z or y-z for 3D data: layers or a tilt show as spots above and below the middle.

Choices: x-y; x-z; y-z
   line along
   directional.axis
xX along a line ROI, y across it; z from z_nm.

x is along a line ROI; y across it, for the width of a stripe pattern.

Choices: x; y; z
   bin
   directional.bin_nm
5 nmThe localizations are counted in bins this wide.

A tenth of the period or less, and not below the precision: finer bins only add noise to each.

at least 0.1 nm
   shifts up to
   directional.max_shift_nm
500 nmThe largest shift correlated.

A few periods; the longer, the more peaks the spectrum resolves, but past half the ROI's length the overlap is thin and the correlation noisy.

at least 1 nm
   period guess
   directional.period_nm
0 nmThe peak nearest it is the period; 0: the first strong one.

The expected period (190 nm for spectrin): the nearest peak is taken, so a guess picks the first harmonic rather than the second. 0 takes the first strong peak.

   cross-correlations
   directional.cross
onAlso every pair of visible layers.

Off for only each layer with itself.

   without an ROI
   directional.window
the occupied areaThe window when neither a region nor a drawn ROI gives one.

As without an ROI of the radial approaches.

Choices: the occupied area; the bounding box
   ROI line
   directional.roi_line
the first it hasIn an ROI of the ROI manager, which of its named lines x runs along.

Draw the line along the structure in each ROI first (the ROI manager's lines); the first it has is used when this is left alone.

Output

Figures: one per approach ticked – each layer's curve in its colour, the cross-correlations dashed in grey, the pointwise band shaded, and for L - r the global band dotted; the legend gives each curve's p. The window figure shows the window and the localizations measured in it (the first file's): check it before trusting a curve.

Text: the window, its area, the number of files, and per curve the first maximum of g and of L - r and the test.

Values per region (a column each in the region table; the first layer with no suffix, then _L2, ..., and _L1xL2 for a pair):

From the directional approaches, per layer: period_nm and period_g (the period from the correlation along the line, and the correlation there), period_fft_nm and period_fft_mag (from the spectrum); per pair shift_nm_L1xL2 and shift_g_L1xL2, where the cross-correlation is highest. The correlation image figure is one image per layer and pair; the along a line figure the profiles, the correlations with each period marked, and the spectra.

Arrays per region: from the line, lag_nm (the shifts) and line_g (per layer and pair, with their suffixes), so Curves averages them over the ROIs. From the radial approaches, r_nm (the bin centres), and per curve pairs and expected (the counts, so a summary over regions can pool them as the sum of the pairs over the sum of the expectations), g, K_nm2, lr_nm, and the bands g_lo, g_hi, lr_nm_lo, lr_nm_hi.

A good result: g near 1 and L - r near 0 at large r, a clear peak inside the window's size, the curve outside the envelope at the distances that matter. A bad one: g drifting away from 1 at large r – the window does not fit the data (the occupied area's squares too small or too large, a drawn ROI reaching past the cell), or the density is not uniform at the scale of the window (a gradient looks clustered at every r).

Differences from SMAP

Based on SMAP's SpatialPointPattern with its helper myRipleysK, and the 2D pair correlation of correlation (paircrosscorrelationfunction) (Ries 2020). The main changes:

References