qTune {BayesSpace} | R Documentation

## Tuning the choice of q (number of clusters) before running spatialCluster

### Description

Before running `spatialCluster()`, we recommend tuning the choice of `q` by choosing the `q` that maximizes the model's negative log likelihood over early iterations. `qTune()` computes the average negative log likelihood for a range of q values over iterations 100:1000, and `qPlot()` displays the results.

### Usage

    qPlot(sce, qs = seq(3, 7), force.retune = FALSE, ...)

    qTune(sce, qs = seq(3, 7), burn.in = 100, nrep = 1000, ...)

### Arguments

`sce` | A SingleCellExperiment object containing the spatial data.
`qs` | The values of q to evaluate.
`force.retune` | If specified, existing tuning values in `sce` will be overwritten.
`...` | Other parameters are passed to `spatialCluster()`.
`burn.in, nrep` | Integers specifying the range of repetitions to compute.

### Details

`qTune()` takes the same parameters as `spatialCluster()` and will run the MCMC clustering algorithm up to `nrep` iterations for each value of `q`. The first `burn.in` iterations are discarded as burn-in and the log likelihood is averaged over the remaining iterations.

`qPlot()` plots the computed negative log likelihoods as a function of q. If `qTune()` was run previously, i.e. there exists an attribute of `sce` named `"q.logliks"`, the pre-computed results are displayed. Otherwise, or if `force.retune` is specified, `qplot()` will automatically run `qTune()` before plotting (and can take the same parameters as `spatialCluster()`.

### Value

`qTune()` returns a modified `sce` with tuning log likelihoods stored as an attribute named `"q.logliks"`.

`qPlot()` returns a ggplot object.

### Examples

    set.seed(149)
    sce <- exampleSCE()
    sce <- qTune(sce, seq(3, 7), burn.in=10, nrep=100)
    qPlot(sce)

[Package BayesSpace version 1.4.1 Index]