[R] Random resampling of columns in species association matrices
David L Carlson
dcarlson at tamu.edu
Wed May 9 18:01:43 CEST 2012
Sample data would make it possible to explore the options in more detail,
but here are two possibilities:
1. Convert each row of the matrix to row proportions and then take the
cumulative sum. Now draw a random uniform number between 0 and 1 and find
the first column that is larger than the random number. That column is your
randomly selected host. If there is one host, the cumulative sums will be
zero until you reach that column and then it will flip to 1 so that you will
always select that host.
2. For each parasite, create a vector of host names with each host repeated
by the number of interactions with that host. Use sample() to randomly draw
a host. You'll probably want to combine the vectors into a list to automate
the process over all parasites.
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of mariasve
> Sent: Wednesday, May 09, 2012 9:35 AM
> To: r-help at r-project.org
> Subject: [R] Random resampling of columns in species association
> matrices
>
> I have a host-parasite association matrix in which parasite species are
> rows
> and host species columns and cells contain the frequency of
> interactions.
> Some parasites are associated with many hosts, and some hosts harbor
> several
> parasites, and I want to repeatedly select only one single
> representative
> host per "generalized" (multi-host) parasite to create a new matrix in
> which
> no hosts are repeated. That is, I want multiple randomly generated
> symmetric
> matrices in which a host and a parasite species appear only once.
> Furthermore, I want to weight the probability of selecting a particular
> host
> for a parasite by the frequency of interactions between the two.
> Finally, a
> handful of parasites associate with only one single host. I do not want
> to
> lose these from the matrix, but rather fix these associations and only
> randomly select hosts for the generalized parasite species.
>
> My goal is to eventually perform generalized least squares regressions
> between a parasite trait and several host traits, but the first major
> hurdle
> for me to get over is how to randomly select only one host per parasite
> with
> no repetition of species in the matrix. I am also generally interested
> in
> how to resample columns instead of rows (in the package boot, for
> instance)
> because of another analysis I'm working on, and I have been unable to
> find a
> solution to this when searching the R help site.
>
> Any suggestions would be most welcomed.
>
> Maria
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Random-
> resampling-of-columns-in-species-association-matrices-tp4620618.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list