Skip to content
Snippets Groups Projects
Commit e41e58a2 authored by pqiao29's avatar pqiao29
Browse files

change I,Q,H->R to I,Q->R

parent 0409143d
No related branches found
No related tags found
No related merge requests found
...@@ -213,7 +213,7 @@ plot_sirplus <- function(x, comp_remove, ...@@ -213,7 +213,7 @@ plot_sirplus <- function(x, comp_remove,
theme_bw() + theme(axis.text.x = element_text(angle = 90)) theme_bw() + theme(axis.text.x = element_text(angle = 90))
if(length(unique(plot_df$experiment)) > 1){ if(length(unique(plot_df$experiment)) > 1){
p <- p + facet_grid(reo_exp(experiment) ~ ., scale = 'free') p <- p + facet_grid(reo_exp(experiment) ~ ., scales = 'free')
} }
if(sep_compartments){ if(sep_compartments){
......
...@@ -114,7 +114,7 @@ recovery.FUN <- function(dat, at, seed = NULL) { ...@@ -114,7 +114,7 @@ recovery.FUN <- function(dat, at, seed = NULL) {
rand = dat$control$rec.rand, rand = dat$control$rec.rand,
active, active,
status = dat$attr$status, status = dat$attr$status,
label = c("i", "q", "h"), label = c("i", "q"),
state = recovState, state = recovState,
at, at,
expTime = dat$attr$expTime, expTime = dat$attr$expTime,
......
...@@ -87,7 +87,7 @@ plot_models <- function(sims = baseline_sim, ...@@ -87,7 +87,7 @@ plot_models <- function(sims = baseline_sim,
} else ( } else (
plot_df %>% ggplot(aes(x = Date, y = count, colour = compartment, plot_df %>% ggplot(aes(x = Date, y = count, colour = compartment,
linetype = sim)) + linetype = sim)) +
facet_grid(reo_exp(experiment) ~ ., scale = 'free') + facet_grid(reo_exp(experiment) ~ ., scales = 'free') +
scale_x_date(date_breaks = "1 week", date_labels = "%m-%d") + scale_x_date(date_breaks = "1 week", date_labels = "%m-%d") +
geom_line(size = 1.5, alpha = 0.8) + geom_line(size = 1.5, alpha = 0.8) +
scale_colour_manual(values = compcols, labels = complabels) + scale_colour_manual(values = compcols, labels = complabels) +
...@@ -109,7 +109,7 @@ plot_models <- function(sims = baseline_sim, ...@@ -109,7 +109,7 @@ plot_models <- function(sims = baseline_sim,
} else ( } else (
plot_df %>% ggplot(aes(x = Date, y = count+1, colour = compartment, plot_df %>% ggplot(aes(x = Date, y = count+1, colour = compartment,
linetype = sim)) + linetype = sim)) +
facet_grid(reo_exp(experiment) ~ ., scale = 'free') + facet_grid(reo_exp(experiment) ~ ., scales = 'free') +
scale_y_continuous(trans = trans) + scale_y_continuous(trans = trans) +
scale_x_date(date_breaks = "1 week", date_labels = "%m-%d") + scale_x_date(date_breaks = "1 week", date_labels = "%m-%d") +
geom_line(size = 1.5, alpha = 0.8) + geom_line(size = 1.5, alpha = 0.8) +
......
No preview for this file type
test_that("All modules(MOD) produce the same result as Churches' modules (.seiqhrf.icm)", {
param <- param_seiqhrf(arec.rate = 0)
init <- init_seiqhrf(s.num = 1000)
#### default functions: initialize.FUN, infection.FUN, recovery.FUN, departures.FUN, arrivals.FUN
control1 <- control_seiqhrf(nsteps = 10)
### Churches' original function:
control2 <- control1
control2$initialize.FUN <- "initialize.icm"
control2$infection.FUN <- "infection.seiqhrf.icm"
control2$recovery.FUN <- "progress.seiqhrf.icm"
control2$departures.FUN <- "departures.seiqhrf.icm"
control2$arrivals.FUN <- "arrivals.seiqhrf.icm"
No_seeds <- 10
seed_list <- sample(1:1000, No_seeds)
comp <- rep(NA, No_seeds)
i <- 1
for(seed in seed_list){
sim1 <- seiqhrf(param = param, init = init, control = control1, seed)
sim2 <- seiqhrf(param = param, init = init, control = control2, seed)
comp[i] <- identical(sim1, sim2)
i <- i + 1
}
expect_equal(sum(comp), No_seeds)
})
test_that("Identical output as Churches' original function: recovery.FUN", {
control <- control_seiqhrf()
param <- param_seiqhrf(arec.rate = 0)
init <- init_seiqhrf()
at <- 2
dat <- do.call(initialize.FUN, list(param, init, control))
dat <- do.call(infection.FUN, list(dat, at))
No_seeds <- 10
seed_list <- sample(1:1000, No_seeds)
comp <- rep(NA, No_seeds)
i <- 1
for(seed in seed_list){
dat1 <- do.call(recovery.FUN, list(dat, at, seed))
dat2 <- do.call(progress.seiqhrf.icm, list(dat, at, seed))
comp[i] <- identical(dat1, dat2)
i <- i + 1
}
expect_equal(sum(comp), No_seeds)
})
\ No newline at end of file
test_that("seiqhrf and simulate_seiqhrf produce identical output", {
s.num = 1000
q.num = 10
nsteps = 10
nsims = 3
arec.rate = 0 ### has to be fixed 0 for comparison
No_seeds <- 10
seed_list <- sample(1:1000, No_seeds)
comp <- rep(NA, No_seeds)
i <- 1
for(seed in seed_list){
Churhes_res <- simulate_seiqhrf(nsteps = nsteps, nsims = nsims,
arec.rate = arec.rate, s.num = s.num, q.num = q.num,
infection.FUN = infection.seiqhrf.icm,
recovery.FUN = progress.seiqhrf.icm,
departures.FUN = departures.seiqhrf.icm,
arrivals.FUN = arrivals.seiqhrf.icm, seed = seed)$sim
class(Churhes_res) <- "seiqhrf"
param <- param_seiqhrf(arec.rate = arec.rate)
init <- init_seiqhrf(s.num = s.num, q.num = q.num)
control <- control_seiqhrf(nsteps = nsteps, nsims = nsims)
sirplus_res <- seiqhrf(init, control, param, seed)
comp[i] <- identical(Churhes_res[3:4], sirplus_res[3:4]) # Due to $usr.specified in control and param, can only compare "epi" and "times
i <- i + 1
}
expect_equal(sum(comp), No_seeds)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment