Skip to content

Commit

Permalink
Adding codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jun 6, 2024
1 parent 97337a0 commit b4eb34d
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 42 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: Coverage

jobs:
coverage:
runs-on: ubuntu-latest
name: Coverage

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/[email protected]

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: check

- name: Running coverage
run: |
# Files to exclude
files <- list.files("inst/", full.names = TRUE, recursive = TRUE)
# Run coverage
covr::codecov(
line_exclusions = as.list(files),
token = Sys.getenv("CODECOV_TOKEN")
)
shell: Rscript {0}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ knitr::opts_chunk$set(
[![R-CMD-check](https://github.com/UofUEpiBio/epiworldR/actions/workflows/r.yml/badge.svg)](https://github.com/UofUEpiBio/epiworldR/actions/workflows/r.yml)
[![CRANlogs downloads](https://cranlogs.r-pkg.org/badges/grand-total/epiworldR)](https://cran.r-project.org/package=epiworldR)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/UofUEpiBio/epiworldR/blob/master/LICENSE.md)
[![codecov](https://codecov.io/gh/UofUEpiBio/epiworldR/graph/badge.svg?token=ZB8FVLI7GN)](https://codecov.io/gh/UofUEpiBio/epiworldR)
<!-- badges: end -->

This R package is a wrapper of the C++ library [epiworld](https://github.com/UofUEpiBio/epiworld){target="_blank"}. It provides a general framework for modeling disease transmission using [agent-based models](https://en.wikipedia.org/w/index.php?title=Agent-based_model&oldid=1153634802){target="_blank"}. Some of the main features include:
Expand Down
88 changes: 61 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ status](https://www.r-pkg.org/badges/version/epiworldR)](https://CRAN.R-project.
downloads](https://cranlogs.r-pkg.org/badges/grand-total/epiworldR)](https://cran.r-project.org/package=epiworldR)
[![License:
MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/UofUEpiBio/epiworldR/blob/master/LICENSE.md)
[![codecov](https://codecov.io/gh/UofUEpiBio/epiworldR/graph/badge.svg?token=ZB8FVLI7GN)](https://codecov.io/gh/UofUEpiBio/epiworldR)
<!-- badges: end -->

This R package is a wrapper of the C++ library
Expand Down Expand Up @@ -96,6 +97,9 @@ sir <- ModelSIR(
#> |Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> | done.
```

``` r

sir
#> ________________________________________________________________________________
Expand All @@ -119,8 +123,8 @@ summary(sir)
#> Number of entities : 0
#> Days (duration) : 50 (of 50)
#> Number of viruses : 1
#> Last run elapsed t : 141.00ms
#> Last run speed : 35.22 million agents x day / second
#> Last run elapsed t : 165.00ms
#> Last run speed : 30.13 million agents x day / second
#> Rewiring : off
#>
#> Global events:
Expand All @@ -145,6 +149,9 @@ summary(sir)
#> - Susceptible 0.91 0.09 0.00
#> - Infected 0.00 0.70 0.30
#> - Recovered 0.00 0.00 1.00
```

``` r
plot(sir)
```

Expand Down Expand Up @@ -175,12 +182,15 @@ run(model_seirconn, ndays = 100)
#> Running the model...
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> done.
```

``` r
model_seirconn
#> ________________________________________________________________________________
#> Susceptible-Exposed-Infected-Removed (SEIR) (connected)
#> It features 10000 agents, 2 virus(es), and 0 tool(s).
#> The model has 4 states.
#> The final distribution is: 608 Susceptible, 4 Exposed, 2 Infected, and 9386 Recovered.
#> The final distribution is: 634 Susceptible, 5 Exposed, 0 Infected, and 9361 Recovered.
```

Computing some key statistics
Expand All @@ -200,15 +210,18 @@ head(plot(repnum))

<img src="man/figures/README-unnamed-chunk-4-2.png" width="100%" />

#> virus_id virus date avg n sd lb ub
#> 1 0 COVID-19 0 2.858974 78 2.592318 1 7.30
#> 2 0 COVID-19 2 1.964286 28 1.914509 0 5.65
#> 3 0 COVID-19 3 2.761905 21 2.321740 0 7.00
#> 4 0 COVID-19 4 2.000000 33 1.887459 0 6.40
#> 5 0 COVID-19 5 1.864865 37 2.225636 0 9.10
#> 6 0 COVID-19 6 2.104167 48 2.667692 0 10.65
#> virus_id virus date avg n sd lb ub
#> 1 0 COVID-19 0 2.762500 80 2.082135 1.0 7.025
#> 2 0 COVID-19 2 3.250000 24 2.862805 0.0 9.850
#> 3 0 COVID-19 3 3.294118 17 2.663755 0.4 9.400
#> 4 0 COVID-19 4 2.666667 18 2.351470 0.0 7.875
#> 5 0 COVID-19 5 1.878788 33 1.745666 0.0 5.800
#> 6 0 COVID-19 6 1.794118 34 1.533058 0.0 4.350

plot_incidence(model_seirconn)
``` r

plot_incidence(model_seirconn)
```

<img src="man/figures/README-unnamed-chunk-4-3.png" width="100%" />

Expand All @@ -218,13 +231,13 @@ head(plot_generation_time(model_seirconn))

<img src="man/figures/README-unnamed-chunk-4-4.png" width="100%" />

#> date avg n sd ci_lower ci_upper virus virus_id
#> 1 2 5.714286 21 4.681270 2 17.00 COVID-19 0
#> 2 3 7.444444 18 4.501271 2 15.45 COVID-19 0
#> 3 4 7.192308 26 5.578668 2 20.75 COVID-19 0
#> 4 5 7.111111 27 4.236593 2 15.70 COVID-19 0
#> 5 6 7.575000 40 7.249713 2 30.20 COVID-19 0
#> 6 7 6.303030 33 4.531038 2 18.00 COVID-19 0
#> date avg n sd ci_lower ci_upper virus virus_id
#> 1 2 8.400000 20 6.227274 2.475 24.150 COVID-19 0
#> 2 3 8.750000 16 6.547264 2.375 21.750 COVID-19 0
#> 3 4 7.625000 16 5.302515 2.375 19.000 COVID-19 0
#> 4 5 5.888889 27 3.178453 2.000 12.700 COVID-19 0
#> 5 6 10.148148 27 5.586410 2.000 21.400 COVID-19 0
#> 6 7 8.458333 24 6.064717 2.000 20.825 COVID-19 0

## SIR Logit

Expand Down Expand Up @@ -275,6 +288,9 @@ run(model_logit, 50)
#> |Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> | done.
```

``` r
plot(model_logit)
```

Expand All @@ -291,6 +307,9 @@ rn <- get_reproductive_number(model_logit)
) |> prop.table())[,2]
#> 0 1
#> 0.12984 0.14201
```

``` r

# Looking into the agents
get_agents(model_logit)
Expand Down Expand Up @@ -332,6 +351,9 @@ sir <- ModelSIR(
#> |Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> | done.
```

``` r

# Transmission network
net <- get_transmissions(sir)
Expand All @@ -340,6 +362,9 @@ net <- get_transmissions(sir)
library(epiworldR)
library(netplot)
#> Loading required package: grid
```

``` r
x <- igraph::graph_from_edgelist(
as.matrix(net[,2:3]) + 1
)
Expand Down Expand Up @@ -378,6 +403,9 @@ run_multiple(model_sir, ndays = 100, nsims = 50, saver = saver, nthread = 2)
#> _________________________________________________________________________
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> done.
```

``` r

# Retrieving the results
ans <- run_multiple_get_results(model_sir)
Expand All @@ -387,17 +415,23 @@ head(ans$total_hist)
#> 1 1 0 1 Susceptible 990
#> 2 1 0 1 Infected 10
#> 3 1 0 1 Recovered 0
#> 4 1 1 1 Susceptible 974
#> 5 1 1 1 Infected 25
#> 4 1 1 1 Susceptible 977
#> 5 1 1 1 Infected 22
#> 6 1 1 1 Recovered 1
```

``` r
head(ans$reproductive)
#> sim_num virus_id virus source source_exposure_date rt
#> 1 1 0 COVID-19 767 11 0
#> 2 1 0 COVID-19 835 10 0
#> 3 1 0 COVID-19 793 9 0
#> 4 1 0 COVID-19 612 9 0
#> 5 1 0 COVID-19 466 9 0
#> 6 1 0 COVID-19 920 8 0
#> 1 1 0 COVID-19 976 9 0
#> 2 1 0 COVID-19 644 9 0
#> 3 1 0 COVID-19 608 9 0
#> 4 1 0 COVID-19 314 9 0
#> 5 1 0 COVID-19 41 9 0
#> 6 1 0 COVID-19 32 9 0
```

``` r

plot(ans$reproductive)
```
Expand Down Expand Up @@ -427,7 +461,7 @@ citation("epiworldR")
#> And the actual R package:
#>
#> Meyer D, Vega Yon G (2024). _epiworldR: Fast Agent-Based Epi Models_.
#> R package version 0.1-0, <https://github.com/UofUEpiBio/epiworldR>.
#> R package version 0.2-1, <https://github.com/UofUEpiBio/epiworldR>.
#>
#> To see these entries in BibTeX format, use 'print(<citation>,
#> bibtex=TRUE)', 'toBibtex(.)', or set
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-get.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set.seed(1231)
# to check that.
expect_equal(nrow(get_hist_tool(model)), 0L)
expect_equal(nrow(get_hist_total(model)), 0L)
expect_equal(nrow(get_hist_variant(model)), 0L)
expect_equal(nrow(get_hist_virus(model)), 0L)
expect_equal(nrow(get_reproductive_number(model)), 0L)
expect_equal(dim(get_transition_probability(model)), c(3, 3))
expect_equal(nrow(get_hist_transition_matrix(model)), 0L)
Expand Down
23 changes: 13 additions & 10 deletions inst/tinytest/test-sir.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ agents_smallworld(

# Initializing
queuing_off(sir_0)
init(sir_0, days = 50, seed = 1912)

# Running and printing
run(sir_0)
run(sir_0, ndays = 50, seed = 1912)

tmat_0 <- get_transition_probability(sir_0)

Expand All @@ -40,19 +39,23 @@ agents_smallworld(
p = .01
)

# Initializing
init(sir_1, days = 50, seed = 1912)

# Running and printing
run(sir_1)
run(sir_1, ndays = 50, seed = 1912)

tmat_1 <- get_transition_probability(sir_1)

# Expected
tmat_expected <- structure(c(0.90395575761795, 0, 0, 0.0959785506129265, 0.707067608833313,
0, 6.55534968245775e-05, 0.292932420969009, 1), dim = c(3L, 3L
), dimnames = list(c("Susceptible", "Infected", "Recovered"),
c("Susceptible", "Infected", "Recovered")))
tmat_expected <- structure(
c(
0.963432729244232, 0, 0, 0.0365671403706074, 0.702733814716339,
0, 0, 0.297266155481339, 1
),
dim = c(3L, 3L),
dimnames = list(
c("Susceptible", "Infected", "Recovered"),
c("Susceptible", "Infected", "Recovered")
)
)

expect_equivalent(tmat_0, tmat_1)
expect_equivalent(tmat_0, tmat_expected)
Expand Down
Binary file modified man/figures/README-unnamed-chunk-4-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-unnamed-chunk-4-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-unnamed-chunk-4-3.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-unnamed-chunk-4-4.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-unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions playground/epiworld_presentation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ agents_smallworld(
p = .01
)
# Initializing
init(seir, days = 100, seed = 1912)
# Running and printing
run(seir)
run(seir, ndays = 100, seed = 1912)
seir
```
Expand Down

0 comments on commit b4eb34d

Please sign in to comment.