Skip to content

Commit

Permalink
Adding defunct message
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jun 8, 2024
1 parent c22106e commit 9607b1e
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 52 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ export(add_entity)
export(add_globalevent)
export(add_tool)
export(add_tool_agent)
export(add_tool_n)
export(add_virus)
export(add_virus_agent)
export(add_virus_n)
export(agents_from_edgelist)
export(agents_smallworld)
export(change_state)
Expand Down
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# epiworldR 0.2-1 (dev)
# epiworldR 0.3-0 (dev)

* Adds the new mixing models `ModelSIRMixing` and `ModelSEIRMixing`.

* Ports the `Entity` class. Entities are used to group agents within a model.

* Refactors `add_tool`, `add_virus`, and `add_entity` simplifying syntax. Now,
these functions only receive the model and object. Prevalence is
specified in the object itself.
specified in the object itself. `add_tool_n` and `add_virus_n` are now
deprecated.

* `globalaction_*` are now defunct. Use `globalevent_*` instead.


Check notice on line 14 in NEWS.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

NEWS.md#L14

Expected: 1; Actual: 2
# epiworldR 0.1-0`
Expand Down
31 changes: 29 additions & 2 deletions R/functions-renamed.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#' Deprecated functions in epiworldR
#' Deprecated and removed functions in epiworldR
#' @description
#' Starting version 0.0-4, epiworld changed how it refered to "actions."
#' Following more traditional ABMs, actions are now called "events."
#'
#' @param ... Arguments to be passed to the new function.
#' @param model Model object of class `epiworld_model`.
#' @param tool Tool object of class `epiworld_tool`.
#' @param virus Virus object of class `epiworld_virus`.
#' @name epiworldR-deprecated
NULL
NULL

#' @param n Deprecated. Either set the prevalence during the tool/virus
#' initialization or use `set_prevalence_tool`/`set_prevalence_virus`.
#' @export
#' @rdname epiworldR-deprecated
add_tool_n <- function(model, tool, n) {

.Deprecated(new = "add_tool")

set_prevalence_tool(tool, n, as_proportion = FALSE)
add_tool(model, tool)

}

