Open slwu89 opened 2 years ago
One way to do it is this. Because the number of rows will vary as more people become infected/vaccinated this doesn't sit well with the standard Render method of generating output.
nat_inf <- list('age' = NULL, 'inf' = NULL, 'NAT' = NULL)
nat_vaxx <- list('age' = NULL, 'vaccine' = NULL, 'NAT' = NULL)
for (i in seq_len(length.out = parameters$N_age)) {
# age/infection
bset_i <- variables$discrete_age$get_index_of(set = i)
inf_i <- variables$inf_num$get_values(index = bset_i)
ab_i <- exp(variables$ab_titre$get_values(index = bset_i))
nat_i <- vapply(X = unique(inf_i), FUN = function(inf) {
mean(ab_i[which(inf_i == inf)])
}, FUN.VALUE = numeric(1), USE.NAMES = FALSE)
nat_inf$inf <- c(nat_inf$inf, unique(inf_i))
nat_inf$age <- c(nat_inf$age, rep(i, times = length(nat_i)))
nat_inf$NAT <- c(nat_inf$NAT, nat_i)
# age/vaccine
vaxx_i <- variables$dose_num$get_values(index = bset_i)
nat_i <- vapply(X = unique(vaxx_i), FUN = function(vaxx) {
mean(ab_i[which(vaxx_i == vaxx)])
}, FUN.VALUE = numeric(1), USE.NAMES = FALSE)
nat_vaxx$vaccine <- c(nat_vaxx$vaccine, unique(vaxx_i))
nat_vaxx$age <- c(nat_vaxx$age, rep(i, times = length(nat_i)))
nat_vaxx$NAT <- c(nat_vaxx$NAT, nat_i)
}
nat_inf <- do.call(cbind, nat_inf)
nat_vaxx <- do.call(cbind, nat_vaxx)
Needs:
Requirements: