lamho86 / phylolm

GNU General Public License v2.0
30 stars 12 forks source link

Implement parallel bootstrap to glm (#10) #12

Closed Ax3man closed 6 years ago

Ax3man commented 6 years ago

Following issue #10, and PR #11, here is the same parallel bootstrap implementation, but for phyloglm.

Results are the practically the same with the new and old function:

library(phylolm)
set.seed(123456)
tre = rtree(50)
x = rTrait(n=1,phy=tre)
X = cbind(rep(1,50),x)
y = rbinTrait(n=1,phy=tre, beta=c(-1,0.5), alpha=1 ,X=X)
dat = data.frame(trait01 = y, predictor = x)

fit_old_MPLE <- phyloglm_old(trait01~predictor,phy=tre,data=dat,boot=5000, method = 'logistic_MPLE')
fit_old_IG10 <- phyloglm_old(trait01~predictor,phy=tre,data=dat,boot=5000, method = 'logistic_IG10')
fit_new_MPLE <- phyloglm(trait01~predictor,phy=tre,data=dat,boot=5000, method = 'logistic_MPLE', parallel = "SOCK")
fit_new_IG10 <- phyloglm(trait01~predictor,phy=tre,data=dat,boot=5000, method = 'logistic_IG10', parallel = "SOCK")

library(dplyr)
library(tidyr)
library(ggplot2)
result <- bind_rows(old_MPLE = as.data.frame(fit_old_MPLE$bootstrap), 
                    new_MPLE = as.data.frame(fit_new_MPLE$bootstrap), 
                    old_IG10 = as.data.frame(fit_old_IG10$bootstrap), 
                    new_IG10 = as.data.frame(fit_new_IG10$bootstrap),
                    .id = 'version') %>% 
  mutate(version = factor(version, unique(version)))
ggplot(gather(result, 'parameter', 'value', -version), aes(version, value)) +
  geom_violin(draw_quantiles = c(0.25, 0.5, 0.75), fill = 1, alpha = 0.1) + 
  facet_wrap(~parameter, scales = 'free_y', nr = 1) +
  theme_minimal()

Let me know if you need anything else related to this!

rplot

lamho86 commented 6 years ago

This is great! Thanks.