Draws n units with replacement, with selection probability proportional to the inclusion probabilities. A unit can be selected multiple times.

up_multinomial(pik)

Arguments

pik

A numeric vector of inclusion probabilities. The sum determines the number of draws: n = round(sum(pik)).

Value

An integer vector of n selected indices (1 to length(pik)). May contain repeated values.

Details

Multinomial sampling (PPS with replacement) makes n independent draws, each with probability proportional to pik. This is equivalent to sampling::UPmultinomial() but returns indices instead of counts.

Properties:

  • Fixed number of draws n = round(sum(pik))

  • Units can be selected multiple times

  • Selection probability per draw: \(p_k = \pi_k / \sum \pi_k\)

Useful for Hansen-Hurwitz estimation and bootstrap procedures.

See also

up_brewer(), up_maxent() for without-replacement methods, srs() with replace = TRUE for equal probability

Examples

pik <- c(0.2, 0.4, 0.6, 0.8)  # sum = 2, so 2 draws

set.seed(42)
idx <- up_multinomial(pik)
idx  # 2 indices, may repeat
#> [1] 1 1

# Larger example
pik <- c(1, 2, 3, 4)  # sum = 10, so 10 draws
set.seed(42)
idx <- up_multinomial(pik)
table(idx)  # Unit 4 likely appears most often
#> idx
#> 1 2 3 4 
#> 2 3 3 2 

# Use for selection
df <- data.frame(id = 1:4, x = c(10, 20, 30, 40))
df[idx, ]  # 10 rows, some repeated
#>     id  x
#> 1    1 10
#> 1.1  1 10
#> 4    4 40
#> 2    2 20
#> 3    3 30
#> 3.1  3 30
#> 2.1  2 20
#> 4.1  4 40
#> 3.2  3 30
#> 2.2  2 20