# Probability plot usage

Jakob Theorell1,2

1Oxford Autoimmune Neurology Group, Nuffield Department of Clinical Neurosciences, University of Oxford, Oxford, United Kingdom
2Department of Clinical Neurosciences, Karolinska Institutet, Stockholm, Sweden

#### 2021-05-19

# 1 Introduction

In this document, a typical analysis using the groupProbPlot function is shown. The indention with this function is to display differences between groups, tissues, stimulations or similar, with a single-cell resolution. The idea is that a cell that comes from a cell type that is specific for one of the two investigated groups will be surrounded exclusively by euclidean nearest neighbors that come from the same group. This is the basis for the analysis: in the standard case, the individual cell is given a number between -1 and 1 that reflects which fraction of the 100 closest neighbors in the euclidean space created by all the input markers that come from one group (-1) or the other (1). The scale is tweaked to reflect that the middle in this case corresponds to a likelihood of a perfect mix with 50% of the cells from each group. For an introduction to the package and example data description, see the general DepecheR package vinjette.

# 2 Installation

This is how to install the package, if that has not already been done:

    if(!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
    BiocManager::install("DepecheR")

# 3 Preparations of example data

For visualization purposes, some 2-dimensional representation of the data is necessary. This could just be two of the variables used to construct the probability vector, but it is more informative to include data on all variables, aided by e.g. tSNE or UMAP. In this case, we will display the data with tSNE.

    library(DepecheR)
    data("testData")
    data("testDataSNE")

# 4 Group probability plotting

This function differs from the other group differentiation functions in the DepecheR package in that no clustering output from the depeche function or any other clustering algorithm is needed as input. Instead, all the indata that the euclidean nearest neighbors should be identified from needs to be added, together with a group identity vector and the 2D data used to display the data. Optionally, the resulting group probability vector can be returned, which will be the case in this example.

    dataTrans <-
      testData[, c("SYK", "CD16", "CD57", "EAT.2", "CD8", "NKG2C", "CD2", "CD56")]

    testData$groupProb <- groupProbPlot(xYData = testDataSNE$Y,
                                        groupVector = testData$label,
                                        groupName1 = "Group_1",
                                        groupName2 = "Group_2",
                                        dataTrans = dataTrans)
    ## [1] "Done with k-means"
    ## [1] "Now the first bit is done, and the iterative part takes off"
    ## [1] "Clusters 1 to 7 smoothed in 2.9159369468689 . Now, 13 clusters are
    ## [1] left."
    ## [1] "Clusters 8 to 14 smoothed in 0.925199031829834 . Now, 6 clusters are
    ## [1] left."
    ## [1] "Clusters 15 to 20 smoothed in 0.905373096466064 . Now, 0 clusters are
    ## [1] left."

When running this function, the output is a high-resolution plot saved to disc. A low resolution variant of the result (made small for BioConductor size constraint reasons) is shown here. In this case, the groups are so separated, that almost all cells show a 100% probability of belonging to one of the groups or the other. This is unusual with real data, so the white fields are generally larger.

Group probaility plot

# 5 Session information

    sessionInfo()

    ## R version 4.1.0 RC (2021-05-10 r80283)
    ## Platform: x86_64-w64-mingw32/x64 (64-bit)
    ## Running under: Windows Server x64 (build 17763)
    ##
    ## Matrix products: default
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.1252
    ## [3] LC_MONETARY=English_United States.1252
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.1252
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] DepecheR_1.8.0   knitr_1.33       BiocStyle_2.20.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] ggrepel_0.9.1       Rcpp_1.0.6          lattice_0.20-44
    ##  [4] tidyr_1.1.3         FNN_1.1.3           corpcor_1.6.9
    ##  [7] snow_0.4-3          gtools_3.8.2        assertthat_0.2.1
    ## [10] digest_0.6.27       foreach_1.5.1       utf8_1.2.1
    ## [13] RSpectra_0.16-0     plyr_1.8.6          R6_2.5.0
    ## [16] ellipse_0.4.2       evaluate_0.14       ggplot2_3.3.3
    ## [19] pillar_1.6.1        gplots_3.1.1        rlang_0.4.11
    ## [22] gdata_2.18.0        jquerylib_0.1.4     gmodels_2.18.1
    ## [25] Matrix_1.3-3        rmarkdown_2.8       moments_0.14
    ## [28] rARPACK_0.11-0      BiocParallel_1.26.0 stringr_1.4.0
    ## [31] igraph_1.2.6        munsell_0.5.0       compiler_4.1.0
    ## [34] xfun_0.23           pkgconfig_2.0.3     htmltools_0.5.1.1
    ## [37] doSNOW_1.0.19       tidyselect_1.1.1    tibble_3.1.2
    ## [40] gridExtra_2.3       bookdown_0.22       codetools_0.2-18
    ## [43] matrixStats_0.58.0  viridisLite_0.4.0   fansi_0.4.2
    ## [46] crayon_1.4.1        dplyr_1.0.6         MASS_7.3-54
    ## [49] bitops_1.0-7        grid_4.1.0          jsonlite_1.7.2
    ## [52] gtable_0.3.0        lifecycle_1.0.0     DBI_1.1.1
    ## [55] magrittr_2.0.1      scales_1.1.1        KernSmooth_2.23-20
    ## [58] stringi_1.6.2       reshape2_1.4.4      viridis_0.6.1
    ## [61] robustbase_0.93-7   bslib_0.2.5.1       ellipsis_0.3.2
    ## [64] generics_0.1.0      vctrs_0.3.8         RColorBrewer_1.1-2
    ## [67] iterators_1.0.13    mixOmics_6.16.0     tools_4.1.0
    ## [70] glue_1.4.2          DEoptimR_1.0-8      purrr_0.3.4
    ## [73] parallel_4.1.0      yaml_2.2.1          colorspace_2.0-1
    ## [76] BiocManager_1.30.15 caTools_1.18.2      beanplot_1.2
    ## [79] sass_0.4.0