This function returns positive weights that sum to one for individuals using subpopulation labels, such that every subpopulation receives equal weight. In particular, if there are K subpopulations, then the sum of weights for every individuals of a given subpopulation will equal 1/K. The weight of every individual is thus inversely proportional to the number of individuals in its subpopulation.
The length-n vector of subpopulation assignments for each individual.
The length-n vector of weights for each individual.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# if every individual has a different subpopulation, weights are uniform: subpops <- 1:10 w <- weightsSubpops(subpops) stopifnot(all(w == rep.int(1/10,10))) # subpopulations can be strings too subpops <- c('a', 'b', 'c') w <- weightsSubpops(subpops) stopifnot(all(w == rep.int(1/3,3))) # if there are two subpopulations # and the first has twice as many individuals as the second # then the individuals in this first subpopulation weight half as much # as the ones in the second subpopulation subpops <- c(1, 1, 2) w <- weightsSubpops(subpops) stopifnot(all(w == c(1/4,1/4,1/2)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.