The Oxford COVID-19 Government Response Tracker (OxCGRT) tracks and compares worldwide government responses to the COVID-19 pandemic rigorously and consistently. OxCGRT makes available systematic information in a consistent way, aiding those who require information have access to it efficiently. This package facilitates access to the OxCGRT data for R users via version 2 of its API. This package also includes functions to calculate the various OxCGRT indices in R. This package is aimed at R users who use or plan to use the OxCGRT data for their research or for other academic purposes or who develop or want to develop other metrics or indices that build on the OxCGRT approach.
oxcgrt
do?
The oxcgrt
package has two main sets of functions
that:
Retrieve OxCGRT
data (get_*
functions) via version 2 of its API;
and,
Calculate various OxCGRT
indicators,
sub-indices and indices (calculate_*
functions).
There are other R packages
that provide access to data from the OxCGRT.
The COVID19
package and the oxcovid19
package are just two examples of these. However, all these packages
provide access to the OxCGRT
data as data dumps and only for the time-series of the
stringency index per country. To our knowledge, the oxcgrt
package is the only R package
currently that provides an interface to the available API for querying
and retrieving data. Also, the oxcgrt
package provides
functions to calculate the OxCGRT
sub-indices and indices based on their methodology. None of the other R packages that we have seen and
reviewed have this functionality.
You can install the released version of oxcgrt from CRAN with:
install.packages("oxcgrt")
And the development version from GitHub with:
if(!require(remotes)) install.packages("remotes")
remotes::install_github("como-ph/oxcgrt")
oxcgrt
data retrieval workflow via API
The retrieve data functions are based on the OxCGRT’s JSON API described here. Two API endpoints are provided: 1) endpoint for JSON providing data for stringency index by country over time; and, 2) endpoint for JSON providing data on policy actions and stringency index for a specific country on a specific day.
For each of these endpoints, the data retrieval workflow is composed of two steps: first is the creation of the appropriate API URL query; and, second is the retrieval of the appropriate data as per query into a data.frame structure usable in R. This workflow is show in code below:
## Load oxcgrt package
library(oxcgrt)
## Step 1: Create the appropriate API URL query for time series data from
## 1 June 2020 up to current day
query <- get_json_time(from = "2020-06-01")
## Step 2: Retrieve the data
get_data_time(query)
This results in the following:
#> # A tibble: 121,658 × 9
#> date_value country_code country_name confirmed deaths stringency_actu…
#> <date> <chr> <chr> <int> <int> <dbl>
#> 1 2020-06-01 FIN Finland 6986 305 44.4
#> 2 2020-06-01 DNK Denmark 11699 576 60.2
#> 3 2020-06-01 LBN Lebanon 1233 27 74.1
#> 4 2020-06-01 GUY Guyana 153 12 87.0
#> 5 2020-06-01 PSE Palestinian Territ… 449 3 80.6
#> 6 2020-06-01 AFG Afghanistan 15836 269 84.3
#> 7 2020-06-01 SVK Slovakia 1522 28 67.6
#> 8 2020-06-01 VEN Venezuela 1662 17 85.2
#> 9 2020-06-01 HKG Hong Kong SAR China 1087 4 52.8
#> 10 2020-06-01 VNM Vietnam 328 0 69.4
#> # … with 121,648 more rows, and 3 more variables: stringency <dbl>,
#> # stringency_legacy <dbl>, stringency_legacy_disp <dbl>
The oxcgrt
functions are designed to work with pipe
operators via the magrittr
package. The steps shown above
can be replicated using pipe operators as follows:
## Load magrittr package
library(magrittr)
get_json_time(from = "2020-06-01") %>% ## Step 1: Creat API URL query
get_data_time() ## Step 2: Retrieve data
This results in the same output as the earlier workflow albeit sorted alphabetically by country code:
#> # A tibble: 121,658 × 9
#> date_value country_code country_name confirmed deaths stringency_actu…
#> <date> <chr> <chr> <int> <int> <dbl>
#> 1 2020-06-01 FIN Finland 6986 305 44.4
#> 2 2020-06-01 DNK Denmark 11699 576 60.2
#> 3 2020-06-01 LBN Lebanon 1233 27 74.1
#> 4 2020-06-01 GUY Guyana 153 12 87.0
#> 5 2020-06-01 PSE Palestinian Territ… 449 3 80.6
#> 6 2020-06-01 AFG Afghanistan 15836 269 84.3
#> 7 2020-06-01 SVK Slovakia 1522 28 67.6
#> 8 2020-06-01 VEN Venezuela 1662 17 85.2
#> 9 2020-06-01 HKG Hong Kong SAR China 1087 4 52.8
#> 10 2020-06-01 VNM Vietnam 328 0 69.4
#> # … with 121,648 more rows, and 3 more variables: stringency <dbl>,
#> # stringency_legacy <dbl>, stringency_legacy_disp <dbl>
For more detailed examples of how to retrieve data via the OxCGRT API version 2, read Retrieve data via OxCGRT API.
oxcgrt
calculate workflow
The calculate_*
functions are based on the OxCGRT’s
methodology described here.
There are two sets of calculate functions included in
oxcgrt
. The first calculates the OxCGRT
sub-indices and the second calculates the four OxCGRT
indices which are composed of various combinations of
the indicators used by OxCGRT
sub-indices and indices.
For more detailed examples of how to calculate the various OxCGRT sub-indices and indices, read Calculate OxCGRT sub-indices and indices.
The oxcgrt
package comes with helpful datasets which
serve as guides to facilitate in usage and interpretation of the OxCGRT
data.
The OxCGRT
provides an authoritative codebook found here.
The oxcgrt
package has extracted the tables from this
documentation into a single codebook that can serve as a handy and
convenient reference for an R
user when working with OxCGRT
data in R. The OxCGRT
codebook can be accessed as follows:
codebook
which outputs the codebook as a singular table in tbl
format as shown below:
#> # A tibble: 29 × 6
#> ID Name Description Measurement Coding `Policy Group`
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 C1 C1_School closing "Record cl… Ordinal sc… 0 - n… Containment a…
#> 2 C1 C1_Flag "" Binary fla… 0 - t… Containment a…
#> 3 C2 C2_Workplace closing "Record cl… Ordinal sc… 0 - n… Containment a…
#> 4 C2 C2_Flag "" Binary fla… 0 - t… Containment a…
#> 5 C3 C3_Cancel public events "Record ca… Ordinal sc… 0 - n… Containment a…
#> 6 C3 C3_Flag "" Binary fla… 0 - t… Containment a…
#> 7 C4 C4_Restrictions on gathe… "Record li… Ordinal sc… 0 - n… Containment a…
#> 8 C4 C4_Flag "" Binary fla… 0 - t… Containment a…
#> 9 C5 C5_Close public transport "Record cl… Ordinal sc… 0 - n… Containment a…
#> 10 C5 C5_Flag "" Binary fla… 0 - t… Containment a…
#> # … with 19 more rows
The current oxcgrt
package version includes the OxCGRT
codebook version 2.5 released on 4 November 2020.
In the OxCGRT
methodology document,
an example indicator dataset is used to demonstrate the calculation of
per indicator sub-indices and the four main indices that OxCGRT
provides. This example dataset has been made available in table format
in the oxcgrt
package and can be accessed as follows:
indicatorData
which outputs the example data as a singular table in
tbl
format as shown below:
#> # A tibble: 14 × 6
#> indicator value flag_value max_value flag score
#> <chr> <int> <int> <int> <int> <dbl>
#> 1 C1 2 1 3 1 66.7
#> 2 C2 NA NA 3 1 0
#> 3 C3 2 0 2 1 75
#> 4 C4 2 0 4 1 37.5
#> 5 C5 0 NA 2 1 0
#> 6 C6 1 0 3 1 16.7
#> 7 C7 1 1 2 1 50
#> 8 C8 3 NA 4 0 75
#> 9 E1 2 0 2 1 75
#> 10 E2 2 NA 2 0 100
#> 11 H1 2 0 2 1 75
#> 12 H2 3 NA 3 0 100
#> 13 H3 2 NA 2 0 100
#> 14 H6 2 0 4 1 37.5
This dataset is used by the oxcgrt
package to test the
calculate_*
functions and for demonstrating how these
functions work. This dataset can be useful for those trying to learn the
OxCGRT’s
calculation methods and R users
who are learning how to use the oxcgrt
package
calculate_*
functions.
The current version of oxcgrt
package is
experimental in that its stability and future development would
depend on the OxCGRT‘s
current and future development. The OxCGRT
is in continuous evolution given that the COVID-19 pandemic is still
on-going and various governments’ responses to it are continuously
changed and/or updated. The OxCGRT
has also been developing other indices that capture other aspects of
governments’ responses not yet covered by current indices.
The oxcgrt
package author and maintainer commit to
ensuring that current functions are maintained and/or updated in a
manner that ensures backwards compatibility should changes to the data
structure and/or to the indices calculation are implemented by the OxCGRT
team. This would include maintaining the arguments used by the current
functions, maintaining the functionality of the current functions, and
maintaining the type of outputs of the current functions. Should changes
implemented by the OxCGRT
team to the data structure and/or to the indices calculation require the
breaking of the syntax, functionality and/or outputs of the current
functions, a formal and proper deprecation process will be implemented
that include proper and detailed documentation of the changes and the
potential impact on current users.
The oxcgrt
package is an independent development and is
separate from and not recognised and approved by the OxCGRT
team. The author and maintainer of the package is not affiliated with OxCGRT
but is committed to ensure fidelity to the methods and usage specified
by OxCGRT
and accuracy of outputs described and required by OxCGRT.
Any mistakes, problems and issues with the functionality and outputs
of the oxcgrt
including mistakes in interpretation of the
calculation of the sub-indices and indices noted (if any) are that of
the author and maintainer and not of the OxCGRT.
Hence any problems and issues to the usage, functionality and outputs of
the oxcgrt
package should be addressed directly to the
author and maintainer here.
When using the oxcgrt
package, please cite both the
source of the OxCGRT
data and oxcgrt
package itself.
For the source of the OxCGRT data, the following citation is recommended:
Hale, Thomas, Noam Angrist, Emily Cameron-Blake, Laura Hallas, Beatriz Kira, Saptarshi Majumdar, Anna Petherick, Toby Phillips, Helen Tatlow, Samuel Webster (2020). Oxford COVID-19 Government Response Tracker, Blavatnik School of Government.
For the oxcgrt
package, the suggested citation can be
obtained using a call to the citation
function as
follows:
citation("oxcgrt")
#>
#> To cite oxcgrt in publications use:
#>
#> Ernest Guevarra (2020). oxcgrt: An Interface to the Oxford COVID-19
#> Government Response Tracker API. R package version 0.1.0. URL
#> https://como-ph.github.io/oxcgrt/
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Manual{,
#> title = {oxcgrt: An Interface to the Oxford COVID-19 Government Response Tracker API},
#> author = {Ernest Guevarra},
#> year = {2020},
#> note = {R package version 0.1.0},
#> url = {https://como-ph.github.io/oxcgrt/},
#> }
Feedback, bug reports and feature requests are welcome; file issues or seek support here. If you would like to contribute to the package, please see our contributing guidelines.
This project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.