knitr::opts_chunk$set( collapse = TRUE, comment = "##", eval = F )
In this file, we show the memory and time used for phyr::communityPGLMM()
. It seems that for Gaussian models, use bobyqa
as optimizer can save time and memory. But for Binomial models, the optimizer does not affect too much. Thus, may use Nelder-Mead
for its robustness.
Also, note the hugh differences in memory usage between cpp = TRUE
and cpp = FALSE
.
First, let's prepare some toy data.
library(profvis) library(dplyr, quietly = TRUE) library(phyr) comm = comm_a comm$site = row.names(comm) dat = tidyr::gather(comm, key = "sp", value = "freq", -site) %>% left_join(envi, by = "site") %>% left_join(traits, by = "sp") dat$pa = as.numeric(dat$freq > 0) cov_ranef = list(sp = phylotree)
Then, we start the profvis.
bobyqa
with Rprofvis({ phyr::communityPGLMM(freq ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, cov_ranef = list(sp = phylotree), REML = TRUE, cpp = FALSE, optimizer = "bobyqa") })
bobyqa
with Rcppprofvis({ phyr::communityPGLMM(freq ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, cov_ranef = list(sp = phylotree), REML = TRUE, cpp = TRUE, optimizer = "bobyqa") })
Nelder-Mead
with Rprofvis({ phyr::communityPGLMM(freq ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, cov_ranef = list(sp = phylotree), REML = TRUE, cpp = FALSE, optimizer = "Nelder-Mead") })
Nelder-Mead
with Rcppprofvis({ phyr::communityPGLMM(freq ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, cov_ranef = list(sp = phylotree), REML = TRUE, cpp = TRUE, optimizer = "Nelder-Mead") })
bobyqa
with Rprofvis({ phyr::communityPGLMM(pa ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, family = "binomial", cov_ranef = list(sp = phylotree), REML = TRUE, cpp = FALSE, optimizer = "bobyqa") })
bobyqa
with Rcppprofvis({ phyr::communityPGLMM(pa ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, family = "binomial", cov_ranef = list(sp = phylotree), REML = TRUE, cpp = TRUE, optimizer = "bobyqa") })
Nelder-Mead
with Rprofvis({ phyr::communityPGLMM(pa ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, family = "binomial", cov_ranef = list(sp = phylotree), REML = TRUE, cpp = FALSE, optimizer = "Nelder-Mead") })
Nelder-Mead
with Rcppprofvis({ phyr::communityPGLMM(pa ~ 1 + shade + (1|sp__) + (1|site) + (1|sp@site), dat, family = "binomial", cov_ranef = list(sp = phylotree), REML = TRUE, cpp = TRUE, optimizer = "Nelder-Mead") })
psv
with Rprofvis({ psv(comm_sim, tree_sim, cpp = FALSE) })
psv
with Rcppprofvis({ x <- psv(comm_sim, tree_sim, cpp = TRUE) }) microbenchmark::microbenchmark(psv(comm, tree, cpp = FALSE), psv(comm, tree, cpp = TRUE), times = 100) microbenchmark::microbenchmark(pse(comm, tree, cpp = FALSE), pse(comm, tree, cpp = TRUE), times = 100)
phy = ape::rtree(n = 10000) profvis({ ape::vcv(phy, corr = TRUE) }) profvis({ vcv2(phy, corr = TRUE) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.