Let's say I want to take a sample of variable-length values โโfrom an arbitrary number of difference probability distributions and with a weighted probability of sampling from each distribution.
It looks like I should be able to do this using the purrr map functions, but I'm afraid ...
library(tidyverse) set.seed(20171127) # sample from 5 different probability distributions dists <- tibble( samp_distA = round(rnorm(n=1000, mean=17, sd=4)), samp_distB = round(rnorm(n=1000, mean=13, sd=4)), samp_distC = round(rnorm(n=1000, mean=13, sd=4)), samp_distD = round(rbeta(n=1000, 2,8)*10), samp_distE = round(rnorm(n=1000, mean=8, sd=3)) ) # define number of samples to be drawn for each group n.times <- c(20,15,35,8,6) # define weights to be used for sampling from dists probs <- tibble(A = c(0.80, 0.05, 0.05, 0.05, 0.05), B = c(0.05, 0.80, 0.05, 0.05, 0.05), C = c(0.05, 0.05, 0.80, 0.05, 0.05), D = c(0.05, 0.05, 0.05, 0.80, 0.80), E = c(0.05, 0.05, 0.05, 0.05, 0.80) ) # sample from dists, n.times, and using probs as weights... output <- map2(sample, size=n.times, weight=probs, tbl=dists) #...doesn't work
Any suggestions gratefully received.