interCellTypeSpatialCrossCor: Tests for inter-cell-type spatial cross-correlation between...

View source: R/correlationStatistics.R

interCellTypeSpatialCrossCorR Documentation

Tests for inter-cell-type spatial cross-correlation between gene A in group A and gene B in group B

Description

Tests for inter-cell-type spatial cross-correlation between gene A in group A and gene B in group B

Usage

interCellTypeSpatialCrossCor(gexpA, gexpB, groupA, groupB, weight)

Arguments

gexpA

Expression for gene A

gexpB

Expression for gene B

groupA

Cells in group A

groupB

Cells in group B

weight

Adjacency weight matrix

Value

statistic of how well gene expression A in cells of group A are correlated in space with gene expression B in cells of group B

Examples

# Simulate data
set.seed(0)
N <- 100
pos <- cbind(rnorm(N), rnorm(N))
rownames(pos) <- paste0('cell', 1:N)
colnames(pos) <- c('x', 'y')
weight <- getSpatialNeighbors(pos)
ctA <- sample(rownames(pos), N/2)
ctB <- setdiff(rownames(pos), ctA)
gexpA <- pos[,2]
gexpA[ctB] <- 0
gexpB <- pos[,2]
gexpB[ctA] <- 0
#plotEmbedding(pos, col=gexpA)
#plotEmbedding(pos, col=gexpB)
interCellTypeSpatialCrossCor(gexpA, gexpB, ctA, ctB, weight)
cor(gexpA, gexpB) # compare


JEFworks/MERingue documentation built on June 11, 2022, 4:16 a.m.