Created
March 8, 2014 16:24
-
-
Save SteveViss/9434384 to your computer and use it in GitHub Desktop.
Simple rules yield complex food webs (2000)Richard J. Williams & Neo D. MartinezNiche Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Niche-Food Web Model - Williams et Martinez | |
#### Parameters | |
# S = Number of trophic species | |
# C = Network connectance [0,0.5[ | |
nicheFW <- function(S,C){ | |
### Model | |
vec_n <- runif(S) | |
vec_r <- rbeta(S,1,1/(2*C)-1)*vec_n | |
vec_c <- runif(S,vec_r/2,vec_n) | |
vec_r_inf <- vec_c - vec_r/2 | |
vec_r_sup <- vec_c + vec_r/2 | |
out <- matrix(0, nrow=S,ncol=S) | |
for (y in 1:S){ | |
for (i in y:S){ | |
if(vec_n[y]>=vec_r_inf[i] & vec_n[y]<=vec_r_sup[i]) out[i,y]=1 | |
if(vec_n[i]>=vec_r_inf[y] & vec_n[i]<=vec_r_sup[y]) out[y,i]=1 | |
} | |
} | |
return(out) | |
} | |
Co = function(x) sum(x)/prod(dim(x)) | |
REPL = replicate(200, Co(nicheFW(80, 0.1))) | |
plot(density(REPL)) | |
summary(REPL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment