I'm trying to downsample from a matrix of numbers. Each number is the number of times we saw a particular event. By downsample I mean I want to pseudo-randomly select values from each row so they equal approximately 1/30th of what they currently are.
Attached is roughly what I want to get out. It's a little more exact than I actually want but this is what I meant.
An example before and after table Col 1 Col 2 Frank 930 900 David 10000 12000 Rosa 7500 6900 Simone 500 460 Col 1 Col 2 Frank 30 28 David 300 250 Rosa 210 310 Simone 18 40
The goal is to simulate if we ran an experiment fewer times. All values in the matrix are between 0 and about 200k. Currently each column has about 45k rows and sum to between 30 and 40 million. The goal is to downsample by about 30 fold so I end up with each column summing 1-1.5 million. It could go up to about 2 million if necessary but can't really go below 1 million. I don't want to just divide each cell by 30 or sample randomly.
My initial plan was to populate a list with each row name equal to the number of times it appeared than randomly select from that list a certain number of times. Someone suggested I try the function rbinom but I couldn't work out how to use it properly. I've included what I did for each variant of rbinom and roughly what I got out of each one below. If anyone can point me in the right direction with it that would be great. This was attempting to reduce by about 10.
I want to get out a matrix with the same number of rows as I started with where each column sums to between 1 and 1.5 million. The order of the rows doesn't matter as long as they keep their row names.
I'm working in R.
#Produces a list that's all 0s. dbinom(foo$col1,1500000, 0.1) #Produces a list that's all 0s pbinom(foo$col1,1500000, 0.1) #Produces a list that's mostly NAs qbinom(foo$col1,1500000, 1/10) #Gives insanely high numbers (~150000) on every row rbinom(foo$col1,1500000, 0.1)