Skip to content

Commit

Permalink
testing deficit curves with bootstrap procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNakamura committed Nov 16, 2022
1 parent 59f7dbf commit d273781
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/PD_deficit_curves.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

PD_defict_curves <-
function(phy, data, reps, samp){
rep_boot <- rep(samps, each = reps)
rep_boot <- rep(samp, each = reps)
boot_1 <-
lapply(rep_boot, function(x){
sub_insert <- data[sample(1:nrow(data), x), ]
sub_insert <- data[sample(1:nrow(data), x, replace = TRUE), ]
PD_deficit_2(phylo = phy,
data = sub_insert,
level = c("genus_insertion",
Expand Down
58 changes: 58 additions & 0 deletions test_deficit_curves.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
library(FishPhyloMaker)
t <- readRDS("/Users/gabrielnakamura/OneDrive/Manuscritos/Darwinian_shortfalls/output/data_insertion.rds")
tree <- readRDS("/Users/gabrielnakamura/OneDrive/Manuscritos/Darwinian_shortfalls/output/tree_graft_final.rds")
orders <- names(sort(table(t$o), decreasing = TRUE))[1:10] # top ten orders with most species
t_order <- lapply(orders, function(x) t[which(t$o == x), ]) # all specie sfor each one of the ten orders
sub_samp <- seq(3, 100, 10) # sub samples for the bootstrap procedure

lapply(sub_samp, function(x){
sub_insert <- t_order[[1]][sample(1:nrow(t_order[[1]]), x), ]
PD_deficit(phylo = tree, data = sub_insert, level = c(""))
})


rep_boot <- rep(sub_samp, each = 10)
boot_1 <-
lapply(rep_boot, function(x){
sub_insert <- t_order[[1]][sample(1:nrow(t_order[[1]]), x), ]
PD_deficit_2(phylo = tree,
data = sub_insert,
level = c("genus_insertion",
"family_insertion",
"order_insertion")
)
})
boot_deficit <- do.call(rbind, boot_1)
names_boot <- paste("boot", rep_boot, sep = "_")
data.frame(boot_deficit, names_boot)
sub_insert <- t_order[[1]][sample(1:nrow(t_order[[1]]), 3), ]
PD_deficit_2(phylo = tree,
data = sub_insert,
level = c("genus_insertion",
"family_insertion",
"order_insertion")
)
PD_deficit_2(phylo = res_phylo_marine$Phylogeny,
data = insertions_marine,
level = c("genus_insertion",
"family_insertion",
"order_insertion")
)
PD_curves_orders <-
lapply(t_order, function(x){
PD_defict_curves(phy = tree, data = x, reps = 10, samp = sub_samp)
})
all_deficit <- do.call(rbind, PD_curves_orders[2:10])
all_deficit$group <- rep(paste("order", c(2:10)), each = 1500)
all_deficit$names_2 <- factor(all_deficit$names_boot, levels = unique(all_deficit$names_boot))


ggplot(data = all_deficit, aes(x = names_2, y = Darwinian_deficit, group = group, color = group)) +
geom_smooth()

ggplot() +
geom_point(data = mean_deficit, aes(x = names_2, y = mean)) +
geom_line()

match(PD_curves_orders[[1]]$names_boot)
PD_defict_curves(phy = tree, data = sub_insert, reps = 50, samp = sub_samp)

0 comments on commit d273781

Please sign in to comment.