sample_partitions_similar_weights: Generate Random, Non-Overlapping Similarly-Weighted Partition...

Description Usage Arguments Value

View source: R/sample_partitions.R

Description

Generate Random, Non-Overlapping Similarly-Weighted Partition of Indices

Usage

1
2
3
4
5
6
7
8
sample_partitions_similar_weights(
  w,
  fraction = NULL,
  size = NULL,
  w_tolerance = 0.01,
  max_rejections = 100L,
  warn = TRUE
)

Arguments

w

Numeric vector of n non-negative, finite weights. Weights are normalized such that sum(w) equals one.

fraction

A numeric in (0,1] specifying the size of each set relative to n. If NULL, argument size is used.

size

An integer in {1, 2, ..., n} specifying the size of each set. If NULL, argument fraction is used.

w_tolerance

Maximum allowed difference between target weight of each set (e.g. fraction * 1) and the actual total weight of the set (i.e. sum(w[set]). If all sets are within the tolerance, the sample is accepted, otherwise rejected.

max_rejections

The maximum number of rejections before giving up.

warn

If TRUE, a warning is produced if the sets produced are not of equal size.

Value

A list of P random non-overlapping (disjoint) sets where each element holds indices in {1, 2, ..., n} and where the union of all sets is {1, 2, ..., n}. Attribute weights is a numeric vector of length P where each element is he sum of all normalized weight of the corresponding set. The partition found is such that |weight_i - 1/P| ≤q w_{tolerance}| is true for each set. Attribute count gives the number of internal samples produced before arriving at an accepted sample. If no accepted sample was found, the NA is returned (with count attribute set).


HenrikBengtsson/TopDomStudy documentation built on May 14, 2021, 1:49 p.m.