Skip to content

Suggestions regarding randomly repooling genind objects

2 messages · Bhuller, Ravneet, Zhian Kamvar

#
Dear Members,

I have subset the genind object by population using seppop.

This has given me a new obj (which is a list of genind objects)

Now I want to randomly repool genind objects - incrementing the repooling size by 1 every time:

e.g.

1. randomly repool 2 genind objects, with replacement
2. randomly repool 3 genind objects, with replacement

and so on until all the genind objects are repooled.

Please if anyone can give me any suggestions on how to do this. I have tried various for loops but not successful.

Many thanks,

Rav
#
Hi,

The function repool() can take a list object, and you can subset a list with replacement. The sample() function will allow you to randomly sample any vector with or without replacement. 

For this problem, you should only need one loop/apply function.

Here's an example:

library(adegenet)
data(nancycats)
nanpop <- seppop(nancycats, drop = FALSE)
repooled <- lapply(seq(2, nPop(nancycats)), function(n) repool(nanpop[sample(17, n)]))

In the end, this will give you a list of repooled genind objects where each genind object only contains unique populations and the last object is the same size as the original, but in a different order. If you wanted the potential for duplicate populations within your data, you would add replace = TRUE to the sample() function. 

Hope that helps,
Zhian