groupProbPlot {DepecheR} | R Documentation

## Define and plot group probabilities

### Description

This function defines and plots the single-observation probability for belonging to either of two groups. It builds on the same idea as has been put forward in the Sconify package: -Burns TJ (2019). Sconify: A toolkit for performing KNN-based statistics for flow and mass cytometry data. R package version 1.4.0 and -Hart GT, Tran TM, Theorell J, Schlums H, Arora G, Rajagopalan S, et al. Adaptive NK cells in people exposed to Plasmodium falciparum correlate with protection from malaria. J Exp Med. 2019 Jun 3;216(6):1280–90. First, the k nearest neighbors are defined for each individual cell, and the cell in question thereafter gets a group probability assigned to it, which is calculated by defining the percentage of neighbors belonging to each respective groups. In other words, if 20 out of 100 neighbors belong to group A and 80 belong to group B, and the value for the cell will be 20 A or 80 accordingly reflected in the color scale on the resulting plot.

### Usage

    groupProbPlot(
      xYData,
      groupVector,
      dataTrans,
      kNeighK = max(100, round(nrow(dataTrans)/10000)),
      kMeansK = round(nrow(dataTrans)/1000),
      densContour = TRUE,
      groupName1 = unique(groupVector)[1],
      groupName2 = unique(groupVector)[2],
      plotName = "default",
      title = FALSE,
      bandColor = "black",
      plotDir = ".",
      dotSize = 400/sqrt(nrow(xYData)),
      returnProb = FALSE,
      returnProbColVec = FALSE,
      createOutput = TRUE
    )

### Arguments

`xYData` | A dataframe or matrix with two columns. Each row contains information about the x and y positition in the field for that observation.
`groupVector` | Vector with the same length as xYData containing information about the group identity of each observation.
`dataTrans` | The data cloud in which the nearest neighbors for the events should be identified.
`kNeighK` | The number of nearest neighbors.
`kMeansK` | The number of clusters in the initial step of the algorithm. A higher number leads to shorter runtime, but potentially lower accuracy.
`densContour` | If density contours should be created for the plot(s) or not. Defaults to TRUE. a
`groupName1` | The name for the first group
`groupName2` | The name for the second group
`plotName` | The main name for the graph and the analysis.
`title` | If there should be a title displayed on the plotting field. As the plotting field is saved as a png, this title cannot be removed as an object afterwards, as it is saved as coloured pixels. To simplify usage for publication, the default is FALSE, as the files are still named, eventhough no title appears on the plot.
`bandColor` | The color of the contour bands. Defaults to black.
`plotDir` | If different from the current directory. If specified and non-existent, the function creates it. If "." is specified, the plots will be saved at the current directory.
`dotSize` | Simply the size of the dots. The default makes the dots smaller the more observations that are included.
`returnProb` | Should a probability vector be returned? Mutually exclusive with returnProbColVec.
`returnProbColVec` | Should the color vector be returned as part of the output? Mutually exclusive with returnProb.
`createOutput` | For testing purposes. Defaults to TRUE. If FALSE, no output is generated.

### Value

A graph showing the probability as a color scale from blue over white to red for each event to belong to one group or the other, with a separate color scale. Optionally also the color vector, if returnProbColVec is TRUE.

### Examples

    data(testData)
    data(testDataSNE)
    dataTrans <-
      testData[, c("SYK", "CD16", "CD57", "EAT.2", "CD8", "NKG2C", "CD2", "CD56")]
    ## Not run:
    groupProbPlot(xYData = testDataSNE$Y, groupVector = testData$label,
    dataTrans)

    ## End(Not run)

[Package DepecheR version 1.2.2 Index]