diff --git a/R/model-methods.R b/R/model-methods.R index 464927b2..7bc71f22 100644 --- a/R/model-methods.R +++ b/R/model-methods.R @@ -17,7 +17,7 @@ stopifnot_model <- function(model) { #' #' @param x An object of class `epiworld_model`. #' @param ndays Number of days (steps) of the simulation. -#' @param seed Seed to set for initializing random number generator. +#' @param seed Seed to set for initializing random number generator (passed to [set.seed()]). #' @param model Model object. #' @export #' @name epiworld-methods @@ -157,11 +157,12 @@ verbose_on.epiworld_model <- function(x) { #' @returns #' - The `run` function returns the simulated model of class `epiworld_model`. #' @rdname epiworld-methods -run <- function(model, ndays, seed = sample.int(1e4, 1)) UseMethod("run") +run <- function(model, ndays, seed = NULL) UseMethod("run") #' @export -run.epiworld_model <- function(model, ndays, seed = sample.int(1e4, 1)) { - run_cpp(model, ndays, seed) +run.epiworld_model <- function(model, ndays, seed = NULL) { + if (length(seed)) set.seed(seed) + run_cpp(model, ndays, sample.int(1e4, 1)) invisible(model) } diff --git a/man/ModelDiffNet.Rd b/man/ModelDiffNet.Rd index e8ed956c..83c6fefd 100644 --- a/man/ModelDiffNet.Rd +++ b/man/ModelDiffNet.Rd @@ -67,8 +67,8 @@ n <- 10000 # Generating synthetic data on a matrix with 2 columns. X <- cbind( - age = sample(1:100, n, replace = TRUE), - female = sample.int(2, n, replace = TRUE) - 1 + age = sample(1:100, n, replace = TRUE), + female = sample.int(2, n, replace = TRUE) - 1 ) adopt_chatgpt <- ModelDiffNet( diff --git a/man/ModelSEIR.Rd b/man/ModelSEIR.Rd index 8f8f4958..d161e9b5 100644 --- a/man/ModelSEIR.Rd +++ b/man/ModelSEIR.Rd @@ -47,8 +47,8 @@ values: (1) Proportion of non-infected agents who are removed, and (2) Proportion of exposed agents to be set as infected. } \examples{ -model_seir <- ModelSEIR(name = "COVID-19", prevalence = 0.01, -transmission_rate = 0.9, recovery_rate = 0.1, incubation_days = 4) +model_seir <- ModelSEIR(name = "COVID-19", prevalence = 0.01, + transmission_rate = 0.9, recovery_rate = 0.1, incubation_days = 4) # Adding a small world population agents_smallworld( @@ -57,8 +57,8 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_seir, ndays = 100, seed = 1912) model_seir diff --git a/man/ModelSEIRCONN.Rd b/man/ModelSEIRCONN.Rd index c885d54c..1a3cb966 100644 --- a/man/ModelSEIRCONN.Rd +++ b/man/ModelSEIRCONN.Rd @@ -57,14 +57,14 @@ This is equivalent to a compartmental model (\href{https://en.wikipedia.org/w/in # An example with COVID-19 model_seirconn <- ModelSEIRCONN( name = "COVID-19", - prevalence = 0.01, + prevalence = 0.01, n = 10000, - contact_rate = 2, - incubation_days = 7, + contact_rate = 2, + incubation_days = 7, transmission_rate = 0.5, recovery_rate = 0.3 ) - + # Running and printing run(model_seirconn, ndays = 100, seed = 1912) model_seirconn @@ -72,7 +72,7 @@ model_seirconn plot(model_seirconn) # Adding the flu -flu <- virus("Flu", .9, 1/7, prevalence = 0.001, as_proportion = TRUE) +flu <- virus("Flu", .9, 1 / 7, prevalence = 0.001, as_proportion = TRUE) add_virus(model_seirconn, flu) #' # Running and printing diff --git a/man/ModelSEIRD.Rd b/man/ModelSEIRD.Rd index c32c3496..0f3e83c3 100644 --- a/man/ModelSEIRD.Rd +++ b/man/ModelSEIRD.Rd @@ -57,9 +57,9 @@ proportion of non-infected agents already removed, and (3) proportion of non-ifected agents already deceased. } \examples{ -model_seird <- ModelSEIRD(name = "COVID-19", prevalence = 0.01, -transmission_rate = 0.9, recovery_rate = 0.1, incubation_days = 4, -death_rate = 0.01) +model_seird <- ModelSEIRD(name = "COVID-19", prevalence = 0.01, + transmission_rate = 0.9, recovery_rate = 0.1, incubation_days = 4, + death_rate = 0.01) # Adding a small world population agents_smallworld( @@ -68,8 +68,8 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_seird, ndays = 100, seed = 1912) model_seird diff --git a/man/ModelSEIRDCONN.Rd b/man/ModelSEIRDCONN.Rd index bb535114..c3db3dc8 100644 --- a/man/ModelSEIRDCONN.Rd +++ b/man/ModelSEIRDCONN.Rd @@ -67,15 +67,15 @@ non-ifected agents already deceased. # An example with COVID-19 model_seirdconn <- ModelSEIRDCONN( name = "COVID-19", - prevalence = 0.01, + prevalence = 0.01, n = 10000, - contact_rate = 2, - incubation_days = 7, + contact_rate = 2, + incubation_days = 7, transmission_rate = 0.5, recovery_rate = 0.3, death_rate = 0.01 ) - + # Running and printing run(model_seirdconn, ndays = 100, seed = 1912) model_seirdconn @@ -84,7 +84,7 @@ plot(model_seirdconn) # Adding the flu flu <- virus( - "Flu", prob_infecting = .3, recovery_rate = 1/7, + "Flu", prob_infecting = .3, recovery_rate = 1 / 7, prob_death = 0.001, prevalence = 0.001, as_proportion = TRUE ) diff --git a/man/ModelSIR.Rd b/man/ModelSIR.Rd index eafb9a3c..6312ccd7 100644 --- a/man/ModelSIR.Rd +++ b/man/ModelSIR.Rd @@ -45,8 +45,8 @@ model. In particular, the user can specify how many of the non-infected agents have been removed at the beginning of the simulation. } \examples{ -model_sir <- ModelSIR(name = "COVID-19", prevalence = 0.01, - transmission_rate = 0.9, recovery_rate = 0.1) +model_sir <- ModelSIR(name = "COVID-19", prevalence = 0.01, + transmission_rate = 0.9, recovery_rate = 0.1) # Adding a small world population agents_smallworld( @@ -55,8 +55,8 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_sir, ndays = 100, seed = 1912) model_sir diff --git a/man/ModelSIRCONN.Rd b/man/ModelSIRCONN.Rd index e6e21556..4e867bb7 100644 --- a/man/ModelSIRCONN.Rd +++ b/man/ModelSIRCONN.Rd @@ -62,7 +62,7 @@ model_sirconn <- ModelSIRCONN( transmission_rate = 0.4, recovery_rate = 0.95 ) - + # Running and printing run(model_sirconn, ndays = 100, seed = 1912) model_sirconn diff --git a/man/ModelSIRD.Rd b/man/ModelSIRD.Rd index c2b92ca0..ddda5479 100644 --- a/man/ModelSIRD.Rd +++ b/man/ModelSIRD.Rd @@ -49,11 +49,11 @@ non-ifected agents already deceased. } \examples{ model_sird <- ModelSIRD( - name = "COVID-19", - prevalence = 0.01, - transmission_rate = 0.9, - recovery_rate = 0.1, - death_rate = 0.01 + name = "COVID-19", + prevalence = 0.01, + transmission_rate = 0.9, + recovery_rate = 0.1, + death_rate = 0.01 ) # Adding a small world population @@ -63,8 +63,8 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_sird, ndays = 100, seed = 1912) model_sird diff --git a/man/ModelSIRDCONN.Rd b/man/ModelSIRDCONN.Rd index 717d7321..cd48e99c 100644 --- a/man/ModelSIRDCONN.Rd +++ b/man/ModelSIRDCONN.Rd @@ -67,7 +67,7 @@ model_sirdconn <- ModelSIRDCONN( recovery_rate = 0.5, death_rate = 0.1 ) - + # Running and printing run(model_sirdconn, ndays = 100, seed = 1912) model_sirdconn diff --git a/man/ModelSIRLogit.Rd b/man/ModelSIRLogit.Rd index 3201c78c..ce9f3d44 100644 --- a/man/ModelSIRLogit.Rd +++ b/man/ModelSIRLogit.Rd @@ -47,10 +47,10 @@ SIR Logistic model set.seed(2223) n <- 100000 -# Creating the data to use for the "ModelSIRLogit" function. It contains -# information on the sex of each agent and will be used to determine -# differences in disease progression between males and females. Note that -# the number of rows in these data are identical to n (100000). +# Creating the data to use for the "ModelSIRLogit" function. It contains +# information on the sex of each agent and will be used to determine +# differences in disease progression between males and females. Note that +# the number of rows in these data are identical to n (100000). X <- cbind( Intercept = 1, Female = sample.int(2, n, replace = TRUE) - 1 @@ -60,12 +60,12 @@ X <- cbind( coef_infect <- c(.1, -2, 2) coef_recover <- rnorm(2) -# Feed all above information into the "ModelSIRLogit" function. +# Feed all above information into the "ModelSIRLogit" function. model_logit <- ModelSIRLogit( "covid2", data = X, coefs_infect = coef_infect, - coefs_recover = coef_recover, + coefs_recover = coef_recover, coef_infect_cols = 1L:ncol(X), coef_recover_cols = 1L:ncol(X), prob_infection = .8, @@ -82,11 +82,11 @@ plot(model_logit) # Females are supposed to be more likely to become infected. rn <- get_reproductive_number(model_logit) -# Probability of infection for males and females. +# Probability of infection for males and females. (table( X[, "Female"], (1:n \%in\% rn$source) -) |> prop.table())[,2] +) |> prop.table())[, 2] # Looking into the individual agents. get_agents(model_logit) diff --git a/man/ModelSIS.Rd b/man/ModelSIS.Rd index 8b0a8994..f671b2a2 100644 --- a/man/ModelSIS.Rd +++ b/man/ModelSIS.Rd @@ -40,8 +40,8 @@ infection.} Susceptible-Infected-Susceptible model (SIS) (\href{https://en.wikipedia.org/w/index.php?title=Compartmental_models_in_epidemiology&oldid=1155757336#The_SIS_model}{wiki}) } \examples{ -model_sis <- ModelSIS(name = "COVID-19", prevalence = 0.01, - transmission_rate = 0.9, recovery_rate = 0.1) +model_sis <- ModelSIS(name = "COVID-19", prevalence = 0.01, + transmission_rate = 0.9, recovery_rate = 0.1) # Adding a small world population agents_smallworld( @@ -50,8 +50,8 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_sis, ndays = 100, seed = 1912) model_sis diff --git a/man/ModelSISD.Rd b/man/ModelSISD.Rd index 4e164ab5..835a87de 100644 --- a/man/ModelSISD.Rd +++ b/man/ModelSISD.Rd @@ -43,12 +43,12 @@ Susceptible-Infected-Susceptible-Deceased model (SISD) (\href{https://en.wikiped } \examples{ model_sisd <- ModelSISD( - name = "COVID-19", - prevalence = 0.01, - transmission_rate = 0.9, - recovery_rate = 0.1, - death_rate = 0.01 - ) + name = "COVID-19", + prevalence = 0.01, + transmission_rate = 0.9, + recovery_rate = 0.1, + death_rate = 0.01 +) # Adding a small world population agents_smallworld( @@ -57,8 +57,8 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_sisd, ndays = 100, seed = 1912) model_sisd diff --git a/man/ModelSURV.Rd b/man/ModelSURV.Rd index 90dc9aa8..796694f7 100644 --- a/man/ModelSURV.Rd +++ b/man/ModelSURV.Rd @@ -99,11 +99,11 @@ agents_smallworld( k = 5, d = FALSE, p = .01 - ) - +) + # Running and printing run(model_surv, ndays = 100, seed = 1912) -model_surv +model_surv # Plotting plot(model_surv, main = "SURV Model") diff --git a/man/agents.Rd b/man/agents.Rd index f5d7e74b..9375c4ff 100644 --- a/man/agents.Rd +++ b/man/agents.Rd @@ -64,29 +64,29 @@ contains all the information about the agents in the model. The And the \code{get_state} function returns the state of a single agent. } \examples{ - + model_sirconn <- ModelSIRCONN( -name = "COVID-19", -n = 10000, -prevalence = 0.01, -contact_rate = 5, -transmission_rate = 0.4, -recovery_rate = 0.95 + name = "COVID-19", + n = 10000, + prevalence = 0.01, + contact_rate = 5, + transmission_rate = 0.4, + recovery_rate = 0.95 ) run(model_sirconn, ndays = 100, seed = 1912) -x <- get_agents(model_sirconn) # Storing all agent information into object of - # class epiworld_agents - -print(x, compressed = FALSE, max_print = 5) # Displaying detailed information of - # the first 5 agents using - # compressed=F. Using compressed=T - # results in less-detailed - # information about each agent. - -x[0] # Print information about the first agent. Substitute the agent of - # interest's position where '0' is. +x <- get_agents(model_sirconn) # Storing all agent information into object of +# class epiworld_agents + +print(x, compressed = FALSE, max_print = 5) # Displaying detailed information of +# the first 5 agents using +# compressed=F. Using compressed=T +# results in less-detailed +# information about each agent. + +x[0] # Print information about the first agent. Substitute the agent of +# interest's position where '0' is. } \seealso{ agents diff --git a/man/agents_smallworld.Rd b/man/agents_smallworld.Rd index 36717930..12036208 100644 --- a/man/agents_smallworld.Rd +++ b/man/agents_smallworld.Rd @@ -113,15 +113,15 @@ provided, the agent will be updated with the default values of the virus/tool. \examples{ # Initializing SIR model with agents_smallworld -sir <- ModelSIR(name = "COVID-19", prevalence = 0.01, transmission_rate = 0.9, - recovery_rate = 0.1) +sir <- ModelSIR(name = "COVID-19", prevalence = 0.01, transmission_rate = 0.9, + recovery_rate = 0.1) agents_smallworld( - sir, - n = 1000, - k = 5, - d = FALSE, - p = .01 - ) + sir, + n = 1000, + k = 5, + d = FALSE, + p = .01 +) run(sir, ndays = 100, seed = 1912) sir @@ -132,7 +132,7 @@ head(net) # Simulating a bernoulli graph set.seed(333) n <- 1000 -g <- matrix(runif(n ^ 2) < .01, nrow = n) +g <- matrix(runif(n^2) < .01, nrow = n) diag(g) <- FALSE el <- which(g, arr.ind = TRUE) - 1L @@ -141,8 +141,8 @@ el <- which(g, arr.ind = TRUE) - 1L sir <- ModelSIR("COVID-19", .01, .8, .3) agents_from_edgelist( sir, - source = el[,1], - target = el[,2], + source = el[, 1], + target = el[, 2], size = n, directed = TRUE ) diff --git a/man/entities.Rd b/man/entities.Rd index 9f0724d2..1f0be67d 100644 --- a/man/entities.Rd +++ b/man/entities.Rd @@ -114,13 +114,13 @@ Epiworld entities are especially useful for mixing models, particularly \examples{ # Creating a mixing model mymodel <- ModelSIRMixing( - name = "My model", - n = 10000, - prevalence = .001, - contact_rate = 10, - transmission_rate = .1, - recovery_rate = 1/7, - contact_matrix = matrix(c(.9, .1, .1, .9), 2, 2) + name = "My model", + n = 10000, + prevalence = .001, + contact_rate = 10, + transmission_rate = .1, + recovery_rate = 1 / 7, + contact_matrix = matrix(c(.9, .1, .1, .9), 2, 2) ) ent1 <- entity("First", 5000, FALSE) diff --git a/man/epiworld-data.Rd b/man/epiworld-data.Rd index 3390eee0..148de4f1 100644 --- a/man/epiworld-data.Rd +++ b/man/epiworld-data.Rd @@ -193,7 +193,7 @@ seirconn <- ModelSEIRCONN( name = "Disease", n = 10000, prevalence = 0.1, - contact_rate = 2.0, + contact_rate = 2.0, transmission_rate = 0.8, incubation_days = 7.0, recovery_rate = 0.3 @@ -204,12 +204,12 @@ set.seed(937) run(seirconn, 50) # Retrieving the transition probability -get_transition_probability(seirconn) +get_transition_probability(seirconn) -# Retrieving date, state, and counts dataframe including any added tools +# Retrieving date, state, and counts dataframe including any added tools get_hist_tool(seirconn) -# Retrieving overall date, state, and counts dataframe +# Retrieving overall date, state, and counts dataframe head(get_hist_total(seirconn)) # Retrieving date, state, and counts dataframe by variant @@ -225,7 +225,7 @@ t_hist <- get_hist_transition_matrix(seirconn) head(t_hist) # And turn it into an array -as.array(t_hist)[,,1:3] +as.array(t_hist)[, , 1:3] # We cam also get (and plot) the incidence, as well as # the generation time diff --git a/man/epiworld-methods.Rd b/man/epiworld-methods.Rd index 3d5deab2..17cacfd1 100644 --- a/man/epiworld-methods.Rd +++ b/man/epiworld-methods.Rd @@ -35,7 +35,7 @@ verbose_off(x) verbose_on(x) -run(model, ndays, seed = sample.int(10000, 1)) +run(model, ndays, seed = NULL) \method{summary}{epiworld_model}(object, ...) @@ -78,7 +78,7 @@ clone_model(model) \item{ndays}{Number of days (steps) of the simulation.} -\item{seed}{Seed to set for initializing random number generator.} +\item{seed}{Seed to set for initializing random number generator (passed to \code{\link[=set.seed]{set.seed()}}).} \item{object}{Object of class \code{epiworld_model}.} @@ -199,79 +199,79 @@ the assignment operator will only copy the pointer. \examples{ model_sirconn <- ModelSIRCONN( -name = "COVID-19", -n = 10000, -prevalence = 0.01, -contact_rate = 5, -transmission_rate = 0.4, -recovery_rate = 0.95 + name = "COVID-19", + n = 10000, + prevalence = 0.01, + contact_rate = 5, + transmission_rate = 0.4, + recovery_rate = 0.95 ) -# Queuing - If you wish to implement the queuing function, declare whether -# you would like it "on" or "off", if any. +# Queuing - If you wish to implement the queuing function, declare whether +# you would like it "on" or "off", if any. queuing_on(model_sirconn) queuing_off(model_sirconn) run(model_sirconn, ndays = 100, seed = 1912) -# Verbose - "on" prints the progress bar on the screen while "off" -# deactivates the progress bar. Declare which function you want to implement, -# if any. +# Verbose - "on" prints the progress bar on the screen while "off" +# deactivates the progress bar. Declare which function you want to implement, +# if any. verbose_on(model_sirconn) verbose_off(model_sirconn) run(model_sirconn, ndays = 100, seed = 1912) get_states(model_sirconn) # Returns all unique states found within the model. -get_param(model_sirconn, 'Contact rate') # Returns the value of the selected - # parameter within the model object. - # In order to view the parameters, - # run the model object and find the - # "Model parameters" section. - -set_param(model_sirconn, 'Contact rate', 2) # Allows for adjustment of model - # parameters within the model - # object. In this example, the - # Contact rate parameter is - # changed to 2. You can now rerun - # the model to observe any - # differences. - -set_name(model_sirconn, 'My Epi-Model') # This function allows for setting - # a name for the model. Running the - # model object, the name of the model - # is now reflected next to "Name of - # the model". - -get_name(model_sirconn) # Returns the set name of the model. - -get_n_viruses(model_sirconn) # Returns the number of viruses in the model. - # In this case, there is only one virus: - # "COVID-19". - -get_n_tools(model_sirconn) # Returns the number of tools in the model. In - # this case, there are zero tools. - +get_param(model_sirconn, "Contact rate") # Returns the value of the selected +# parameter within the model object. +# In order to view the parameters, +# run the model object and find the +# "Model parameters" section. + +set_param(model_sirconn, "Contact rate", 2) # Allows for adjustment of model +# parameters within the model +# object. In this example, the +# Contact rate parameter is +# changed to 2. You can now rerun +# the model to observe any +# differences. + +set_name(model_sirconn, "My Epi-Model") # This function allows for setting +# a name for the model. Running the +# model object, the name of the model +# is now reflected next to "Name of +# the model". + +get_name(model_sirconn) # Returns the set name of the model. + +get_n_viruses(model_sirconn) # Returns the number of viruses in the model. +# In this case, there is only one virus: +# "COVID-19". + +get_n_tools(model_sirconn) # Returns the number of tools in the model. In +# this case, there are zero tools. + get_ndays(model_sirconn) # Returns the length of the simulation in days. This - # will match "ndays" within the "run" function. - -get_n_replicates(model_sirconn) # Returns the number of replicates of the - # model. - -size(model_sirconn) # Returns the population size in the model. In this case, - # there are 10,000 agents in the model. +# will match "ndays" within the "run" function. + +get_n_replicates(model_sirconn) # Returns the number of replicates of the +# model. + +size(model_sirconn) # Returns the population size in the model. In this case, +# there are 10,000 agents in the model. # Set Agents Data -# First, your data matrix must have the same number of rows as agents in the -# model. Below is a generated matrix which will be passed into the -# "set_agents_data" function. -data <- matrix(data=runif(20000, min=0, max=100), nrow=10000, ncol=2) +# First, your data matrix must have the same number of rows as agents in the +# model. Below is a generated matrix which will be passed into the +# "set_agents_data" function. +data <- matrix(data = runif(20000, min = 0, max = 100), nrow = 10000, ncol = 2) set_agents_data(model_sirconn, data) -get_agents_data_ncols(model_sirconn) # Returns number of columns +get_agents_data_ncols(model_sirconn) # Returns number of columns -get_virus(model_sirconn, 0) # Returns information about the first virus in - # the model (index begins at 0). +get_virus(model_sirconn, 0) # Returns information about the first virus in +# the model (index begins at 0). -add_tool(model_sirconn, tool("Vaccine", .9, .9, .5, 1, prevalence = 0.5, as_prop = TRUE)) -get_tool(model_sirconn, 0) # Returns information about the first tool in the - # model. In this case, there are no tools so an - # error message will occur. +add_tool(model_sirconn, tool("Vaccine", .9, .9, .5, 1, prevalence = 0.5, as_prop = TRUE)) +get_tool(model_sirconn, 0) # Returns information about the first tool in the +# model. In this case, there are no tools so an +# error message will occur. } diff --git a/man/epiworldR-package.Rd b/man/epiworldR-package.Rd index 1d594f7a..33015655 100644 --- a/man/epiworldR-package.Rd +++ b/man/epiworldR-package.Rd @@ -19,11 +19,11 @@ Useful links: } \author{ -\strong{Maintainer}: Derek Meyer \email{derekmeyer37@gmail.com} (\href{https://orcid.org/0009-0005-1350-6988}{ORCID}) +\strong{Maintainer}: George Vega Yon \email{g.vegayon@gmail.com} (\href{https://orcid.org/0000-0002-3171-0844}{ORCID}) Authors: \itemize{ - \item George Vega Yon \email{g.vegayon@gmail.com} (\href{https://orcid.org/0000-0002-3171-0844}{ORCID}) + \item Derek Meyer \email{derekmeyer37@gmail.com} (\href{https://orcid.org/0009-0005-1350-6988}{ORCID}) } Other contributors: diff --git a/man/global-actions.Rd b/man/global-actions.Rd index dd4c819e..e47f02b9 100644 --- a/man/global-actions.Rd +++ b/man/global-actions.Rd @@ -117,7 +117,7 @@ epitool <- tool( as_proportion = FALSE, susceptibility_reduction = .9, transmission_reduction = .5, - recovery_enhancer = .5, + recovery_enhancer = .5, death_reduction = .9 ) @@ -159,7 +159,7 @@ model <- ModelSIRCONN( contact_rate = 5, transmission_rate = 0.4, recovery_rate = 0.3 - ) +) # We create the object where the history of the agents will be stored agents_history <- NULL @@ -167,7 +167,7 @@ agents_history <- NULL # This function prints the total number of agents in each state # and stores the history of the agents in the object `agents_history` hist_saver <- function(m) { - + message("Today's totals are: ", paste(get_today_total(m), collapse = ", ")) # We use the `<<-` operator to assign the value to the global variable @@ -175,8 +175,8 @@ hist_saver <- function(m) { agents_history <<- cbind( agents_history, get_agents_states(m) - ) - + ) + } } \seealso{ diff --git a/man/run_multiple.Rd b/man/run_multiple.Rd index 8d736f5b..dc308dc0 100644 --- a/man/run_multiple.Rd +++ b/man/run_multiple.Rd @@ -80,7 +80,7 @@ model_sir <- ModelSIRCONN( n = 1000, contact_rate = 2, transmission_rate = 0.9, recovery_rate = 0.1 - ) +) # Generating a saver saver <- make_saver("total_hist", "reproductive") @@ -96,7 +96,7 @@ head(ans$reproductive) # Plotting multi_sir <- run_multiple_get_results(model_sir)$total_hist -multi_sir <- multi_sir[multi_sir$date <= 20,] +multi_sir <- multi_sir[multi_sir$date <= 20, ] plot(multi_sir) } diff --git a/man/tool.Rd b/man/tool.Rd index f5beaa0c..0e0d3090 100644 --- a/man/tool.Rd +++ b/man/tool.Rd @@ -225,13 +225,13 @@ epitool <- tool( as_proportion = TRUE, susceptibility_reduction = .9, transmission_reduction = .5, - recovery_enhancer = .5, + recovery_enhancer = .5, death_reduction = .9 ) epitool -set_name_tool(epitool, 'Pfizer') # Assigning name to the tool +set_name_tool(epitool, "Pfizer") # Assigning name to the tool get_name_tool(epitool) # Returning the name of the tool add_tool(model_sirconn, epitool) run(model_sirconn, ndays = 100, seed = 1912) @@ -246,21 +246,21 @@ add_tool(model_sirconn, epitool) run(model_sirconn, ndays = 100, seed = 1912) # Adjusting probabilities due to tool -set_susceptibility_reduction(epitool, 0.1) # Susceptibility reduction +set_susceptibility_reduction(epitool, 0.1) # Susceptibility reduction set_transmission_reduction(epitool, 0.2) # Transmission reduction set_recovery_enhancer(epitool, 0.15) # Probability increase of recovery set_death_reduction(epitool, 0.05) # Probability reduction of death -rm_tool(model_sirconn, 0) +rm_tool(model_sirconn, 0) add_tool(model_sirconn, epitool) run(model_sirconn, ndays = 100, seed = 1912) # Run model to view changes # Using the logit function -------------- sir <- ModelSIR( - name = "COVID-19", prevalence = 0.01, + name = "COVID-19", prevalence = 0.01, transmission_rate = 0.9, recovery_rate = 0.1 - ) +) # Adding a small world population agents_smallworld( @@ -303,7 +303,7 @@ tfun <- tool_fun_logit( ) # The infection prob is lower -hist(plogis(dat \%*\% rbind(.5,1))) +hist(plogis(dat \%*\% rbind(.5, 1))) tfun # printing @@ -312,15 +312,16 @@ set_susceptibility_reduction_fun( tool = get_tool(sir, 0), model = sir, tfun = tfun - ) - +) + run(sir, ndays = 50, seed = 11) hist_1 <- get_hist_total(sir) op <- par(mfrow = c(1, 2)) -plot(hist_0); abline(v = 30) -plot(hist_1); abline(v = 30) +plot(hist_0) +abline(v = 30) +plot(hist_1) +abline(v = 30) par(op) - } diff --git a/man/virus.Rd b/man/virus.Rd index b911a4ef..d456690c 100644 --- a/man/virus.Rd +++ b/man/virus.Rd @@ -209,10 +209,10 @@ passed to \code{set_distribution_virus}. \examples{ mseirconn <- ModelSEIRCONN( name = "COVID-19", - prevalence = 0.01, + prevalence = 0.01, n = 10000, - contact_rate = 4, - incubation_days = 7, + contact_rate = 4, + incubation_days = 7, transmission_rate = 0.5, recovery_rate = 0.99 ) @@ -231,7 +231,7 @@ mseirconn rm_virus(mseirconn, 0) # Removing the first virus from the model object set_distribution_virus(delta, distribute_virus_randomly(100, as_proportion = FALSE)) -add_virus(mseirconn, delta) +add_virus(mseirconn, delta) # Setting parameters for the delta virus manually set_prob_infecting(delta, 0.5) @@ -249,9 +249,9 @@ delta2 <- virus( virus_set_state(delta2, 1, 2, 3) # Using the logit function -------------- sir <- ModelSIR( - name = "COVID-19", prevalence = 0.01, + name = "COVID-19", prevalence = 0.01, transmission_rate = 0.9, recovery = 0.1 - ) +) # Adding a small world population agents_smallworld( @@ -281,7 +281,7 @@ vfun <- virus_fun_logit( ) # The infection prob is lower -hist(plogis(dat \%*\% rbind(-1,1))) +hist(plogis(dat \%*\% rbind(-1, 1))) vfun # printing @@ -289,10 +289,9 @@ set_prob_infecting_fun( virus = get_virus(sir, 0), model = sir, vfun = vfun - ) - +) + run(sir, ndays = 50, seed = 11) plot(sir) - }