diff --git a/NAMESPACE b/NAMESPACE index 71c4906a..fd04593d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -42,11 +42,14 @@ S3method(plot,epiworld_multiple_save_reproductive_number) S3method(plot,epiworld_repnum) S3method(plot,epiworld_seir) S3method(plot,epiworld_seirconn) +S3method(plot,epiworld_seirdconn) S3method(plot,epiworld_sir) S3method(plot,epiworld_sirconn) S3method(plot,epiworld_sird) S3method(plot,epiworld_sis) +S3method(plot,epiworld_sisd) S3method(plot,epiworld_surv) +S3method(plot,epiworld_survd) S3method(print,epiworld_agent) S3method(print,epiworld_agents) S3method(print,epiworld_agents_tools) @@ -74,12 +77,15 @@ S3method(verbose_on,epiworld_model) export(ModelDiffNet) export(ModelSEIR) export(ModelSEIRCONN) +export(ModelSEIRDCONN) export(ModelSIR) export(ModelSIRCONN) export(ModelSIRD) export(ModelSIRLogit) export(ModelSIS) +export(ModelSISD) export(ModelSURV) +export(ModelSURVD) export(add_global_action) export(add_tool) export(add_tool_agent) diff --git a/R/cpp11.R b/R/cpp11.R index 5ab8775d..4a02446f 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -128,6 +128,22 @@ ModelSIRD_cpp <- function(name, prevalence, transmission_rate, recovery_rate, de .Call(`_epiworldR_ModelSIRD_cpp`, name, prevalence, transmission_rate, recovery_rate, death_rate) } +ModelSISD_cpp <- function(name, prevalence, transmission_rate, recovery_rate, death_rate) { + .Call(`_epiworldR_ModelSISD_cpp`, name, prevalence, transmission_rate, recovery_rate, death_rate) +} + +ModelSURVD_cpp <- function(name, prevalence, efficacy_vax, latent_period, prob_symptoms, prop_vaccinated, prop_vax_redux_transm, infect_period, prop_vax_redux_infect, surveillance_prob, transmission_rate, prob_death, prob_noreinfect) { + .Call(`_epiworldR_ModelSURVD_cpp`, name, prevalence, efficacy_vax, latent_period, prob_symptoms, prop_vaccinated, prop_vax_redux_transm, infect_period, prop_vax_redux_infect, surveillance_prob, transmission_rate, prob_death, prob_noreinfect) +} + +ModelSIRDCONN_cpp <- function(name, n, prevalence, contact_rate, transmission_rate, recovery_rate, death_rate) { + .Call(`_epiworldR_ModelSIRDCONN_cpp`, name, n, prevalence, contact_rate, transmission_rate, recovery_rate, death_rate) +} + +ModelSEIRDCONN_cpp <- function(name, n, prevalence, contact_rate, transmission_rate, incubation_days, recovery_rate, death_rate) { + .Call(`_epiworldR_ModelSEIRDCONN_cpp`, name, n, prevalence, contact_rate, transmission_rate, incubation_days, recovery_rate, death_rate) +} + ModelSEIRCONN_cpp <- function(name, n, prevalence, contact_rate, transmission_rate, incubation_days, recovery_rate) { .Call(`_epiworldR_ModelSEIRCONN_cpp`, name, n, prevalence, contact_rate, transmission_rate, incubation_days, recovery_rate) } diff --git a/inst/include/epiworld.hpp b/inst/include/epiworld.hpp index c3dc8ba2..950c1b70 100644 --- a/inst/include/epiworld.hpp +++ b/inst/include/epiworld.hpp @@ -3183,8 +3183,10 @@ inline void DataBase::record() // Now the diagonal must reflect the state for (size_t s_i = 0u; s_i < model->nstates; ++s_i) { + for (size_t s_j = 0u; s_j < model->nstates; ++s_j) { + if ((s_i != s_j) && (transition_matrix[s_i + s_j * model->nstates] > 0)) { transition_matrix[s_j + s_j * model->nstates] += @@ -3195,15 +3197,18 @@ inline void DataBase::record() } - #ifdef EPI_DEBUG + } + + #ifdef EPI_DEBUG + for (size_t s_i = 0u; s_i < model->nstates; ++s_i) + { if (transition_matrix[s_i + s_i * model->nstates] != today_total[s_i]) throw std::logic_error( "The diagonal of the updated transition Matrix should match the daily totals" ); - #endif } - + #endif } @@ -6949,7 +6954,6 @@ inline void Model::actions_run() for (size_t t = 0u; t < p->n_tools; ++t) db.update_tool(p->tools[t]->id, p->state, a.new_state); - // Saving the last state and setting the new one p->state_prev = p->state; p->state = a.new_state; @@ -16902,16 +16906,16 @@ inline ModelSISD::ModelSISD( // Adding statuses model.add_state("Susceptible", epiworld::default_update_susceptible); model.add_state("Infected", epiworld::default_update_exposed); - model.add_state("Deceased") + model.add_state("Deceased"); // Setting up parameters model.add_param(transmission_rate, "Transmission rate"); model.add_param(recovery_rate, "Recovery rate"); - model.add_param(death_rate, "Death rate") + model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- epiworld::Virus virus(vname); - virus.set_state(1,0,0); + virus.set_state(1,0,2); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); @@ -16929,7 +16933,7 @@ inline ModelSISD::ModelSISD( epiworld_double prevalence, epiworld_double transmission_rate, epiworld_double recovery_rate, - epiworld_double death_rate, + epiworld_double death_rate ) { diff --git a/man/ModelDiffNet.Rd b/man/ModelDiffNet.Rd index f884e10f..2dcbaef0 100644 --- a/man/ModelDiffNet.Rd +++ b/man/ModelDiffNet.Rd @@ -91,12 +91,15 @@ plot(adopt_chatgpt) \seealso{ Other Models: \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSEIR.Rd b/man/ModelSEIR.Rd index 836333fb..f37a831a 100644 --- a/man/ModelSEIR.Rd +++ b/man/ModelSEIR.Rd @@ -65,11 +65,14 @@ epiworld-methods Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSEIRCONN.Rd b/man/ModelSEIRCONN.Rd index f44a5bc6..10861214 100644 --- a/man/ModelSEIRCONN.Rd +++ b/man/ModelSEIRCONN.Rd @@ -86,12 +86,15 @@ epiworld-methods Other Models: \code{\link{ModelDiffNet}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSIR.Rd b/man/ModelSIR.Rd index 753024bd..a05717b1 100644 --- a/man/ModelSIR.Rd +++ b/man/ModelSIR.Rd @@ -65,11 +65,14 @@ epiworld-methods Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSIRCONN.Rd b/man/ModelSIRCONN.Rd index b6ce8874..38281c40 100644 --- a/man/ModelSIRCONN.Rd +++ b/man/ModelSIRCONN.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ModelSIRCONN.R +% Please edit documentation in R/ModelSIRCONN.R, R/ModelSIRDCONN.R \name{ModelSIRCONN} \alias{ModelSIRCONN} \alias{epiworld_sirconn} @@ -15,6 +15,17 @@ ModelSIRCONN( recovery_rate ) +\method{plot}{epiworld_sirconn}(x, main = get_name(x), ...) + +ModelSIRCONN( + name, + n, + prevalence, + contact_rate, + transmission_rate, + recovery_rate +) + \method{plot}{epiworld_sirconn}(x, main = get_name(x), ...) } \arguments{ @@ -36,16 +47,27 @@ transmission.} \item{main}{Title of the plot} \item{...}{Currently ignore.} + +\item{death_rate}{Numeric scalar between 0 and 1. Probability of death.} } \value{ \itemize{ \item The \code{ModelSIRCONN}function returns a model of class \link{epiworld_model}. } +The \code{plot} function returns a plot of the SIRCONN model of class +\link{epiworld_model}. + +\itemize{ +\item The \code{ModelSIRDCONN}function returns a model of class \link{epiworld_model}. +} + The \code{plot} function returns a plot of the SIRCONN model of class \link{epiworld_model}. } \description{ +Susceptible Infected Removed model (SIR connected) + Susceptible Infected Removed model (SIR connected) } \examples{ @@ -62,19 +84,52 @@ model_sirconn <- ModelSIRCONN( run(model_sirconn, ndays = 100, seed = 1912) model_sirconn +plot(model_sirconn, main = "SIRCONN Model") +model_sirconn <- ModelSIRCONN( + name = "COVID-19", + n = 10000, + prevalence = 0.01, + contact_rate = 5, + transmission_rate = 0.4, + recovery_rate = 0.95 +) + +# Running and printing +run(model_sirconn, ndays = 100, seed = 1912) +model_sirconn + plot(model_sirconn, main = "SIRCONN Model") } \seealso{ epiworld-methods +epiworld-methods + +Other Models: +\code{\link{ModelDiffNet}()}, +\code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, +\code{\link{ModelSEIR}()}, +\code{\link{ModelSIRD}()}, +\code{\link{ModelSIRLogit}()}, +\code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, +\code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, +\code{\link{ModelSURV}()}, +\code{\link{epiworld-data}} + Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSIRD.Rd b/man/ModelSIRD.Rd index 6251592a..651ee30f 100644 --- a/man/ModelSIRD.Rd +++ b/man/ModelSIRD.Rd @@ -30,7 +30,7 @@ infection.} } \value{ \itemize{ -\item The \code{ModelSIR} function returns a model of class \link{epiworld_model}. +\item The \code{ModelSIRD} function returns a model of class \link{epiworld_model}. } \itemize{ @@ -72,11 +72,14 @@ epiworld-methods Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSIRLogit.Rd b/man/ModelSIRLogit.Rd index 25abf5a4..c1d98555 100644 --- a/man/ModelSIRLogit.Rd +++ b/man/ModelSIRLogit.Rd @@ -95,11 +95,14 @@ get_agents(model_logit) Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSIS.Rd b/man/ModelSIS.Rd index 74fe3ef2..4212bf9d 100644 --- a/man/ModelSIS.Rd +++ b/man/ModelSIS.Rd @@ -66,11 +66,14 @@ epiworld-methods Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()}, \code{\link{epiworld-data}} } diff --git a/man/ModelSURV.Rd b/man/ModelSURV.Rd index 9c53f680..60d35cc8 100644 --- a/man/ModelSURV.Rd +++ b/man/ModelSURV.Rd @@ -115,12 +115,15 @@ epiworld-methods Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{epiworld-data}} } \concept{Models} diff --git a/man/epiworld-data.Rd b/man/epiworld-data.Rd index 3ce59adc..89cf6a39 100644 --- a/man/epiworld-data.Rd +++ b/man/epiworld-data.Rd @@ -237,12 +237,15 @@ gent <- plot_generation_time(seirconn) Other Models: \code{\link{ModelDiffNet}()}, \code{\link{ModelSEIRCONN}()}, +\code{\link{ModelSEIRDCONN}()}, \code{\link{ModelSEIR}()}, \code{\link{ModelSIRCONN}()}, \code{\link{ModelSIRD}()}, \code{\link{ModelSIRLogit}()}, \code{\link{ModelSIR}()}, +\code{\link{ModelSISD}()}, \code{\link{ModelSIS}()}, +\code{\link{ModelSURVD}()}, \code{\link{ModelSURV}()} } \concept{Models} diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 7a708a81..1c530db5 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -230,6 +230,34 @@ extern "C" SEXP _epiworldR_ModelSIRD_cpp(SEXP name, SEXP prevalence, SEXP transm END_CPP11 } // epimodels.cpp +SEXP ModelSISD_cpp(std::string name, double prevalence, double transmission_rate, double recovery_rate, double death_rate); +extern "C" SEXP _epiworldR_ModelSISD_cpp(SEXP name, SEXP prevalence, SEXP transmission_rate, SEXP recovery_rate, SEXP death_rate) { + BEGIN_CPP11 + return cpp11::as_sexp(ModelSISD_cpp(cpp11::as_cpp>(name), cpp11::as_cpp>(prevalence), cpp11::as_cpp>(transmission_rate), cpp11::as_cpp>(recovery_rate), cpp11::as_cpp>(death_rate))); + END_CPP11 +} +// epimodels.cpp +SEXP ModelSURVD_cpp(std::string name, double prevalence, double efficacy_vax, double latent_period, double prob_symptoms, double prop_vaccinated, double prop_vax_redux_transm, double infect_period, double prop_vax_redux_infect, double surveillance_prob, double transmission_rate, double prob_death, double prob_noreinfect); +extern "C" SEXP _epiworldR_ModelSURVD_cpp(SEXP name, SEXP prevalence, SEXP efficacy_vax, SEXP latent_period, SEXP prob_symptoms, SEXP prop_vaccinated, SEXP prop_vax_redux_transm, SEXP infect_period, SEXP prop_vax_redux_infect, SEXP surveillance_prob, SEXP transmission_rate, SEXP prob_death, SEXP prob_noreinfect) { + BEGIN_CPP11 + return cpp11::as_sexp(ModelSURVD_cpp(cpp11::as_cpp>(name), cpp11::as_cpp>(prevalence), cpp11::as_cpp>(efficacy_vax), cpp11::as_cpp>(latent_period), cpp11::as_cpp>(prob_symptoms), cpp11::as_cpp>(prop_vaccinated), cpp11::as_cpp>(prop_vax_redux_transm), cpp11::as_cpp>(infect_period), cpp11::as_cpp>(prop_vax_redux_infect), cpp11::as_cpp>(surveillance_prob), cpp11::as_cpp>(transmission_rate), cpp11::as_cpp>(prob_death), cpp11::as_cpp>(prob_noreinfect))); + END_CPP11 +} +// epimodels.cpp +SEXP ModelSIRDCONN_cpp(std::string name, unsigned int n, double prevalence, double contact_rate, double transmission_rate, double recovery_rate, double death_rate); +extern "C" SEXP _epiworldR_ModelSIRDCONN_cpp(SEXP name, SEXP n, SEXP prevalence, SEXP contact_rate, SEXP transmission_rate, SEXP recovery_rate, SEXP death_rate) { + BEGIN_CPP11 + return cpp11::as_sexp(ModelSIRDCONN_cpp(cpp11::as_cpp>(name), cpp11::as_cpp>(n), cpp11::as_cpp>(prevalence), cpp11::as_cpp>(contact_rate), cpp11::as_cpp>(transmission_rate), cpp11::as_cpp>(recovery_rate), cpp11::as_cpp>(death_rate))); + END_CPP11 +} +// epimodels.cpp +SEXP ModelSEIRDCONN_cpp(std::string name, unsigned int n, double prevalence, double contact_rate, double transmission_rate, double incubation_days, double recovery_rate, double death_rate); +extern "C" SEXP _epiworldR_ModelSEIRDCONN_cpp(SEXP name, SEXP n, SEXP prevalence, SEXP contact_rate, SEXP transmission_rate, SEXP incubation_days, SEXP recovery_rate, SEXP death_rate) { + BEGIN_CPP11 + return cpp11::as_sexp(ModelSEIRDCONN_cpp(cpp11::as_cpp>(name), cpp11::as_cpp>(n), cpp11::as_cpp>(prevalence), cpp11::as_cpp>(contact_rate), cpp11::as_cpp>(transmission_rate), cpp11::as_cpp>(incubation_days), cpp11::as_cpp>(recovery_rate), cpp11::as_cpp>(death_rate))); + END_CPP11 +} +// epimodels.cpp SEXP ModelSEIRCONN_cpp(std::string name, unsigned int n, double prevalence, double contact_rate, double transmission_rate, double incubation_days, double recovery_rate); extern "C" SEXP _epiworldR_ModelSEIRCONN_cpp(SEXP name, SEXP n, SEXP prevalence, SEXP contact_rate, SEXP transmission_rate, SEXP incubation_days, SEXP recovery_rate) { BEGIN_CPP11 @@ -745,12 +773,16 @@ extern "C" { static const R_CallMethodDef CallEntries[] = { {"_epiworldR_ModelDiffNet_cpp", (DL_FUNC) &_epiworldR_ModelDiffNet_cpp, 8}, {"_epiworldR_ModelSEIRCONN_cpp", (DL_FUNC) &_epiworldR_ModelSEIRCONN_cpp, 7}, + {"_epiworldR_ModelSEIRDCONN_cpp", (DL_FUNC) &_epiworldR_ModelSEIRDCONN_cpp, 8}, {"_epiworldR_ModelSEIR_cpp", (DL_FUNC) &_epiworldR_ModelSEIR_cpp, 5}, {"_epiworldR_ModelSIRCONN_cpp", (DL_FUNC) &_epiworldR_ModelSIRCONN_cpp, 6}, + {"_epiworldR_ModelSIRDCONN_cpp", (DL_FUNC) &_epiworldR_ModelSIRDCONN_cpp, 7}, {"_epiworldR_ModelSIRD_cpp", (DL_FUNC) &_epiworldR_ModelSIRD_cpp, 5}, {"_epiworldR_ModelSIRLogit_cpp", (DL_FUNC) &_epiworldR_ModelSIRLogit_cpp, 10}, {"_epiworldR_ModelSIR_cpp", (DL_FUNC) &_epiworldR_ModelSIR_cpp, 4}, + {"_epiworldR_ModelSISD_cpp", (DL_FUNC) &_epiworldR_ModelSISD_cpp, 5}, {"_epiworldR_ModelSIS_cpp", (DL_FUNC) &_epiworldR_ModelSIS_cpp, 4}, + {"_epiworldR_ModelSURVD_cpp", (DL_FUNC) &_epiworldR_ModelSURVD_cpp, 13}, {"_epiworldR_ModelSURV_cpp", (DL_FUNC) &_epiworldR_ModelSURV_cpp, 13}, {"_epiworldR_add_global_action_cpp", (DL_FUNC) &_epiworldR_add_global_action_cpp, 2}, {"_epiworldR_add_tool_agent_cpp", (DL_FUNC) &_epiworldR_add_tool_agent_cpp, 5},