#' @export
#' @rdname epiworldR-deprecated
add_virus_n <- function(model, virus, n) {

.Deprecated(new = "add_virus")
set_prevalence_virus(virus, n, as_proportion = FALSE)
add_virus(model, virus)

}
13 changes: 6 additions & 7 deletions R/global-actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ globalevent_tool <- function(
#' @rdname epiworldR-deprecated
globalaction_tool <- function(...) {

.Deprecated(
.Defunct(
new = "globalevent_tool"
)
)

globalevent_tool(...)

}

#' @export
Expand Down Expand Up @@ -134,7 +132,7 @@ globalevent_tool_logit <- function(
#' @rdname epiworldR-deprecated
globalaction_tool_logit <- function(...) {

.Deprecated(
.Defunct(
new = "globalevent_tool_logit"
)

Expand Down Expand Up @@ -172,7 +170,8 @@ globalevent_set_params <- function(
#' @rdname epiworldR-deprecated
globalaction_set_params <- function(...) {

.Deprecated(

.Defunct(
new = "globalevent_set_params"
)

Expand Down Expand Up @@ -234,7 +233,7 @@ globalevent_fun <- function(
#' @rdname epiworldR-deprecated
globalaction_fun <- function(...) {

.Deprecated(
.Defunct(
new = "globalevent_fun"
)

Expand Down
21 changes: 19 additions & 2 deletions R/tool.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,31 @@ get_name_tool <- function(tool) {

#' @export
#' @param tool An object of class `epiworld_tool`
#' @param proportion Deprecated. Either set the prevalence during the tool
#' initialization or use `set_prevalence_tool`.
#' @details
#' The `add_tool` function adds the specified tool to the model of class
#' [epiworld_model] with specified proportion.
#' @rdname tool
add_tool <- function(model, tool) UseMethod("add_tool")
add_tool <- function(model, tool, proportion) {

if (!missing(proportion)) {

warning(
"The 'proportion' argument is deprecated. ",
"Use 'set_prevalence_tool' instead."
)

set_prevalence_tool(tool, proportion, TRUE)

}

UseMethod("add_tool")

}

#' @export
add_tool.epiworld_model <- function(model, tool) {
add_tool.epiworld_model <- function(model, tool, proportion) {

stopifnot_tool(tool)
add_tool_cpp(model, tool)
Expand Down
37 changes: 27 additions & 10 deletions R/virus.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,30 @@ get_name_virus <- function(virus) {
#' @rdname virus
#' @param model An object of class `epiworld_model`.
#' @param virus An object of class `epiworld_virus`
#' @param proportion Deprecated. Either set the prevalence during the virus
#' initialization or use `set_prevalence_virus`.
#' @returns
#' - The `add_virus` function does not return a value, instead it adds the
#' virus of choice to the model object of class [epiworld_model].
add_virus <- function(model, virus) UseMethod("add_virus")
add_virus <- function(model, virus, proportion) {

if (!missing(proportion)) {

warning(
"The argument 'proportion' is deprecated and will be removed in ",
"the next version."
)

set_prevalence_virus(virus, proportion, as_proportion = TRUE)

}

UseMethod("add_virus")

}

#' @export
add_virus.epiworld_model <- function(model, virus) {
add_virus.epiworld_model <- function(model, virus, proportion) {

stopifnot_virus(virus)
add_virus_cpp(model, virus)
Expand All @@ -158,7 +175,7 @@ add_virus.epiworld_model <- function(model, virus) {
}

#' @export
add_virus.epiworld_sir <- function(model, virus) {
add_virus.epiworld_sir <- function(model, virus, proportion) {

stopifnot_virus(virus)
virus_set_state(virus, init = 1, end = 2, removed = 2)
Expand All @@ -167,7 +184,7 @@ add_virus.epiworld_sir <- function(model, virus) {
}

#' @export
add_virus.epiworld_sird <- function(model, virus) {
add_virus.epiworld_sird <- function(model, virus, proportion) {

stopifnot_virus(virus)
virus_set_state(virus, init = 1, end = 2, removed = 3)
Expand All @@ -176,15 +193,15 @@ add_virus.epiworld_sird <- function(model, virus) {
}

#' @export
add_virus.epiworld_sirconn <- function(model, virus) {
add_virus.epiworld_sirconn <- function(model, virus, proportion) {

stopifnot_virus(virus)
add_virus.epiworld_sir(model, virus)

}

#' @export
add_virus.epiworld_sirdconn <- function(model, virus) {
add_virus.epiworld_sirdconn <- function(model, virus, proportion) {

stopifnot_virus(virus)
add_virus.epiworld_sird(model, virus)
Expand All @@ -193,7 +210,7 @@ add_virus.epiworld_sirdconn <- function(model, virus) {


#' @export
add_virus.epiworld_seir <- function(model, virus) {
add_virus.epiworld_seir <- function(model, virus, proportion) {

stopifnot_virus(virus)
virus_set_state(virus, init = 1, end = 3, removed = 3)
Expand All @@ -202,7 +219,7 @@ add_virus.epiworld_seir <- function(model, virus) {
}

#' @export
add_virus.epiworld_seird <- function(model, virus) {
add_virus.epiworld_seird <- function(model, virus, proportion) {

stopifnot_virus(virus)
virus_set_state(virus, init = 1, end = 3, removed = 4)
Expand All @@ -211,15 +228,15 @@ add_virus.epiworld_seird <- function(model, virus) {
}

#' @export
add_virus.epiworld_seirconn <- function(model, virus) {
add_virus.epiworld_seirconn <- function(model, virus, proportion) {

stopifnot_virus(virus)
add_virus.epiworld_seir(model, virus)

}

#' @export
add_virus.epiworld_seirdconn <- function(model, virus) {
add_virus.epiworld_seirdconn <- function(model, virus, proportion) {

stopifnot_virus(virus)
add_virus.epiworld_seird(model, virus)
Expand Down
61 changes: 35 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ summary(sir)
#> Number of entities : 0
#> Days (duration) : 50 (of 50)
#> Number of viruses : 1
#> Last run elapsed t : 162.00ms
#> Last run speed : 30.85 million agents x day / second
#> Last run elapsed t : 163.00ms
#> Last run speed : 30.49 million agents x day / second
#> Rewiring : off
#>
#> Global events:
Expand Down Expand Up @@ -197,7 +197,16 @@ model_seirconn <- ModelSEIRCONN(
incubation_days = 7,
transmission_rate = 0.1,
recovery_rate = 1/7
) |> add_virus(virus("COVID-19", 0.01, 0.6, 0.5, 7), .5)
) |> add_virus(
virus(
name = "COVID-19",
prevalence = 0.01,
as_proportion = TRUE,
prob_infecting = 0.01,
recovery_rate = 0.6,
prob_death = 0.5,
incubation = 7
))

set.seed(132)
run(model_seirconn, ndays = 100)
Expand All @@ -219,16 +228,16 @@ summary(model_seirconn)
#> Number of entities : 0
#> Days (duration) : 100 (of 100)
#> Number of viruses : 2
#> Last run elapsed t : 34.00ms
#> Last run speed : 29.33 million agents x day / second
#> Last run elapsed t : 36.00ms
#> Last run speed : 27.62 million agents x day / second
#> Rewiring : off
#>
#> Global events:
#> - Update infected individuals (runs daily)
#>
#> Virus(es):
#> - COVID-19 (baseline prevalence: 1.00%)
#> - COVID-19 (baseline prevalence: 50.00%)
#> - COVID-19 (baseline prevalence: 1.00%)
#>
#> Tool(s):
#> (none)
Expand All @@ -240,15 +249,15 @@ summary(model_seirconn)
#> - Prob. Transmission : 0.1000
#>
#> Distribution of the population at time 100:
#> - (0) Susceptible : 4900 -> 229
#> - (1) Exposed : 5100 -> 8
#> - (2) Infected : 0 -> 27
#> - (3) Recovered : 0 -> 9736
#> - (0) Susceptible : 9800 -> 13
#> - (1) Exposed : 200 -> 0
#> - (2) Infected : 0 -> 1
#> - (3) Recovered : 0 -> 9986
#>
#> Transition Probabilities:
#> - Susceptible 0.97 0.03 0.00 0.00
#> - Susceptible 0.94 0.06 0.00 0.00
#> - Exposed 0.00 0.86 0.14 0.00
#> - Infected 0.00 0.00 0.78 0.22
#> - Infected 0.00 0.00 0.85 0.15
#> - Recovered 0.00 0.00 0.00 1.00
```

Expand All @@ -269,13 +278,13 @@ head(plot(repnum))

<img src="man/figures/README-seir-conn-figures-2.png" width="100%" />

#> virus_id virus date avg n sd lb ub
#> 1 0 COVID-19 0 3.671053 76 3.012809 1 12.0
#> 2 0 COVID-19 2 2.714286 7 4.347961 0 10.8
#> 3 0 COVID-19 3 3.461538 13 4.539005 0 12.8
#> 4 0 COVID-19 4 3.307692 13 3.923957 0 12.1
#> 5 0 COVID-19 5 2.074074 27 2.615427 0 9.0
#> 6 0 COVID-19 6 3.421053 19 2.968647 0 9.1
#> virus_id virus date avg n sd lb ub
#> 1 0 COVID-19 0 5.615385 91 4.832228 1.0 17.0
#> 2 0 COVID-19 2 5.000000 9 3.605551 0.2 10.4
#> 3 0 COVID-19 3 6.000000 13 5.049752 0.0 13.0
#> 4 0 COVID-19 4 4.592593 27 3.885469 0.0 12.7
#> 5 0 COVID-19 5 4.846154 26 4.920913 0.0 14.5
#> 6 0 COVID-19 6 4.236842 38 3.241906 0.0 12.0

``` r

Expand All @@ -284,13 +293,13 @@ head(plot_generation_time(model_seirconn))

<img src="man/figures/README-seir-conn-figures-3.png" width="100%" />

#> date avg n sd ci_lower ci_upper virus virus_id
#> 1 2 3.250000 4 1.258306 2.075 4.850 COVID-19 0
#> 2 3 11.600000 10 8.733079 2.000 26.975 COVID-19 0
#> 3 4 11.545455 11 6.890046 4.000 23.000 COVID-19 0
#> 4 5 9.666667 18 8.791707 2.425 30.775 COVID-19 0
#> 5 6 9.571429 14 6.618323 2.650 24.450 COVID-19 0
#> 6 7 10.045455 22 6.168100 2.525 25.900 COVID-19 0
#> date avg n sd ci_lower ci_upper virus virus_id
#> 1 2 7.125000 8 2.474874 2.7 9.825 COVID-19 0
#> 2 3 8.090909 11 7.203534 2.0 23.750 COVID-19 0
#> 3 4 6.708333 24 4.338695 2.0 16.425 COVID-19 0
#> 4 5 7.428571 21 4.738897 2.0 15.500 COVID-19 0
#> 5 6 7.628571 35 4.173345 2.0 15.300 COVID-19 0
#> 6 7 6.921053 38 4.675304 2.0 16.150 COVID-19 0

## SIR Logit

Expand Down
11 changes: 10 additions & 1 deletion man/epiworldR-deprecated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/README-multiple-example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-seir-conn-figures-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-seir-conn-figures-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-seir-conn-figures-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9607b1e

Please sign in to comment.