forked from eliminaterabies/egfR0
/
egf_R0.R
84 lines (61 loc) · 1.89 KB
/
egf_R0.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
library(tidyverse)
library(epigrowthfit)
library(future.apply)
library(shellpipes)
loadEnvironments()
no_cores <- availableCores() - 4
plan(multicore, workers = no_cores)
print(no_cores)
minDays <- 0
maxDays <- 100
print(interval_df)
## from once.rda
once <- (rdsRead("once")
%>% select(Biter.ID,dateGen)
%>% filter(between(dateGen,minDays,maxDays))
%>% group_by(Biter.ID)
%>% mutate(count=n())
%>% arrange(Biter.ID)
)
psimgencluster <- function(time,num,bootsample){
return(future_replicate(num,sample_clustergen(time,bootsample)))
}
simgencluster <- psimgencluster(once,num=nsamp,bootsample=nboot)
simtimesamp <- function(time,num,bootsample){
return(future_replicate(num, sample(time, size=bootsample, replace=TRUE)))
}
si <- (interval_df
%>% filter(Type == "Serial")
%>% pull(Days)
)
sisamp <- simtimesamp(si,num=nsamp,bootsample=nboot)
gi <- (interval_df
%>% filter(Type == "Generation")
%>% pull(Days)
)
egf_fit_dfs <- bind_rows(rdsRead("exp"),rdsRead("logistic"))
#egf_gi <- (egf_fit_dfs
# %>% group_by(loc,phase,egf_fit)
# %>% mutate(R0sims = map(rsamp,~simR0_data(.,time=gi,n=nsamp,bootsample=nboot)))
# %>% group_by(loc,phase,method)
# %>% reframe(R0tiles(R0sims))
# %>% mutate(interval = "Generation")
#)
print(egf_fit_dfs$rsamp)
egf_gi2 <- (egf_fit_dfs
# %>% mutate(R0sims = pmap(rsamp,~clustersimR0_data(.,time=once,n=nsamp,bootsample=nboot)))
%>% mutate(R0sims = map(rsamp,~clustersimR0_data(.,time=simgencluster)))
%>% group_by(loc,phase,method)
%>% reframe(R0tiles(R0sims))
%>% mutate(interval = "Cluster-Generation")
)
print(egf_gi2)
egf_si <- (bind_rows(rdsReadList())
# %>% group_by(loc,phase,egf_fit)
# %>% mutate(R0sims = pmap(rsamp,~simR0_data(.,time=si,n=nsamp,bootsample=nboot)))
%>% mutate(R0sims = map(rsamp,~simR0_data(.,time=sisamp)))
%>% group_by(loc,phase,method)
%>% reframe(R0tiles(R0sims))
%>% mutate(interval = "Serial")
)
saveVars(egf_gi2,egf_si,nboot,nsamp)