-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_test.R
More file actions
36 lines (28 loc) · 1.27 KB
/
nested_test.R
File metadata and controls
36 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require(Rcpp)
setwd('~/RcppNested')
raw_data <- read.csv('interaction_matrix.csv', head=F)
csv_mat <- as.matrix(raw_data)
sourceCpp("nestedness.cpp")
calculateNODF(getRandomMatrix_GrowMonotonic(csv_mat, 100))
t<-getRandomMatrix_GrowEvents(csv_mat, sample(-1:2, 50, replace=T), sample(-1:2, 50, replace=T), sample(-50:50, 50, replace=T))
calculateNODF(sortMatrix(t))
vegan::nestednodf(t)
vegan::nestednodf(csv_mat)
calculateNODF(csv_mat)
ran_mat <- getRandomMatrix_Fill(csv_mat)
calculateNODF(ran_mat)
vegan::nestednodf(ran_mat)
#plot distributions form c and native R - time matched, 100x speed increase!
c_version <- system.time(nodf_null <- replicate(500, calculateNODF(getRandomMatrix_GrowMonotonic(csv_mat, 100))$NODF))
r_version <- system.time(nodf_null_2 <- replicate(500, vegan::nestednodf(sortMatrix(getRandomMatrix_Fill(csv_mat)))$statistic["NODF"]))
par(mfcol=c(2,1))
hist(nodf_null)
hist(nodf_null_2)
#different null model generators
nodf_null_col <- replicate(1000, calculateNODF(getRandomMatrix_ColShuffle(csv_mat))$NODF)
nodf_null_row <- replicate(1000, calculateNODF(getRandomMatrix_RowShuffle(csv_mat))$NODF)
nodf_null_fill <- replicate(1000, calculateNODF(getRandomMatrix_Fill(csv_mat))$NODF)
par(mfcol=c(3,1))
hist(nodf_null_col)
hist(nodf_null_row)
hist(nodf_null_fill)