Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What the OP is probably looking for here is a way to bootstrap the data for a Hill or Simpson diversity index, which provides some assumptions about the data being sampled:</p> <ul> <li>Each row is a site, each column is a species, and each value is a count.</li> <li>Individuals are being sampled for the bootstrap, NOT THE COUNTS.</li> </ul> <p>To do this, bootstrapping programs will often model the counts as a string of individuals. For instance, if we had a record like so:</p> <pre><code>a b c 2 3 4 </code></pre> <p>The record would be modeled as:</p> <pre><code>aabbbcccc </code></pre> <p>Then, a sample is usually drawn WITH replacement from the string to create a larger set based on the model set.</p> <p><strong>Bootstrapping a site</strong>: In R, we have a way to do this that is actually quite simple with the 'sample' function. If you select from the column numbers, you can provide probabilities using the count data.</p> <pre><code># Test data. data &lt;- data.frame(a=2, b=3, c=4) # Sampling from first row of data. row &lt;- 1 N_samples &lt;- 50 samples &lt;- sample(1:ncol(data), N_samples, rep=TRUE, prob=data[row,]) </code></pre> <p><strong>Converting the sample into the format of the original table</strong>: Now we have an array of samples, with each item indicating the column number that the sample belongs to. We can convert back to the original table format in multiple ways, but here is a fairly simple one using a simple counting loop:</p> <pre><code># Count the number of each entry and store in a list. for (i in 1:ncol(data)){ site_sample[[i]] &lt;- sum(samples==i) } # Unlist the data to get an array that represents the bootstrap row. site_sample &lt;- unlist(site_sample) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload