diff --git a/.Rprofile b/.Rprofile index cae50de..a9fbfb2 100644 --- a/.Rprofile +++ b/.Rprofile @@ -1 +1 @@ -options(repos=structure(c(CRAN="http://cran.us.r-project.org"))) +options(repos=structure(c(CRAN="https://cloud.r-project.org/"))) diff --git a/.gitignore b/.gitignore index 138866d..44ac001 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .Ruserdata inst/doc docs +dev_history.R diff --git a/DESCRIPTION b/DESCRIPTION index edaacc3..45db86c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,37 +2,45 @@ Type: Package Package: EMtree Title: Infers Direct Species Association Networks using Tree Averaging Version: 1.1.0 -Author: Raphaelle Momal -Maintainer: Raphaelle Momal -Description: Uses averages over spanning trees within an Expectation Maximization algorithm to infer conditional dependence networks. Involves plotting functionalities. +Authors@R: c( + person("Raphaëlle", "Momal", role = c("aut", "cre","cph"), email = "rmomaleisenring@gmail.com", + comment = c(ORCID = "0000-0002-1550-4530"))) +Description: The spanning tree averaging within an Expectation-Maximization algorithm + (Momal, Robin and Ambroise, 2020 ) leverages the + Matrix Tree Theorem to infer conditional dependence networks, such as direct species association + networks. License: GPL-3 Imports: dplyr, ggplot2, ggraph, huge, - influenceR, magrittr, Matrix, mvtnorm, parallel, PLNmodels, - purrr, tibble, tidygraph, - tidyr, vegan, + gridExtra, + pillar, ade4, - gridExtra + viridis, + gmp Suggests: testthat (>= 2.1.0), knitr, rmarkdown, networkD3, + pROC, + tidyr, RColorBrewer Encoding: UTF-8 -LazyData: false -RoxygenNote: 7.1.1 +LazyData: true +RoxygenNote: 7.3.2 +Depends: R (>= 3.5) VignetteBuilder: knitr URL: https://rmomal.github.io/EMtree/ BugReports: https://github.com/Rmomal/EMtree/issues +Language: en-US diff --git a/R/F_inference.R b/R/F_inference.R index 378e80c..7141f64 100644 --- a/R/F_inference.R +++ b/R/F_inference.R @@ -410,8 +410,8 @@ ResampleEMtree <- function(counts,covar_matrix=NULL, unlinked=NULL, #- parallel computation of S fits of new_EMtree if(is.null(user_covariance_estimation)){ suppressWarnings( - PLNfit <- PLNmodels::PLN(counts ~ -1 + offset(log(O)) + ., - data=data.frame(X),control=list("trace"=0)) + PLNfit <- PLNmodels::PLN(formula=counts ~ -1 + offset(log(O)) + ., + data=data.frame(X),control=PLN_param(trace=0)) )} obj<-parallel::mclapply(1:S,function(b){ if(init){ diff --git a/README.Rmd b/README.Rmd index 23f9080..bbf01b0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -28,9 +28,9 @@ By default, it uses the Poisson log-Normal Model ([PLNmodels](https://github.com ### CRAN dependencies ```{r,eval=FALSE} -required_CRAN <- c("Matrix", "purrr","parallel", "mvtnorm", "vegan","huge", - "ggplot2", "magrittr", "dplyr","tidyr", "tibble", - "PLNmodels","ggraph", "tidygraph", "ade4") +required_CRAN <- c("Matrix", "parallel", "mvtnorm", "vegan", + "ggplot2", "magrittr", "dplyr", "tibble", + "PLNmodels","ggraph", "tidygraph","huge") not_installed_CRAN <- setdiff(required_CRAN, rownames(installed.packages())) if (length(not_installed_CRAN) > 0) install.packages(not_installed_CRAN) ``` diff --git a/README.md b/README.md index 205e588..b8e6b64 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ copulas, or Gaussian data transformations. ### CRAN dependencies ``` r -required_CRAN <- c("Matrix", "purrr","parallel", "mvtnorm", "vegan","huge", - "ggplot2", "magrittr", "dplyr","tidyr", "tibble", - "PLNmodels","ggraph", "tidygraph", "ade4") +required_CRAN <- c("Matrix", "parallel", "mvtnorm", "vegan", + "ggplot2", "magrittr", "dplyr", "tibble", + "PLNmodels","ggraph", "tidygraph","huge") not_installed_CRAN <- setdiff(required_CRAN, rownames(installed.packages())) if (length(not_installed_CRAN) > 0) install.packages(not_installed_CRAN) ``` diff --git a/cran-comments.md b/cran-comments.md index aee4e45..a2e7020 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,10 +1,13 @@ ## Test environments -* local R installation, R 4.0.2 -* ubuntu 16.04 (on travis-ci), R 4.0.2 -* win-builder (devel) +- R-hub fedora-clang-devel (r-devel) +- R-hub windows-x86_64-devel (r-devel) +- R-hub macos-highsierra-release (r-release) ## R CMD check results +> On fedora-clang-devel (r-devel), windows-x86_64-devel (r-devel) + checking CRAN incoming feasibility ... NOTE + Maintainer: ‘Raphaelle Momal ’ + + New submission -0 errors | 0 warnings | 1 note - -* This is a new release. +0 errors ✓ | 0 warnings ✓ | 1 note x diff --git a/dev_history.R b/dev_history.R index a070827..cc5d078 100644 --- a/dev_history.R +++ b/dev_history.R @@ -13,6 +13,7 @@ attachment::att_to_description() use_build_ignore("dev_history.R") usethis::use_vignette("Fatala_Net","Fatala fishes") +usethis::use_vignette("Partial_correlations","Partial correlations") pkgdown::build_site() # workflow @@ -44,14 +45,14 @@ covr::report() results <- rhub::check_for_cran(platforms=c("fedora-clang-devel", "windows-x86_64-devel", "macos-highsierra-release")) - +results2 <- rhub::check_for_cran() # Get the summary of your results -results$cran_summary() +results2$cran_summary() # Generate your cran-comments.md, then you copy-paste the output from the function above usethis::use_cran_comments() devtools::check_win_devel() usethis::use_news_md(open = rlang::is_interactive()) - +devtools::release() diff --git a/docs/.DS_Store b/docs/.DS_Store index 2adaebd..d6253b8 100644 Binary files a/docs/.DS_Store and b/docs/.DS_Store differ diff --git a/tests/.DS_Store b/tests/.DS_Store index 6930394..7ca28c7 100644 Binary files a/tests/.DS_Store and b/tests/.DS_Store differ diff --git a/tests/testthat/test-F_Graphs.R b/tests/testthat/test-F_Graphs.R index d6c54f1..6283a30 100644 --- a/tests/testthat/test-F_Graphs.R +++ b/tests/testthat/test-F_Graphs.R @@ -4,9 +4,7 @@ library(PLNmodels) library(parallel) library(tidygraph) library(ggraph) -library(purrr) library(dplyr) -library(tidyr) library(gridExtra) ########################## n<-30 diff --git a/tests/testthat/test-F_inference.R b/tests/testthat/test-F_inference.R index 73bdb0f..53c78f2 100644 --- a/tests/testthat/test-F_inference.R +++ b/tests/testthat/test-F_inference.R @@ -6,8 +6,6 @@ library(dplyr) library(vegan) library(Matrix) library(mvtnorm) -library(tidyr) -library(EMtree) ########################## n<-30 p<-10 diff --git a/tests/testthat/test-test_gener_data.R b/tests/testthat/test-test_gener_data.R index 065372a..15a435a 100644 --- a/tests/testthat/test-test_gener_data.R +++ b/tests/testthat/test-test_gener_data.R @@ -6,7 +6,6 @@ library(dplyr) library(vegan) library(Matrix) library(mvtnorm) -library(tidyr) library(EMtree) ########################## n<-100 diff --git a/vignettes/.DS_Store b/vignettes/.DS_Store new file mode 100644 index 0000000..0b4ac76 Binary files /dev/null and b/vignettes/.DS_Store differ diff --git a/vignettes/Fatala_Net.Rmd b/vignettes/Fatala_Net.Rmd index 8434edc..f3bed38 100644 --- a/vignettes/Fatala_Net.Rmd +++ b/vignettes/Fatala_Net.Rmd @@ -208,6 +208,3 @@ forceNetwork(Links = graph_d3$links, Nodes =graph_d3$nodes, Source = 'source', Target = 'target', NodeID = 'name', Group = 'group',opacity = 1,fontSize = 15, legend=TRUE) ``` - - - diff --git a/vignettes/Partial_correlations.Rmd b/vignettes/Partial_correlations.Rmd new file mode 100644 index 0000000..c6788c7 --- /dev/null +++ b/vignettes/Partial_correlations.Rmd @@ -0,0 +1,65 @@ +--- +title: "Partial correlations" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Partial correlations} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + cache=TRUE +) +library(ggplot2) +library(dplyr) +library(tidyr) +library(magrittr) +``` + +```{r setup} +library(EMtree) +``` + +# Partial correlations simulation + +```{r} +set.seed(1) +p=300 +n=400 +simulation<-data_from_scratch(type="erdos",p=p,n=n,signed=TRUE, dens=3/p) +G=1*(simulation$omega!=0) ; diag(G) = 0 +draw_network(G, remove_isolated = TRUE, pal_edges = "gray70",pal_nodes = "steelblue",btw_rank = 1)$G +``` +simulated partial correlation matrix : +```{r} +ParCor <- - cov2cor(simulation$omega) +``` + +```{r} +ParCor %>% ToVec() %>% as_tibble() %>% filter(value!=0) %>% + ggplot(aes(value))+geom_histogram(alpha=0.8)+ + theme_light()+labs(title="Repartition of non-nul partial correlations", + x="Partial correlation values") + +``` + + +# Inference + +```{r} +EMtreefit<-ResampleEMtree(simulation$data,S = 30,cores = 3) +stab_selection=StATS(EMtreefit$Pmat, nlambda=50, stab.thresh=0.8,plot=TRUE) +``` + +```{r} +net90=ToSym(1*(stab_selection$freqs_opt>0.95)) +table(net90, G) +library(PRROC) +pr<-pr.curve(scores.class0 = stab_selection$freqs_opt, + scores.class1 = ToVec(G)) +pr +``` +