-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7models_20years.R
134 lines (115 loc) · 5.57 KB
/
7models_20years.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Script to run models on 20 year data
# Source model formulas
source('final_models.R')
library(data.table)
# Set seed
set.seed(76568)
# Run standard Negative Binomial model
#########################################################################
# 20 - YEARS
# Results for 20 year - 1.5
twenty_year1.5 <- list.files(path = "./simulated_data/d20year/theta_1.5",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
lapply(fread) %>% # Store all files in list
map(negbinner)
twenty_year1.5 <- do.call(rbind, twenty_year1.5) # Combine data sets into one data set
# check the data
head(twenty_year1.5)
# write.csv
write.csv(twenty_year1.5, "./model_results/twenty_year_1.5_metrics.csv")
#______________________________________________________________________
# Results for 20 year - 5
twenty_year5 <- list.files(path = "./simulated_data/d20year/theta_5",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
lapply(fread) %>% # Store all files in list
map(negbinner)
twenty_year5 <- do.call(rbind, twenty_year5) # Combine data sets into one data set
# check the data
head(twenty_year5)
# write.csv
write.csv(twenty_year5, "./model_results/twenty_year_5_metrics.csv")
#______________________________________________________________________
# Results for 20 year - 10
twenty_year10 <- list.files(path = "./simulated_data/d20year/theta_10",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
lapply(fread) %>% # Store all files in list
map(negbinner)
twenty_year10 <- do.call(rbind, twenty_year10) # Combine data sets into one data set
# check the data
head(twenty_year10)
# write.csv
write.csv(twenty_year10, "./model_results/twenty_year_10_metrics.csv")
#______________________________________________________________________
# Results for 20 year - 100
twenty_year100 <- list.files(path = "./simulated_data/d20year/theta_100",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
lapply(fread) %>% # Store all files in list
map(negbinner)
twenty_year100 <- do.call(rbind, twenty_year100) # Combine data sets into one data set
# check the data
head(twenty_year100)
# write.csv
write.csv(twenty_year100, "./model_results/twenty_year_100_metrics.csv")
###############################################################
##### BAYESIAN MODEL
# Run Bayesian Negative Binomial model
#########################################################################
# Results for 20 year - 1.5
twenty_year1.5b <- list.files(path = "./simulated_data/d20year/theta_1.5",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
# Use fread from data.table to read in the files and store them in a list
lapply(fread) %>%
# Use parLapply from parallel to apply stanbinner to each dataset in parallel
parLapply(cl = cl, fun = stanbinner)
twenty_year1.5b <- do.call(rbind, twenty_year1.5b) # Combine data sets into one data set
# check the data
head(twenty_year1.5b)
# write.csv
write.csv(twenty_year1.5b, "./model_results/twenty_year_1.5b_metrics.csv")
#______________________________________________________________________
# Results for 20 year - 5
twenty_year5b <- list.files(path = "./simulated_data/d20year/theta_5",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
# Use fread from data.table to read in the files and store them in a list
lapply(fread) %>%
# Use parLapply from parallel to apply stanbinner to each dataset in parallel
parLapply(cl = cl, fun = stanbinner)
twenty_year5b <- do.call(rbind, twenty_year5b) # Combine data sets into one data set
# check the data
head(twenty_year5b)
# write.csv
write.csv(twenty_year5b, "./model_results/twenty_year_5b_metrics.csv")
#______________________________________________________________________
# Results for 20 year - 10
twenty_year10b <- list.files(path = "./simulated_data/d20year/theta_10",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
# Use fread from data.table to read in the files and store them in a list
lapply(fread) %>%
# Use parLapply from parallel to apply stanbinner to each dataset in parallel
parLapply(cl = cl, fun = stanbinner)
twenty_year10b <- do.call(rbind, twenty_year10b) # Combine data sets into one data set
# check the data
head(twenty_year10b)
# write.csv
write.csv(twenty_year10b, "./model_results/twenty_year_10b_metrics.csv")
#______________________________________________________________________
# Results for 20 year - 100
twenty_year100b <- list.files(path = "./simulated_data/d20year/theta_100",
# Identify all csv files in folder
pattern = "*.csv", full.names = TRUE) %>%
# Use fread from data.table to read in the files and store them in a list
lapply(fread) %>%
# Use parLapply from parallel to apply stanbinner to each dataset in parallel
parLapply(cl = cl, fun = stanbinner)
twenty_year100b <- do.call(rbind, twenty_year100b) # Combine data sets into one data set
# check the data
head(twenty_year100b)
# write.csv
write.csv(twenty_year100b, "./model_results/twenty_year_100b_metrics.csv")