Closed HughParsonage closed 3 years ago
https://github.com/grattan/covidReff/blob/2ec1a2014a0a36eb6ccf57b12df8e08c72a7311f/R/simulate-covid.R#L171
Partly because that's what you 'really' mean (i.e. a uniform sample of integers), but also because round(runif()) undersamples edges (unless this was intended).
Consider also using dqrng for speed: (not just here but for every random variable).
dqrng
library(data.table) DT <- data.table(vaccine_type = c("pf", "az", "none")[sample(3, size = 1e6, replace = TRUE)]) bench::mark(DT[, days_since_first_dose := round(runif(.N, min = 1, max = fifelse(vaccine_type == "pf", 21, 90)))], DT[, days_since_first_dose := sample.int(if (.BY[[1]] == "pf") 21L else 90L, size = .N, replace = TRUE), by = "vaccine_type"], DT[, days_since_first_dose := dqrng::dqsample.int(if (.BY[[1]] == "pf") 21L else 90L, size = .N, replace = TRUE), by = "vaccine_type"], check = FALSE)
Will take dqrng in the PR!
Agree, and fixed in #15
https://github.com/grattan/covidReff/blob/2ec1a2014a0a36eb6ccf57b12df8e08c72a7311f/R/simulate-covid.R#L171
Partly because that's what you 'really' mean (i.e. a uniform sample of integers), but also because round(runif()) undersamples edges (unless this was intended).
Consider also using
dqrng
for speed: (not just here but for every random variable).