stratify: Stratify operations.

View source: R/stratify.R

stratifyR Documentation

Stratify operations.

Description

stratify stratifies operations.

Usage

stratify(population, sample, reducer, strata, ...)

Arguments

population

tbl with grouping (metadata) and observation variables.

sample

tbl with the same structure as population. This is typically used by operations to estimate parameters.

reducer

operation that is to applied in a stratified manner.

strata

optional character vector specifying grouping variables for stratification.

...

arguments passed to operation.

Value

population with potentially extra columns.

Examples

suppressMessages(suppressWarnings(library(magrittr)))
population <- tibble::tibble(
  Metadata_group = sample(c("a", "b"), 100, replace = TRUE),
  Metadata_type = sample(c("control", "trt"), 100, replace = TRUE),
  AreaShape_Area = c(rnorm(98), 20, 30),
  AreaShape_Eccentricity = rnorm(100)
)
variables <- c("AreaShape_Area", "AreaShape_Eccentricity")
strata <- c("Metadata_group")
sample <- population %>% dplyr::filter(Metadata_type == "control")
population_marked <-
  cytominer::stratify(
    reducer = cytominer::mark_outlier_rows,
    method = "svd+iqr",
    population = population,
    variables = variables,
    sample = sample,
    strata = strata
  )
population_marked %>%
  dplyr::group_by(is_outlier) %>%
  dplyr::sample_n(3)

CellProfiler/cytominr documentation built on July 2, 2023, 6:19 p.m.