# [R] Separating Output of Modularity Analyses

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Nov 19 22:22:47 CET 2019

```Hi Chelsea,
A brute force method, but I think it does what you want:

# create a sequence of integers to make checking easy
null.cz<-1:68
separate_interdigitated_vectors<-function(x,nv=2,vlen=17) {
xlen<-length(x)
starts<-seq(1,xlen-vlen*nv+1,by=vlen*nv)
cat(xlen,starts,"\n")
for(start in starts) {
if(start ==1) {
x1<-x[start:(start+vlen-1)]
x2<-x[(start+vlen):(start+vlen*2-1)]
} else {
x1<-c(x1,x[start:(start+vlen-1)])
x2<-c(x2,x[(start+vlen):(start+vlen*2-1)])
}
}
return(list(x1=matrix(x1,ncol=vlen,byrow=TRUE),
x2=matrix(x2,ncol=vlen,byrow=TRUE)))
}
separate_interdigitated_vectors(null.cz)

Jim

On Wed, Nov 20, 2019 at 2:43 AM Chelsea Hinton <chelsearhinton using gmail.com> wrote:
>
> Hello,
>
> I am working to evaluate the structure of shrub-pollinator networks using
> modularity analyses. I have generated 100 null model networks to test for
> modularity and extract c and z scores for each (measuring statistical
> significance in real networks). However, the output of the "czvalues" for
> all 100 null models comes out in one mass clump (See below code). The
> highlighted section in the below code is an example of the null c and z
> values. I have 17 plants in my shrub-pollinator network (represented by the
> whole numbers) and so the first 17 values are the c scores followed by the
> next 17 which are z scores and so on.
>
> Is there a way I can easily separate out the c values from the z values? Or
> should I instead generate 100 null networks individually?
>
> R Code for null model generation and c and z output for nulls:
>
> library(bipartite)
>
>
> nw<-sortweb(network)
> weighted<-as.matrix(nw)
>
> nulls <- nullmodel(weighted, N=100, method=3)
> null.res <- unlist(sapply(nulls, metaComputeModules, USE.NAMES = TRUE)) #takes
> a while ...
> null.res
> ## [[1]]
> ## Slot "likelihood":
> ## [1] 0.1309568
> ##
> ##
> ## [[2]]
> ## Slot "likelihood":
> ## [1] 0.1303186
> ##
> ##
> ## [[3]]
> ## Slot "likelihood":
> ## [1] 0.14044
> .............
>
> ## [[100]]
> ## Slot "likelihood":
> ## [1] 0.1332231
>
> null.cz<-unlist(sapply(null.res, czvalues, level = "lower", USE.NAMES = TRUE
> ))
> null.cz
> ##           1           2           3           4           5           6
> ##  0.64147140  0.74959438  0.62019013  0.65895062  0.73724490  0.72664360
> ##           7           8           9          10          11          12
> ##  0.73553719  0.57500000  0.60204082  0.66000000  0.72000000  0.37500000
> ##          13          14          15          16          17           1
> ##  0.37500000  0.77777778  0.27777778  0.44444444  0.00000000  0.70710678
> ##           2           3           4           5           6           7
> ##  0.70710678  1.10729957  1.68025904 -0.70710678 -0.12539247  0.99339927
> ##           8           9          10          11          12          13
> ##  0.62696233  0.72849280 -0.27007306 -0.86094603 -0.83722650 -0.72727630
> ##          14          15          16          17           1           2
> ## -0.86094603 -0.42633438 -0.70710678 -1.02821822  0.65504683  0.62195782
> ##           3           4           5           6           7           8
> ##  0.65606509  0.70226843  0.71777778  0.58500000  0.71500000  0.74048443
> ##           9          10          11          12          13          14
> ##  0.70000000  0.44444444  0.57142857  0.75000000  0.62500000  0.66666667
> ##          15          16          17           1           2           3
> ##  0.44444444  0.44444444  0.00000000  0.70710678  1.04053196          NA
> ##           4           5           6           7           8           9
> ##  0.70710678 -0.08671100  2.15643011  0.40204629  0.40204629 -0.47514562
>
> Thank you for your time,
>
> Chelsea
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help