Skip to content

Commit aca8bd3

Browse files
authored
Merge pull request #8 from seroanalytics/dev
Dev
2 parents 93300eb + 34094e1 commit aca8bd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+187
-131
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
outputs/fits/*
2-
2+
vignettes/int/*
33
# Except for the simulate_data directory
44
!outputs/fits/simulated_data/
55

.vscode/settings.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"files.associations": {
3+
"ostream": "cpp",
4+
"__bit_reference": "cpp",
5+
"__config": "cpp",
6+
"__hash_table": "cpp",
7+
"__locale": "cpp",
8+
"__node_handle": "cpp",
9+
"__split_buffer": "cpp",
10+
"__threading_support": "cpp",
11+
"__verbose_abort": "cpp",
12+
"array": "cpp",
13+
"bitset": "cpp",
14+
"cctype": "cpp",
15+
"clocale": "cpp",
16+
"cmath": "cpp",
17+
"complex": "cpp",
18+
"cstdarg": "cpp",
19+
"cstddef": "cpp",
20+
"cstdint": "cpp",
21+
"cstdio": "cpp",
22+
"cstdlib": "cpp",
23+
"cstring": "cpp",
24+
"ctime": "cpp",
25+
"cwchar": "cpp",
26+
"cwctype": "cpp",
27+
"execution": "cpp",
28+
"fstream": "cpp",
29+
"initializer_list": "cpp",
30+
"iomanip": "cpp",
31+
"ios": "cpp",
32+
"iosfwd": "cpp",
33+
"iostream": "cpp",
34+
"istream": "cpp",
35+
"limits": "cpp",
36+
"locale": "cpp",
37+
"mutex": "cpp",
38+
"new": "cpp",
39+
"optional": "cpp",
40+
"ratio": "cpp",
41+
"sstream": "cpp",
42+
"stdexcept": "cpp",
43+
"streambuf": "cpp",
44+
"string": "cpp",
45+
"string_view": "cpp",
46+
"tuple": "cpp",
47+
"typeinfo": "cpp",
48+
"unordered_map": "cpp",
49+
"variant": "cpp",
50+
"vector": "cpp",
51+
"algorithm": "cpp"
52+
}
53+
}

R/.DS_Store

-8 KB
Binary file not shown.

R/postprocess.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ plot_inf_rec <- function(model_summary, file_path) {
283283
ggsave(here::here(file_path, "infection_recov.png"), height = 10, width = 10)
284284
}
285285

286+
286287
plot_cop_rec <- function(model_summary, file_path) {
287288

288289
fitfull <- model_summary$fit

R/utils_front.R

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,32 +205,54 @@ check_sero_timings <- function(data_sero) {
205205
}
206206

207207

208+
#know_inf_df_i <- data.frame(
209+
# id = c(1, 2, 3, 4),
210+
# time = c(-1, 40, 30, -1),
211+
# start = c(1, 2, 3, 4),
212+
# type = c("in_sample", "in_sample", "in_sample", "in_sample"),
213+
# end = c(50, 70, 80, 90)
214+
#)
215+
#T <- 100
216+
#N <- 4
217+
#exp_prior_list_i <- lapply(1:N, function(x) rep(1, 100))
218+
219+
220+
#update_exp_prior(exp_prior_list_i, know_inf_df_i, T, N)
221+
222+
#known_exp <- known_inf_w2
223+
#data_sero <- sero_data_w2
224+
#exposureType <- "vac"
225+
#initialTitreTime <- data_sero %>% group_by(id) %>% filter(time == min(time)) %>% unique %>% .[["time"]]
226+
#endTitreTime <- data_sero %>% group_by(id) %>% filter(time == max(time)) %>% unique %>% .[["time"]]
227+
228+
##know_inf_df_i <- check_oos_sample_df(known_exp, exposureType, initialTitreTime, endTitreTime)
229+
#update_exp_prior(exp_prior_list, know_inf_df_i, T, N)
208230

209231
check_oos_sample_df <- function(known_exp, exposureType, initialTitreTime, endTitreTime) {
210232

211233
N <- length(endTitreTime)
212234
known_exp %>% filter(exposure_type == exposureType) %>%
213-
complete(id = 1:N, fill = list(time = -1)) %>%
235+
complete(id = 1:N, fill = list(time = -1)) %>%
214236
mutate(start = initialTitreTime, end = endTitreTime) %>%
215237
mutate(type = case_when(time >= start & time <= end ~ "in_sample", TRUE ~ "oos_sample"))
216238
}
217239

218-
update_exp_prior <- function(exp_prior_list, know_inf_df_i, T, N) {
240+
update_exp_prior <- function(exp_prior_list_par, know_inf_df_i, T, N) {
219241

220242
for (i in 1:N) {
221243
start_t <- know_inf_df_i[i, ]$start
222244
end_t <- know_inf_df_i[i, ]$end
223-
exp_prior_list[[i]][seq_len(start_t)] <- 0
224-
exp_prior_list[[i]][(end_t - 7):T] <- 0
245+
exp_prior_list_par[[i]][seq_len(start_t)] <- 0
246+
exp_prior_list_par[[i]][(end_t - 7):T] <- 0
225247

226248
if(know_inf_df_i[i, ]$time != -1 && know_inf_df_i[i, ]$type == "in_sample") {
227249
timeexp <- know_inf_df_i[i, ]$time
228-
exp_prior_list[[i]][(timeexp - 14):(timeexp + 14)] <- 0
250+
exp_prior_list_par[[i]][(timeexp - 14):(timeexp + 14)] <- 0
229251
}
230252
# normalise
231-
exp_prior_list[[i]] <- exp_prior_list[[i]] / sum(exp_prior_list[[i]])
253+
exp_prior_list_par[[i]] <- exp_prior_list_par[[i]] / sum(exp_prior_list_par[[i]])
232254
}
233-
exp_prior_list
255+
exp_prior_list_par
234256
}
235257

236258
#' @title check_exposures_times
@@ -263,15 +285,15 @@ check_exposures_times <- function(data_sero, known_exp, exposure_types, fitted_e
263285
exp_prior_list <- lapply(1:N, function(x) exp_prior$prob)
264286

265287
T <- length(exp_prior$prob)
266-
267-
know_inf_df <- map_df(exposure_types,
268-
function(exposureType) {
269-
# Get the known infections
270-
know_inf_df_i <- check_oos_sample_df(known_exp, exposureType, initialTitreTime, endTitreTime)
271-
exp_prior_list <<- update_exp_prior(exp_prior_list, know_inf_df_i, T, N)
272-
know_inf_df_i
273-
}
274-
)
288+
know_inf_df_i <- list()
289+
j <- 1
290+
for (exposureType in exposure_types) {
291+
# Get the known infections
292+
know_inf_df_i[[j]] <- check_oos_sample_df(known_exp, exposureType, initialTitreTime, endTitreTime)
293+
exp_prior_list <- update_exp_prior(exp_prior_list, know_inf_df_i[[j]], T, N)
294+
j <- j + 1
295+
}
296+
know_inf_df <- know_inf_df_i %>% bind_rows
275297

276298
# Get information on people
277299
outside_obs <- know_inf_df %>% filter(!is.na(exposure_type), type == "oos_sample") %>% pull(id)

R/utils_model.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ createSeroJumpModel <- function(
209209
know_inf <- know_inf_df %>%
210210
mutate(time = case_when(time >= initialTitreTime & time <= endTitreTime ~ time, TRUE ~ -1)) %>%
211211
pull(time)
212-
exp_prior_list <<- update_exp_prior(exp_prior_list, know_inf_df, data_t$T, data_t$N)
212+
213+
exp_prior_list <- update_exp_prior(exp_prior_list, know_inf_df, data_t$T, data_t$N)
213214
}
214215
}
215216

@@ -222,7 +223,6 @@ createSeroJumpModel <- function(
222223
data_t$knownInfsN = length(know_inf[know_inf > -1])
223224
}
224225
}
225-
226226
knownNoneInfsVec <- vector(mode = "numeric", length = data_t$N)
227227
for (i in 1:data_t$N) {
228228
if(sum(exp_prior_list[[i]]) == 0 && data_t$knownInfsVec[i] == -1 ) {
@@ -238,14 +238,15 @@ createSeroJumpModel <- function(
238238
data_t$knownExpVec <- data_t$knownInfsTimeVec
239239
}
240240

241-
# exp_prior_list <- rep(exp_prior$prob, N)
242-
# data_t <- calculateIndExposure(modelSeroJump, data_t, infPriorTime, type = infPriorTimeType)
243-
244241
# Code to check form of exp_prior
245242
modelSeroJump$exposureFunctionSample <- function(i) {
246243
sample(1:length(exp_prior_list[[i]]), 1, prob = exp_prior_list[[i]])
247244
}
248245

246+
if (!is.null(data_known)) {
247+
check_exposures_times(data_sero, data_known, exposureTypes, exposureFitted, exposurePriorTime, exposurePriorTimeType)
248+
}
249+
249250
data_t$exp_list <- exp_prior_list
250251
data_t$exp_prior <- exp_prior
251252

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/cs1_sim_recovery.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)