rich core - weighted network

10 views
Skip to first unread message

Jef Vlegels

unread,
Dec 21, 2019, 2:12:32 AM12/21/19
to brainGraph-help
Dear group members,

I'm trying to calculate rich-cores on a series of weighted networks, but I'm running into trouble when trying to use the 'weighted=TRUE' argument in the rich_core() function.
The problem is easy reproducible using for example this code: 

>library("brainGraph")
>library("igraphdata")
>data(UKfaculty)
> is_weighted(UKfaculty)
[1] TRUE

> rich_core(UKfaculty)
     density rank k.r core.size weighted
1: 0.1260802   41   9 0.5061728    FALSE
>#rich_core on unweighted network is calculated without any problem

>rich_core(UKfaculty, weighted=TRUE)
Error: $ operator is invalid for atomic vectors
#the weighted argument is not recognized


Is the function not yet implemented for weighted graphs? Eventhough the manual says it is?

Thanks for any help/advice,
Jef (postdoc Ghent University, Belgium)



This is some sessionInfo:
> packageVersion("brainGraph")
[1] ‘2.7.3’
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252    LC_MONETARY=Dutch_Belgium.1252
[4] LC_NUMERIC=C                   LC_TIME=Dutch_Belgium.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] igraphdata_1.0.1 brainGraph_2.7.3 igraph_1.2.4.1  

loaded via a namespace (and not attached):
 [1] ggrepel_0.8.1       Rcpp_1.0.1          lattice_0.20-35     assertthat_0.2.1    digest_0.6.17      
 [6] foreach_1.4.4       R6_2.4.0            backports_1.1.2     acepack_1.4.1       ggplot2_3.2.1      
[11] pillar_1.4.2        rlang_0.4.2         lazyeval_0.2.1      rstudioapi_0.10     minqa_1.2.4        
[16] data.table_1.11.8   nloptr_1.2.1        rpart_4.1-13        Matrix_1.2-18       checkmate_1.8.5    
[21] splines_3.5.1       lme4_1.1-21         stringr_1.4.0       foreign_0.8-71      RcppEigen_0.3.3.5.0
[26] htmlwidgets_1.3     munsell_0.5.0       compiler_3.5.1      pkgconfig_2.0.2     base64enc_0.1-3    
[31] htmltools_0.3.6     nnet_7.3-12         tidyselect_0.2.5    tibble_2.1.3        gridExtra_2.3      
[36] htmlTable_1.12      RNifti_0.11.1       expm_0.999-3        Hmisc_4.1-1         codetools_0.2-15   
[41] permute_0.9-5       crayon_1.3.4        dplyr_0.8.3         MASS_7.3-50         bitops_1.0-6       
[46] grid_3.5.1          nlme_3.1-137        gtable_0.2.0        magrittr_1.5        scales_1.0.0       
[51] stringi_1.1.7       latticeExtra_0.6-28 boot_1.3-23         Formula_1.2-3       RColorBrewer_1.1-2 
[56] iterators_1.0.10    tools_3.5.1         ade4_1.7-13         glue_1.3.1          purrr_0.3.3        
[61] abind_1.4-5         parallel_3.5.1      survival_2.42-6     yaml_2.2.0          oro.nifti_0.9.1    
[66] colorspace_1.3-2    cluster_2.0.7-1     knitr_1.20 

Chris Watson

unread,
Dec 21, 2019, 5:42:00 PM12/21/19
to brainGr...@googlegroups.com
Hi Jef, that specific example works for me. What is the output of "traceback()"?
You can check if "weighted" is an accepted argument by running
"args(rich_core)". This was added as an argument in 2018 so I don't know why you
are getting an error.

If nothing looks strange, then a hack would be to assign a "density" graph
attribute; i.e.,
UKfaculty$density <- graph.density(UKfaculty)


Chris

On Sat, Dec 21, 2019 at 01:12 AM, Jef Vlegels <jef.v...@gmail.com> wrote:

