ripleys_k: Calculate Ripley's K

View source: R/ripleys_k.R

ripleys_kR Documentation

Calculate Ripley's K

Description

ripleys_k() calculates the emperical Ripley's K measurement for the cell types specified by mnames in the mIF object. This is very useful when exploring the spatial clustering of single cell types on TMA cores or ROI spots following proccessing with a program such as HALO for cell phenotyping.

In the 'ripleys_k' function, there is the ability to perform permutations in order to assess whether the clustering of a cell type is significant, or the ability to derive the exact CSR and forgo permutations for much faster sample processing. Permutations can be helpful if the significance of clustering wasnts to be identified - run 1000 permutations and if observed is outside 95-percentile then significant clustering. We, however, recommend using the exact CSR estimate due to speed.

Some things to be aware of when computing the exact Ripley's K estimate, if your spatial file is greater than the ‘big' size, the edge correction will be converted to ’none' in order to save on resources and compute time. Due to the introduction of Whole Slide Imaging (WSI), this can easily be well over 1,000,000 cells, and calculating edge correction for these spatial files will not succeed when attempting to force an edge correction on it.

Usage

ripleys_k(
  mif,
  mnames,
  r_range = seq(0, 100, 1),
  num_permutations = 50,
  edge_correction = "translation",
  method = "K",
  permute = FALSE,
  keep_permutation_distribution = FALSE,
  workers = 1,
  overwrite = FALSE,
  xloc = NULL,
  yloc = NULL,
  big = 10000
)

Arguments

mif

object of class 'mif' created with 'create_mif'

mnames

cell phenotype markers to calculate Ripley's K for

r_range

radius range (including 0)

num_permutations

number of permutations to use to estimate CSR. If 'keep_perm_dis' is set to FALSE, this will be ignored

edge_correction

edge correction method to pass to 'Kest'. can take one of "translation", "isotropic", "none"

method

not used currently

permute

whether to use CSR estimate or use permutations to determine CSR

keep_permutation_distribution

whether to find mean of permutation distribution or each permutation calculation

workers

number of cores to use for calculations

overwrite

whether to overwrite the 'univariate_Count' slot within 'mif$derived'

xloc

the location of the center of cells. If left 'NULL', 'XMin', 'XMax', 'YMin', and 'YMax' must be present.

yloc

the location of the center of cells. If left 'NULL', 'XMin', 'XMax', 'YMin', and 'YMax' must be present.

big

the number of cells at which to flip from an edge correction method other than 'none' to 'none' due to size

Value

object of class 'mif'

Examples

x <- spatialTIME::create_mif(clinical_data =spatialTIME::example_clinical %>% 
  dplyr::mutate(deidentified_id = as.character(deidentified_id)),
  sample_data = spatialTIME::example_summary %>% 
  dplyr::mutate(deidentified_id = as.character(deidentified_id)),
  spatial_list = spatialTIME::example_spatial,
  patient_id = "deidentified_id", 
  sample_id = "deidentified_sample")
mnames = x$spatial[[1]] %>%
  colnames() %>%
  grep("Pos|CD", ., value =TRUE) %>%
  grep("Cyto|Nucle", ., value =TRUE, invert =TRUE)
x2 = ripleys_k(mif = x, 
  mnames = mnames[1], 
  r_range = seq(0, 100, 1), 
  num_permutations = 100,
  edge_correction = "translation", 
  method = "K", 
  permute = FALSE,
  keep_permutation_distribution =FALSE, 
  workers = 1, 
  overwrite =TRUE)

spatialTIME documentation built on April 1, 2023, 12:18 a.m.