NN_G: Nearest Neighbor Based Measures of Spatial Clustering for IF...

View source: R/nearest_neighbor.R

NN_GR Documentation

Nearest Neighbor Based Measures of Spatial Clustering for IF data

Description

For a given cell type, this function computes proportion of cells that have nearest neighbor less than r for the observed and permuted point processes.

Usage

NN_G(
  mif,
  mnames,
  r_range = seq(0, 100, 50),
  num_permutations = 50,
  edge_correction = "rs",
  keep_perm_dis = FALSE,
  workers = 1,
  overwrite = FALSE,
  xloc = NULL,
  yloc = NULL
)

Arguments

mif

An MIF object

mnames

Character vector of marker names to estimate degree of nearest neighbor distribution

r_range

Numeric vector of potential r values this range must include 0.

num_permutations

Numeric value indicating the number of permutations used. Default is 50.

edge_correction

Character value indicating the type of edge correction to use. Options include "rs" or "hans".

keep_perm_dis

Logical value determining whether or not to keep the full distribution of permuted G values

workers

Integer value for the number of workers to spawn

overwrite

Logical value determining if you want the results to replace the current output (TRUE) or be to be appended (FALSE).

xloc

a string corresponding to the x coordinates. If null the average of XMin and XMax will be used

yloc

a string corresponding to the y coordinates. If null the average of YMin and YMax will be used

Value

Returns a data.frame

Theoretical CSR

Expected value assuming complete spatial randomnessn

Permuted CSR

Average observed G for the permuted point process

Observed

Observed valuefor the observed point process

Degree of Clustering Permuted

Degree of spatial clustering where the reference is the permuted estimate of CSR

Degree of Clustering Theoretical

Degree of spatial clustering where the reference is the theoretical estimate of CSR

Examples

#Create mif object
library(dplyr)
x <- create_mif(clinical_data = example_clinical %>% 
mutate(deidentified_id = as.character(deidentified_id)),
sample_data = example_summary %>% 
mutate(deidentified_id = as.character(deidentified_id)),
spatial_list = example_spatial,
patient_id = "deidentified_id", 
sample_id = "deidentified_sample")

# Define the set of markers to study
markers <- c("CD3..Opal.570..Positive","CD8..Opal.520..Positive",
"FOXP3..Opal.620..Positive","CD3..CD8.","CD3..FOXP3.")

# Nearest Neighbor distribution for all markers with a neighborhood size 
# of  10,20,...,100 (zero must be included in the input).


x <- NN_G(mif = x, mnames = markers[1:2], num_permutations = 1,
edge_correction = 'rs', r = seq(0,100,10),
keep_perm_dis = FALSE, workers = 1)


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