> from: Jef Vlegels <jef.v...@gmail.com>
> date: Fri, Dec 20 11:12 PM -08:00 2019
> to: brainGraph-help <brainGr...@googlegroups.com>
> reply-to: brainGr...@googlegroups.com
> subject: [brainGraph-help] rich core - weighted network
> --
> You received this message because you are subscribed to the Google Groups "brainGraph-help" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/67ba40e3-0fcd-42ee-bd32-c5671f1484a7%40googlegroups.com.

Jef Vlegels

unread,
Dec 23, 2019, 3:38:35 AM12/23/19
to brainGraph-help
Hi Chris,

Waw, that's strange. I've tried it on a server installed version of R (using same brainGraph 2.7.3 version though) and this produced the same errors. 

The traceback gives me this:
> rich_core(UKfaculty, weighted=TRUE)
Error: $ operator is invalid for atomic vectors
> traceback()
1: rich_core(UKfaculty, weighted = TRUE)

Checking the arguments:
> args(rich_core)
function (g, weighted = FALSE) 
NULL

I don't think that's really helpful? 

Also I'm afraid I don't understand how specifying the density as graph attribute helps me to solve this problem?

Thanks again,
Jef
> To unsubscribe from this group and stop receiving emails from it, send an email to brainGr...@googlegroups.com.

Chris Watson

unread,
Dec 23, 2019, 10:33:38 AM12/23/19
to brainGr...@googlegroups.com
Hi, I figured out the problem (I think). I was using a dev version of the
function. The error most likely comes from the line calculating "w_min". The
fastest way for you to fix this would be to change the code by doing

rich_core <- edit(rich_core)

Then it will open a text editor and change the "w_min" line (and the one before it) to
A <- as_adj(g, names=FALSE, sparse=FALSE, attr='weight')
w_min <- min(A[A != 0])

The reason I brought up "density" is because the "$" operator only appears once
in the dev version of the function: where it uses the "density" graph-level
attribute. The other appearance of "$" in the v2.7.3 function is in the line
calculating "w_min".

Let me know if this fixes the problem. I hope to have v3.0.0 ready to go in early 2020.
Chris

P.S. If you don't want to edit functions on the fly, you can try to explicitly
load the "Matrix" library in the namespace (i.e., call "library(Matrix)"
somewhere in your code before calling "rich_core"). This is because the v2.7.3
function uses "summary" on the sparse matrix A which relies on the "Matrix"
package. The dev version does *not* use a *sparse* matrix so avoids the "Matrix"
package.

On Mon, Dec 23, 2019 at 02:38 AM, Jef Vlegels <jef.v...@gmail.com> wrote:

> from: Jef Vlegels <jef.v...@gmail.com>
> date: Mon, Dec 23 12:38 AM -08:00 2019
> to: brainGraph-help <brainGr...@googlegroups.com>
> reply-to: brainGr...@googlegroups.com
> subject: Re: [brainGraph-help] rich core - weighted network
>> <javascript:>> wrote:
>>
>> > from: Jef Vlegels <jef.v...@gmail.com <javascript:>>
>> > date: Fri, Dec 20 11:12 PM -08:00 2019
>> > to: brainGraph-help <brainGr...@googlegroups.com <javascript:>>
>> > reply-to: brainGr...@googlegroups.com <javascript:>
>> an email to brainGr...@googlegroups.com <javascript:>.
> --
> You received this message because you are subscribed to the Google Groups "brainGraph-help" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/2522f6c0-2ccb-490e-ba3a-441c8999f8f2%40googlegroups.com.

Jef Vlegels

unread,
Dec 24, 2019, 5:21:23 AM12/24/19
to brainGraph-help
Hi Chris,

This seems to be my first Christmas present of this year, it's indeed fixed by changing the rice_core() function with your suggestions.

Thank you very much!
Jef
> To unsubscribe from this group and stop receiving emails from it, send an email to brainGr...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages