Skip to contents

Repeatedly fuses subsets of a relatedness collection and returns the replicate consensus matrices as another typed collection.

Usage

precise_stability(
  data,
  scheme = "loo",
  fusion = "mean",
  params = list(),
  replicates = 100,
  type = NULL,
  seed = NULL,
  verbose = TRUE
)

Arguments

data

A tibble from precise_dist(), precise_transform(), precise_fusion(), or precise_graph(), or a named list of matrices with type= declared. Every row must share one type. Duplicated matrices produce a warning, because a duplicate cannot be genuinely left out.

scheme

"loo" (the default) or "bootstrap".

fusion

One fusion method name, used for every replicate. The default is "mean". See precise_fusion() for the choices.

params

A flat list of parameters for that one fusion method, for example list(trim = 0.1) when fusion = "trimmed_mean".

replicates

Whole number of bootstrap replicates. The default is 100. Ignored when scheme = "loo".

type

Only for bare-list input. "distance" or "similarity". Must be omitted for tibble input.

seed

NULL or a whole number. Only affects scheme = "bootstrap".

verbose

TRUE or FALSE. Report progress.

Value

A tibble with one role = "reference" row followed by one row per replicate. The first columns are distance, metric, matrix, type, and time_taken_seconds, matching the collection idiom used elsewhere in the package. The columns role, scheme, fusion, replicate, inputs, parameters, and meta record how each row was produced. Leave-one-out keys are loo_drop_<input> and bootstrap keys are bootstrap_<i>.

Details

The unit of resampling is the whole matrix. No rows, columns, cells, or raw input values are resampled or perturbed, and every result is conditional on the candidate set supplied.

scheme = "loo", the default, is deterministic leave-one-out. It fuses the full set once as the reference row, then fuses the set again with each matrix omitted in turn. It requires at least three matrices so that every replicate still has two to fuse, and each row names the dropped matrix in meta.

scheme = "bootstrap" samples whole matrices with replacement and fuses each resample. It requires at least two matrices, replicates sets how many are drawn, and seed makes the draws reproducible. meta records n_unique_inputs for each replicate, because a resample can repeat one matrix.

See also

Author

Brian Muchmore

Examples

data(data_cell_cycle, package = "PreciseDist")

cells <- c(1:4, 60:63, 118:121)
cell_cycle <- as.matrix(data_cell_cycle[cells, 2:41])
rownames(cell_cycle) <- paste0(data_cell_cycle$Cell_cycle[cells], "_", cells)

candidates <- precise_dist(
  cell_cycle,
  dists = c("euclidean", "manhattan", "canberra", "cosine"),
  verbose = FALSE
)
candidates <- precise_transform(candidates, to = "distance")

replicates <- precise_stability(
  candidates,
  scheme = "loo",
  fusion = "mean",
  verbose = FALSE
)
replicates[, c("distance", "role", "fusion", "replicate")]
#> # A tibble: 5 × 4
#>   distance           role      fusion replicate
#>   <chr>              <chr>     <chr>      <int>
#> 1 reference          reference mean           0
#> 2 loo_drop_euclidean loo_drop  mean           1
#> 3 loo_drop_manhattan loo_drop  mean           2
#> 4 loo_drop_canberra  loo_drop  mean           3
#> 5 loo_drop_cosine    loo_drop  mean           4
replicates$meta[[2]]
#> $n_inputs
#> [1] 3
#> 
#> $input_indices
#> [1] 2 3 4
#> 
#> $dropped
#> [1] "euclidean"
#>