Comments (7)
Here is a better proof of concept and a function to carry out the computation of the individual swapped community by site matrix. The code also performs a quick test at the bottom that checks that species sums have not changed
S = 6
N = 100
nplots = 10
rand_comm = matrix(rpois(S*nplots, 1),
ncol=S, nrow=nplots)
intra_sp_swap = function(comm, groups) {
group_levels = unique(groups)
comm_group_noagg = matrix(NA, ncol=ncol(comm), nrow=nrow(comm))
for(i in seq_along(group_levels)) {
row_indices = groups == group_levels[i]
comm_group = comm[row_indices, ]
sp_sums = colSums(comm_group)
tmp_comm = sapply(sp_sums, function(x)
table(c(sample(1:nrow(comm_group), x,
replace=T),
1:nrow(comm_group))) - 1)
comm_group_noagg[row_indices, ] = tmp_comm
}
comm_group_noagg
}
# test species sums for equality
replicate(20, all.equal(colSums(rand_comm),
colSums(intra_sp_swap(rand_comm, rep(1:2, each=5)))))
from mobr.
here is the best form of the two functions needed for incoperating this into our code base. There are two functions: 1) computes shuffled comm matrix, 2) computes averaged sample based rarefaction curve. These two functions can just be called before normal sample based rarefaction for both the observed and null perms. it is very fast luckily
intra_sp_swap = function(comm, groups) {
group_levels = unique(groups)
comm_group_noagg = matrix(NA, ncol=ncol(comm), nrow=nrow(comm))
for(i in seq_along(group_levels)) {
row_indices = groups == group_levels[i]
comm_group = comm[row_indices, ]
sp_sums = colSums(comm_group)
tmp_comm = sapply(sp_sums, function(x)
table(c(sample(1:nrow(comm_group), x,
replace=T),
1:nrow(comm_group))) - 1)
comm_group_noagg[row_indices, ] = tmp_comm
}
comm_group_noagg
}
avg_swap_rare = function(comm, groups, nperm=1000, effort=NULL){
S = replicate(nperm,
rarefaction(intra_sp_swap(comm, groups),
'samp', effort))
Savg = apply(S, 1, mean)
Savg
}
from mobr.
Bummer minor bug in code not quite as fast as I thought maybe we could turn down the default 1000 replicates to 500 or so.
from mobr.
I should note though that the functions I provide above appear to be working
from mobr.
Looks great, thanks!
from mobr.
Forget about what I said this morning - let's keep the functions as they are for now. It's actually easier to fit them into our original framework this way.
from mobr.
Yea with my functions you can supply them just a single group
Dan
On Jul 15, 2016, at 11:07 AM, Xiao Xiao [email protected] wrote:
Forget about what I said this morning - let's keep the functions as they are for now. It's actually easier to fit them into our original framework this way.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
from mobr.
Related Issues (20)
- rarefaction dens_ratio argument HOT 1
- Add formula specification method for mob stats
- readme needs updating
- Extract direction of 'effect size' (D-bar) HOT 3
- make it clearer how statistics can be accessed
- Warning needed: Computing and plotting issues when the design is unbalanced HOT 7
- kNCN method not using great circle distances
- todo: post v2.0 release HOT 4
- beta diversity calculations HOT 10
- effort = NA by default in calc_comm_div and calc_div leads to not so indicative error messages
- Negative S_PIE values when very small non integer abundances HOT 11
- Wrong result from calc_SPIE when there are only singletons HOT 2
- "mob" in the headlines HOT 2
- vignette and documentation todo HOT 4
- betaC calculation should richness be extrapolated? HOT 4
- Error in `get_delta_stats` for calculating density effects when dens_ratio < 1
- calculation of betaC fails when there are at least 1 doubleton but no singletons HOT 2
- towards more consistent computation of alpha, gamma, and beta diversity HOT 4
- Error in get_delta_stats for continuous analysis using ant samples along an elevation gradient HOT 3
- Errors in plot_rarefaction examples (dev branch)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobr.