sample_partitions_similar_weights_by_half: Generate Random, Non-Overlapping, Similarly-Weighted, Two-Set...

Description Usage Arguments Value

View source: R/sample_partitions_by_half.R

Description

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

Usage

1
2
3
4
5
6
7
sample_partitions_similar_weights_by_half(
  w,
  fraction,
  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 of length two in (0,1/2] specifying the size of each partition relative to n, where the first element specifies the "reference" partition and the second the "test" partition. For backward compatible reasons, if of length one, then it's equivalent to specifying fraction = c(reference = 1/2, test = fraction).

w_tolerance

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

max_rejections

The maximum number of rejections before giving up.

warn

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

Value

A list of two disjoint random non-overlapping partitions where each element holds indices in {1, 2, ..., n}. The first element holds the 'reference' partition and the second the 'test' partition. Attribute weights gives the total normalized weight of each set. If no accepted sample was found, then NA is returned. Attribute count gives the number of internal samples produced before arriving at an accepted or rejected partition.


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