I'm trying to draw n -- say, 10 for simplicity -- samples from an array in Julia. Using the function wsample, ndraws below gives me what I wanted
using Distributions
population = [ 1, 10 ]
weights = [ .4, .6 ]
population_idx = wsample( population, weights, 10 ) # i.e. population indices
ndraws = population[ population_idx ]
I'm using Julia 0.2. Is there a way to do the same thing without the indices? In R for instance, we have
ndraws <- sample( population, size = 10, replace = TRUE, prob = weights )
The docs here suggests there is i.e. doing this
ndraws = wsample( population, weights, 10 )
should give me, err, exactly what I want? Note too, that in the docs, the argument name for number of draws is n but looking in the source code of sample.jl, it refers to k.
wsample( population, weights, 10 )gives the answer you want (values of 1 and 10). When I runpopulation[ population_idx ]I getERROR: BoundsError(). Is there some documentation that sayswsamplereturns an index? It appears to me to return a sample vector frompopulation- James Kingmethods( wsample )is what led to the confusion. The whole multiple dispatch business will take a while to sink in. I would've accepted your answer had it not been a comment. - vathymut