Count cells within a radius for a single field.
Count the number of from cells having a to cell within radius microns in tissue category category. Compute the average number of to cells within radius of from cells.
A data frame with Cell X Position, Cell Y Position and Phenotype columns, such as the result of calling read_cell_seg_data.
Selection criteria for the rows and columns. Accepts all formats accepted by select_rows.
The radius or radii to search within.
Optional tissue category to restrict both from and to.
Optional distance matrix corresponding to csd, produced by calling distance_matrix.
The value of radius for this row.
The number of from cells found in csd.
The number of to cells found in csd.
The number of from cells with a to cell within radius.
The average number of to cells found within radius microns of each from cell.
For each from cell, count the number of to cells within radius microns. Report the number of from cells containing at least one to cell within radius as from_with. Report the average number of to cells per from cell as within_mean.
count_within counts cells within a single field. It will give an error if run on a merged cell seg data file. To count cells in a merged file, use group_by and do to call count_within for each sample in the merged file. See the Examples.
There are some subtleties to the count calculation.
It is not symmetric in from and to. For example the number of tumor cells with a macrophage within 25 microns is not the same as the number of macrophages with a tumor cell within 25 microns.
from_count*within_mean is not the number of to cells within radius of a from cell, it may count to cells multiple times.
Surprisingly, from_count*within_mean is symmetric in from and to. The double-counting works out.
To aggregate within_mean across multiple samples (e.g. by Slide ID) see the examples below.
If category is specified, all reported values are for cells within the given tissue category. If category is NA, values are reported for the entire data set.
radius may be a vector with multiple values.
Developed by Kent S Johnson.
Site built with pkgdown 1.3.0.
