probability

R sample probabilities: Default is equal weight; why does specifying equal weights cause different values to be returned?

放肆的年华 提交于 2020-08-25 03:53:26
问题 I have a simple question regarding the sample function in R. I'm randomly sampling from 0s and 1s and summing them together, from an input vector of length 5, which designates the number of trials to run and sets the seed to generate reproducible random numbers. Seed works as expected, but I get different matrices of random numbers depending on what I put in the prob statement. In this case I assumed prob=NULL should be the same as prob=c(0.5,0.5). Why isn't it? vn<-c(12, 44, 9, 17, 28) > do

Randomly Generating Combinations From Variable Weights

喜你入骨 提交于 2020-08-18 07:34:58
问题 VERY IMPORTANT EDIT: All A i are unique . The Question I have a list A of n unique objects. Each object A i has a variable percentage P i . I want to create an algorithm that generates a new list B of k objects ( k < n / 2 and in most cases k is significantly less than n / 2 . E.g. n=231 , k=21 ). List B should have no duplicates and will be populated with objects originating from list A with the following restriction: The probability that an object A i appears in B is P i . What I Have Tried