Giter Site home page Giter Site logo

bipartite's Introduction

bipartite

repository for the bipartite R-package for network analysis

Hi,

this is the bipartite repository on github. Currently this package is maintained by Carsten Dormann, that's why the repository is hosted under this department.

It falls onto the maintainer to submit new versions to CRAN for release. All non-CRAN-versions are in development, which you can install using the following code (only if you have the tool-chain installed, see R instructions):

library(devtools)
install_github("biometry/bipartite/bipartite")

If you want to add/change something, please add as many comments as possible into the R-code (to make other understand what you are doing), edit the .Rd help file accordingly (here you can use LaTeX-style comments using the %), and finally edit the file bipartite-package.Rd in the versioning section, making users aware of what you have added/changed.

For maximal confusion, the actual package content is in the "bipartite" subfolder, while other material (such as test files, wishlists, comments, the current working package compiled etc.) are directly in this folder.

Carsten

bipartite's People

Contributors

cdormann avatar jarioksa avatar jochenfruend avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bipartite's Issues

Modularity analysis using Dormann and Strauss, 2014 method

Hi!
I am conducting an ecological analysis of a metavirome using the computeModules function. I´ve been able to compute the modules and plot them, but I always get warning messages saying that the matrix length of the modules object and the original web are not same, and because of that I believe that not all nodes are displayed. I attach you my code and the warning messages:

otus.net <- graph.data.frame(links.net, nodes.net, directed = FALSE)

otus.net.adj <- get.adjacency(otus.net, sparse = FALSE, names = TRUE)
modules.net <- computeModules(otus.net.adj, deep = FALSE, tolerance = 1e-10)

plotModuleWeb(modules.net, plotModules = TRUE,
              rank = FALSE, weighted = FALSE, displayAlabels = TRUE,
              displayBlabels = TRUE, labsize = 1, xlabel = "", ylabel = "",
              square.border = "white", fromDepth = 0, upToDepth = -1)

I´ve used upToDepth = -1 with the idea of plotting all modules (If upToDepth is smaller
than fromDepth, all modules are plot)

Warning messages:
1: In dim(slot(moduleWebObject, "originalWeb")) == 0 || dim(slot(moduleWebObject, :
'length(x) = 2 > 1' in coercion to 'logical(1)'
2: In dim(slot(moduleWebObject, "originalWeb")) == 0 || dim(slot(moduleWebObject, :
'length(x) = 2 > 1' in coercion to 'logical(1)'
3: In dim(slot(moduleWebObject, "originalWeb")) == 0 || dim(slot(moduleWebObject, :
'length(x) = 2 > 1' in coercion to 'logical(1)'

Info about R session:

sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.utf8  LC_CTYPE=Spanish_Spain.utf8   
[3] LC_MONETARY=Spanish_Spain.utf8 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.utf8    

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

other attached packages:
 [1] pheatmap_1.0.12      RColorBrewer_1.1-3   forcats_1.0.0       
 [4] stringr_1.5.0        dplyr_1.1.0          purrr_1.0.1         
 [7] readr_2.1.4          tidyr_1.3.0          tibble_3.1.8        
[10] tidyverse_1.3.2      readxl_1.4.2         dendextend_1.17.1   
[13] factoextra_1.0.7     ggplot2_3.4.1        cluster_2.1.4       
[16] igraph_1.4.0         relaimpo_2.2-6       mitools_2.4         
[19] survey_4.1-1         survival_3.5-0       Matrix_1.5-3        
[22] boot_1.3-28.1        MASS_7.3-58.2        bipartite_2.18      
[25] sna_2.7-1            network_1.18.1       statnet.common_4.8.0
[28] vegan_2.6-4          lattice_0.20-45      permute_0.9-7       

loaded via a namespace (and not attached):
 [1] viridis_0.6.2       httr_1.4.4          maps_3.4.1         
 [4] jsonlite_1.8.4      viridisLite_0.4.1   splines_4.2.2      
 [7] modelr_0.1.10       dotCall64_1.0-2     assertthat_0.2.1   
[10] googlesheets4_1.0.1 cellranger_1.1.0    ggrepel_0.9.3      
[13] pillar_1.8.1        backports_1.4.1     glue_1.6.2         
[16] rvest_1.0.3         colorspace_2.1-0    pkgconfig_2.0.3    
[19] broom_1.0.3         haven_2.5.1         corpcor_1.6.10     
[22] scales_1.2.1        tzdb_0.3.0          timechange_0.2.0   
[25] googledrive_2.0.0   mgcv_1.8-41         generics_0.1.3     
[28] ellipsis_0.3.2      withr_2.5.0         cli_3.6.0          
[31] crayon_1.5.2        magrittr_2.0.3      fs_1.6.1           
[34] fansi_1.0.4         nlme_3.1-162        xml2_1.3.3         
[37] tools_4.2.2         hms_1.1.2           gargle_1.3.0       
[40] lifecycle_1.0.3     reprex_2.0.2        munsell_0.5.0      
[43] compiler_4.2.2      rlang_1.0.6         rstudioapi_0.14    
[46] spam_2.9-1          gtable_0.3.1        DBI_1.1.3          
[49] R6_2.5.1            gridExtra_2.3       lubridate_1.9.2    
[52] utf8_1.2.3          stringi_1.7.12      parallel_4.2.2     
[55] Rcpp_1.0.10         fields_14.1         vctrs_0.5.2        
[58] dbplyr_2.3.0        tidyselect_1.2.0    coda_0.19-4 

Is this related with the window size or with the length of the matrix? Many thanks in advance for your support,

Best

Error from specieslevel function

Hi all,

I am trying to run an analysis at the species level, but I am getting the error:
Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array extent

We could think there was something wrong with the structure of my data, however, I got the network level metrics with the same dataset. Also, my data are arranged in the same way as the Safariland data. This is one of my datasets:

dataset_example

Do you have any idea of what could be wrong?

Cheers,

Bug in function "robustness"

Dear Carsten,

There is a bug in function "robustness" of bipartite 2.14. These are the first two lines of its code:
if (is(object, "bipartite"))
stop("This function cannot be meaningfully applied to objects of this class.")

It should be ' if (!is(object, "bipartite")) ' since function "second.extinct" returns object in class "bipartite". Please have a check.

Best,

Hanlun

bug in second.extinct / extinction?

Dear Carsten,

There seems to be a problem in the second.extinct function (or in the extinction function). When you run it with the "abundance" method on "lower", there are special cases for which only one column will be left in m2 (after i iterations in the repeat loop), which will cause problems in the extinction function (L40). Example:

web <- matrix(c(3, 2, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1),
ncol = 3)
second.extinct(web, participant = "lower", method = "abundance")

From my understanding, the problem could be solved by changing line 39 in extinction to

web <- web[sample(1:nrow(web)), sample(1:ncol(web)), drop = FALSE]

or by changing line 38 in second.extinct to

 if (any(dim(m2) == 1)) break;

Seems to yield the same result. Or do I miss something?

Best,
Felix

web <- web[sample(1:nrow(web)), sample(1:ncol(web))]

null.t.test with "cluster coefficient"

Hi,

Sorry I'm new to network analysis, so maybe there's something I missed.
I've try the null.t.test() function with some basic networklevel indicators on a matrix.
I've got this error when I add the "cluster coefficient" in the index list :

Nulltestem2nw <-null.t.test(em2nw, index=c("generality", "vulnerability", "connectance","links per species","cluster coefficient"), nrep=4, N=20)

"Error in t.test.default(unlist(res[i, ]), mu = obs[[i]], na.action = na.omit) : 
  data are essentially constant
Erreur : $ operator is invalid for atomic vectors"

When I tried to get the resulst for cluster coefficient only, it seems to be working.
But even if I specify the level, the observed value remains the cluster coefficient of the whole network :

  1. without specifying the level
NulltestCC <-null.t.test(em2nw, index=c("cluster coefficient"), nrep=4, N=20)
 NulltestCC
                           obs  null mean   lower CI  upper CI       t            P
cluster coefficient 0.03389831 0.09463569 0.07921827 0.1100531 7.88298 8.632008e-11
  1. specifying for higher level (observed result should be 0.09279116)
NulltestHCC <-null.t.test(em2nw, index=c("cluster coefficient"),level = "higher", nrep=4, N=20)
NulltestHCC
                           obs  null mean   lower CI  upper CI        t            P
cluster coefficient 0.03389831 0.05452801 0.04784492 0.0612111 6.243745 2.375485e-07

3 Networklevel indicators of my "em2nw" matrix

        connectance                  web asymmetry              links per species            cluster coefficient                      
                0.05458834                     0.92643392                     3.10224439                     0.03389831                     
                               cluster.coefficient.HL         cluster.coefficient.LL 
                                                0.09279116                     0.23278832 

Thank you for all the work.

non-normalised C.score and checker are NOT the same

HI @cdormann,
I follow the example code of nested function and, in my result, non-normalised C.score and checker have not the same result, I just run the example in the function:

data(Safariland)
nested(Safariland, "ALL")
nested(Safariland, "ALL", rescale=TRUE)

illustration that non-normalised C.score and checker are the same:

nested(Safariland, c("C.score", "checker"), normalise=FALSE)

This is my result:
C.score checker
0.5616097 1.0227920

thanks!

plotModuleWeb() throws length error!

Hi, I was trying to plot the modules--I don't think I have problems with running the modularity computation, but when it comes to plotting it ALWAYS gives me this error.

> library(bipartite)
Loading required package: vegan
Loading required package: permute
Loading required package: lattice
This is vegan 2.6-4
Loading required package: sna
Loading required package: statnet.common

Attaching package: ‘statnet.common’

The following objects are masked from ‘package:base’:

    attr, order

Loading required package: network

‘network’ 1.18.1 (2023-01-24), part of the Statnet Project
* ‘news(package="network")’ for changes since last version
* ‘citation("network")’ for citation information
* ‘https://statnet.org’ for help, support, and other information

sna: Tools for Social Network Analysis
Version 2.7-1 created on 2023-01-24.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
 For citation information, type citation("sna").
 Type help(package="sna") to get started.

 This is bipartite 2.18.
 For latest changes see versionlog in ?"bipartite-package". For citation see: citation("bipartite").
 Have a nice time plotting and analysing two-mode networks.

Attaching package: ‘bipartite’

The following object is masked from ‘package:vegan’:

    nullmodel

> data(small1976)
> moduleWebObject = computeModules(small1976)
> plotModuleWeb(moduleWebObject)
Error in dim(slot(moduleWebObject, "originalWeb")) == 0 || dim(slot(moduleWebObject,  : 
  'length = 2' in coercion to 'logical(1)'

Error with H2_integer = F option of H2fun()

Hi,

When using the H2_integer = F option of H2fun() function, the function return an error indicating H2_max is not defined (at line 102). If I understand well, I would suppose copying line 49 just after the line 32. It should make the job by defining H2_max.

Alternatively, the condition on line 102 may be kept only for cases where H2_integer = T since when it's not the case H2_max.improved = H2_max (assuming this later is defined...)
H2_max <- ifelse(H2_integer && H2_max >= H2_max.improved, H2_max, H2_max.improved)

Best whishes,

max

Can't install from the repository

Hi, I'm trying to install the dev version to be able to run modularity analyses (getting the same thing reported in #16 which seems to have been fixed in c29d225 ). However, I'm getting the following error:

Error: Failed to install 'bipartite' from GitHub:
  input string 1 is invalid
In addition: Warning message:
In gsub("\n([^[:blank:]])", "\n \\1", val) :
  unable to translate 'c(person(given = "Carsten F.",
                    family = "Dormann",
                    role = c("aut", "cre"),
                    email = "[email protected]",
                    comment = c(ORCID = "0000-0002-9835-1794")),
    ...' to a wide string

Issue using H2fun()

I am running H2fun() of the 'bipartite' class in R studio using R version 3.6.1.

Inputting a 20x20 matrix of non-integers where the values is each column sum to 1, it appears that when I run this function with H2_integer set to false, H2_max is never defined before the comparison with H2_max.improved is performed

The error message is:

Error in ifelse(H2_max >= H2_max.improved, H2_max, H2_max.improved) :
object 'H2_max' not found

Looking at the source code it appears that the line:

H2_max <- -sum(newweb/tot*log(newweb/tot), na.rm=TRUE) # first attempt of finding H2_max

only executes in the else block where H2_integer is TRUE.

Why does the order of the species in the adjacency matrix makes a difference with some indices?

Thank you for this great work on bipartite!

I observed that the order of the species in the adjacency matrix makes a difference with some indices when using the function networklevel (Not shown below, but this also happens with specieslevel). Below is an example using the Safariland data.

The species' names come in a particular order. I noticed that if I alter that order, I can get differences in some network indices and this seems unexpected for me. Would you help me understand why is it so?

library(bipartite)

# Compute all network indices
set.seed(1) # to be sure is not because of the random number generation, I set its state here
net_1 <- bipartite::networklevel(web = Safariland)

# Shuffle column names
set.seed(1)
Safariland_2 <- Safariland[, sample(colnames(Safariland))]

set.seed(1)
net_2 <- networklevel(web = Safariland_2)

# The two results are different
identical(net_1, net_2)
## FALSE

# Not all metrics change, but here are the ones where differences appear:
net_df <- data.frame(net_1, net_2)
net_df$dif <- net_df$net_1 - net_df$net_2
net_df[net_df$dif != 0,]

##                          net_1      net_2         dif
## nestedness          19.9081024 19.8819392  0.02616325
## weighted nestedness  0.3852073  0.4056451 -0.02043776
## discrepancy.HL      21.0000000 19.0000000  2.00000000
## extinction.slope.HL  2.6650877  2.8054999 -0.14041217
## extinction.slope.LL  1.3179904  1.3745174 -0.05652698
## robustness.HL        0.7186344  0.7302413 -0.01160692
## robustness.LL        0.5640681  0.5760280 -0.01195993

Also if I order alphabetically the column names, I get different results:

Safariland_3 <- Safariland[, sort(colnames(Safariland))]

set.seed(1)
net_3 <- networklevel(web = Safariland_3)

net_df <- data.frame(net_1, net_3)
net_df$dif <- net_df$net_1 - net_df$net_3
net_df[net_df$dif != 0,]

##                                      net_1        net_4           dif
## nestedness                      19.9081024   19.7548961  0.1532062840
## weighted nestedness              0.3852073    0.4095266 -0.0243192413
## togetherness.HL                  0.1606838    0.1785375 -0.0178537512
## discrepancy.HL                  21.0000000   22.0000000 -1.0000000000
## extinction.slope.HL              2.6650877    2.6336544  0.0314333647
## extinction.slope.LL              1.3179904    1.3208604 -0.0028699917
## robustness.HL                    0.7186344    0.7202266 -0.0015922022
## robustness.LL                    0.5640681    0.5643816 -0.0003134797
## functional.complementarity.HL 1683.8042072 1683.7006539  0.1035533906

Information About the R Session:

sessionInfo()
## R version 4.1.0 (2021-05-18)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.2 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] bipartite_2.16       sna_2.6              network_1.17.1      
## [4] statnet.common_4.5.0 vegan_2.5-7          lattice_0.20-44     
## [7] permute_0.9-5       
## 
## loaded via a namespace (and not attached):
##  [1] spam_2.7-0        tidyselect_1.1.1  xfun_0.24         purrr_0.3.4      
##  [5] splines_4.1.0     colorspace_2.0-2  vctrs_0.3.8       generics_0.1.0   
##  [9] htmltools_0.5.1.1 viridisLite_0.4.0 yaml_2.2.1        mgcv_1.8-36      
## [13] utf8_1.2.1        rlang_0.4.11      pillar_1.6.1      glue_1.4.2       
## [17] DBI_1.1.1         lifecycle_1.0.0   stringr_1.4.0     fields_12.5      
## [21] dotCall64_1.0-1   munsell_0.5.0     gtable_0.3.0      coda_0.19-4      
## [25] evaluate_0.14     knitr_1.33        parallel_4.1.0    fansi_0.5.0      
## [29] highr_0.9         scales_1.1.1      gridExtra_2.3     ggplot2_3.3.5    
## [33] digest_0.6.27     stringi_1.7.3     dplyr_1.0.7       grid_4.1.0       
## [37] tools_4.1.0       magrittr_2.0.1    maps_3.3.0        tibble_3.1.2     
## [41] cluster_2.1.2     crayon_1.4.1      pkgconfig_2.0.3   MASS_7.3-54      
## [45] ellipsis_0.3.2    Matrix_1.3-4      assertthat_0.2.1  rmarkdown_2.9    
## [49] viridis_0.6.1     R6_2.5.0          igraph_1.2.6      nlme_3.1-152     
## [53] compiler_4.1.0

Unable to install from github--input string 1 is invalid

Please see the attched.

> library(devtools)
Loading required package: usethis
> install_github("biometry/bipartite/bipartite")
Downloading GitHub repo biometry/bipartite@HEAD
Error: Failed to install 'bipartite' from GitHub:
  input string 1 is invalid
In addition: Warning message:
In gsub("\n([^[:blank:]])", "\n \\1", val) :
  unable to translate 'c(person(given = "Carsten F.",
                    family = "Dormann",
                    role = c("aut", "cre"),
                    email = "[email protected]",
                    comment = c(ORCID = "0000-0002-9835-1794")),
    ...' to a wide string

NODF values should range from 0 to 1

It looks like the output from the networklevel() function reports values for NODF and weighted NODF greater than 1 when these values should range from [0, 1]. I believe the issue is that the function is reporting e+01 when it should be e-01

image

Error in install

I get this error when I try and install via devtools::install_github("biometry/bipartite/bipartite").

I have tried devtools::install_github("biometry/bipartite/bipartite", build_vignettes = FALSE) as well but get the same error:

── R CMD build ──────────────────────────────────────────────────────────────────────────────────────
✔ checking for file 'C:\Users\matthew.grainger\AppData\Local\Temp\RtmpwZ1RRm\remotes1f5c4371896\biometry-bipartite-dfebfd3\bipartite/DESCRIPTION' (612ms)
─ preparing 'bipartite': (2.8s)
✔ checking DESCRIPTION meta-information ...
─ cleaning src
E checking vignette meta-information (341ms)
Output(s) listed in 'build/vignette.rds' but not in package:
'inst/doc/Intro2bipartite.pdf'
Run R CMD build without --no-build-vignettes to re-create
Error: Failed to install 'bipartite' from GitHub:
! System command 'Rcmd.exe' failed

Issue using networklevel()

I tried to use networklevel function to produce network indices for a non-integer matrix, but unfortunately I 've always received the same error message:"Error in ifelse(H2_max >= H2_max.improved, H2_max, H2_max.improved) :
object 'H2_max' not found".
I retried using different non-integer matrices, I tried using instead the H2_fun() but I kept receiving the same error no matter if H2_integer was set to FALSE or TRUE.
What can I do to resolve this issue?
Thank you in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.