Title: | An Interface to the Oxford COVID-19 Government Response Tracker API |
---|---|
Description: | 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 for their purposes. This package facilitates access to the OxCGRT data via its API <https://covidtracker.bsg.ox.ac.uk/> and includes functions to calculate the various OxCGRT indices in R. |
Authors: | Ernest Guevarra [aut, cre] |
Maintainer: | Ernest Guevarra <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0.9000 |
Built: | 2024-10-27 05:20:14 UTC |
Source: | https://github.com/OxfordIHTM/oxcgrt |
Calculate an OxCGRT index or indices
calculate_index(df, codes, tolerance) calculate_gov_response(df) calculate_containment_health(df) calculate_stringency(df) calculate_economic_support(df) calculate_indices(df)
calculate_index(df, codes, tolerance) calculate_gov_response(df) calculate_containment_health(df) calculate_stringency(df) calculate_economic_support(df) calculate_indices(df)
df |
A data.frame produced by a call to |
codes |
A vector of policy type codes to use for the index calculation. |
tolerance |
An integer specifying the number of missing values above which index will not be calculated and reported. |
A numeric value for mean subindex scores of specified policy types.
For calculate_indices()
, a tibble calculated OxCGRT indices
Ernest Guevarra based on calculation methods by 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.
## Get policy actions data for Afghanistan on 1 September 2020 x <- get_data(json = get_json_actions(ccode = "AFG", from = NULL, to = "2020-09-01")) ## Calculate OxCGRT subindices y <- calculate_subindices(df = x$policyActions) ## Calculate OxCGRT index calculate_index(df = y, codes = c(paste("C", 1:8, sep = ""), paste("E", 1:2, sep = ""), paste("H", 1:3, sep = ""), "H6"), tolerance = 1) ## Calculate OxCGRT government response index calculate_gov_response(df = y) ## Calculate OxCGRT containment and health index calculate_containment_health(df = y) ## Calculate OxCGRT stringency index calculate_stringency(df = y) ## Calculate OxCGRT economic support index calculate_economic_support(df = y) ## Calculate all OxCGRT indices calculate_indices(df = y)
## Get policy actions data for Afghanistan on 1 September 2020 x <- get_data(json = get_json_actions(ccode = "AFG", from = NULL, to = "2020-09-01")) ## Calculate OxCGRT subindices y <- calculate_subindices(df = x$policyActions) ## Calculate OxCGRT index calculate_index(df = y, codes = c(paste("C", 1:8, sep = ""), paste("E", 1:2, sep = ""), paste("H", 1:3, sep = ""), "H6"), tolerance = 1) ## Calculate OxCGRT government response index calculate_gov_response(df = y) ## Calculate OxCGRT containment and health index calculate_containment_health(df = y) ## Calculate OxCGRT stringency index calculate_stringency(df = y) ## Calculate OxCGRT economic support index calculate_economic_support(df = y) ## Calculate all OxCGRT indices calculate_indices(df = y)
Calculate OxCGRT sub-index score for a single indicator
Calculate OxCGRT sub-index scores for all indicators
calculate_subindex(indicator_code, value, flag_value) calculate_subindices( df, indicator_code = "policy_type_code", value = "policyvalue_actual", flag_value = "flagged", add = TRUE )
calculate_subindex(indicator_code, value, flag_value) calculate_subindices( df, indicator_code = "policy_type_code", value = "policyvalue_actual", flag_value = "flagged", add = TRUE )
indicator_code |
A character value specifying the name of the variable
in |
value |
A character value specifying the name of the column in |
flag_value |
A character value specifying the name of the column in |
df |
A data.frame containing per indicator values required for
calculating sub-index scores. This data.frame will be structured similarly
as the policy actions data.frame produced by a call to
|
add |
Logical. Should sub-indices for each indicator be added to |
A numeric value between 0 to 100.
If add
is TRUE (default), returns a tibble composed of the input
data.frame x
with an added column named score for the calculated
sub-indices. If add
is FALSE, returns a tibble of 4 columns with the
first column for the policy codes named policy_type_codes
, the second
column for the policy values named policy_value
, the third column for
the flag values named flag_value
and the fourth column named score
for
the calculated sub-indices.
Ernest Guevarra based on calculation methods by 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.
calculate_subindex(indicator_code = indicatorData$indicator[1], value = indicatorData$value[1], flag_value = indicatorData$flag_value[1]) x <- get_data(json = get_json_actions(ccode = "AFG", from = NULL, to = "2020-09-01")) calculate_subindices(df = x$policyActions)
calculate_subindex(indicator_code = indicatorData$indicator[1], value = indicatorData$value[1], flag_value = indicatorData$flag_value[1]) x <- get_data(json = get_json_actions(ccode = "AFG", from = NULL, to = "2020-09-01")) calculate_subindices(df = x$policyActions)
Codebook for the Oxford COVID-19 Government Response Tracker
codebook
codebook
A tibble with 47 rows and 6 columns:
Variable | Description |
ID |
Policy indicator identifier |
Name |
Name of policy indicator |
Description |
Description of policy indicator |
Measurement |
Measurement of policy indicator |
Coding |
Coding of measurement |
Policy Group |
Name of group policy indicator |
https://github.com/OxCGRT/covid-policy-tracker/blob/master/documentation/codebook.md
Get policy actions and stringency data from JSON
get_data(json)
get_data(json)
json |
A JSON string, URL or file created using |
A tibble of time series stringency index data if json
is a time
series endpoint or a named list of two tibbles (the first tibble is
named policyActions
and the second tibble is named stringencyData
) if
json
is a policy actions endpoint.
## Get time series JSON endpoint x <- get_json_time(from = "2020-10-29", to = "2020-10-31") ## Get time series stringency index data get_data(x) ## Get policy actions JSON endpoint x <- get_json_actions(ccode = "AFG", from = NULL, to = "2020-07-16") ## Get data on policy actions and stringency index get_data(x)
## Get time series JSON endpoint x <- get_json_time(from = "2020-10-29", to = "2020-10-31") ## Get time series stringency index data get_data(x) ## Get policy actions JSON endpoint x <- get_json_actions(ccode = "AFG", from = NULL, to = "2020-07-16") ## Get data on policy actions and stringency index get_data(x)
Get policy actions data from JSON
get_data_action(json) get_data_actions(json)
get_data_action(json) get_data_actions(json)
json |
A JSON string, URL or file created using |
A tibble of policy actions with their respective policy values for specified country/countries and specified date/dates.
## Get relevant JSON for Afghanistan on 01 January 2022 x <- get_json_actions(ccode = "AFG", from = NULL, to = "2022-01-01") ## Get data on policy actions get_data_action(x) ## Get relevant JSON for Afghanistan and Philippines for whole month of ## October x <- get_json_actions(ccode = c("AFG", "PH"), from = "2020-10-29", to = "2020-10-30") ## Get data on policy actions get_data_actions(x)
## Get relevant JSON for Afghanistan on 01 January 2022 x <- get_json_actions(ccode = "AFG", from = NULL, to = "2022-01-01") ## Get data on policy actions get_data_action(x) ## Get relevant JSON for Afghanistan and Philippines for whole month of ## October x <- get_json_actions(ccode = c("AFG", "PH"), from = "2020-10-29", to = "2020-10-30") ## Get data on policy actions get_data_actions(x)
Get time series stringency index data from JSON
get_data_time(json)
get_data_time(json)
json |
A JSON string, URL or file created using |
A tibble of time series stringency index data
x <- get_json_time(from = "2020-07-18", to = "2020-07-20") get_data_time(x)
x <- get_json_time(from = "2020-07-18", to = "2020-07-20") get_data_time(x)
Get legacy data version 1
get_data_v1( type = c("complete", "timeseries"), pcode = c("s1", "s2", "s3", "s4", "s5", "s6", "s7", "s11", "s12", "s13"), notes = TRUE, directory = NULL, tidy = FALSE ) get_data_v1_complete(notes = TRUE, directory = NULL) get_data_v1_timeseries( pcode = c("s1", "s2", "s3", "s4", "s5", "s6", "s7", "s11", "s12", "s13"), directory = NULL, tidy = FALSE )
get_data_v1( type = c("complete", "timeseries"), pcode = c("s1", "s2", "s3", "s4", "s5", "s6", "s7", "s11", "s12", "s13"), notes = TRUE, directory = NULL, tidy = FALSE ) get_data_v1_complete(notes = TRUE, directory = NULL) get_data_v1_timeseries( pcode = c("s1", "s2", "s3", "s4", "s5", "s6", "s7", "s11", "s12", "s13"), directory = NULL, tidy = FALSE )
type |
A character value for type of dataset to retrieve. Either "complete" for the full dataset or "timeseries" for the disaggregated policy indicators datasets. Default is "complete". |
pcode |
A character value for policy indicator code to retrieve if
|
notes |
Logical. Should "complete" dataset be retrieved with notes or
not. Default is TRUE. Ignored if |
directory |
If NULL (default), required dataset is read into current environment. If specified, required dataset is downloaded into this directory with the filename given by the OxCGRT. |
tidy |
Logical. Should "timeseries" dataset be converted to tidy format? Default is FALSE. |
If directory
is NULL, a tibble (or a list of two tibbles) of the
specified dataset. Otherwise, a file path/s to the downloaded file/s.
get_data_v1_complete() get_data_v1_timeseries() get_data_v1()
get_data_v1_complete() get_data_v1_timeseries() get_data_v1()
Get JSON for OxCGRT data
get_json_time(from = "2020-01-02", to = Sys.Date()) get_json_actions(ccode, from = "2020-01-02", to = Sys.Date())
get_json_time(from = "2020-01-02", to = Sys.Date()) get_json_actions(ccode, from = "2020-01-02", to = Sys.Date())
from |
Start date for stringency index data to be collected. This can go
as far back as 2020-01-02 (Default). Format |
to |
End date for stringency index data to be collected. This defaults
to current date. Format |
ccode |
ISO 3166-1 alpha-2 country code, alpha-3 country code, or full country name string or vector of strings (mix of alpha-2 code or alpha-3 code or country names is valid). |
A character object for specified JSON time series endpoint, or a character string or a character vector for specified JSON policy actions endpoint or endpoints.
Ernest Guevarra
## Get JSON for Afghanistan at 7 days previous to current date get_json_actions(ccode = "AFG", from = NULL, to = as.character(Sys.Date() - 7)) ## Get JSON for Afghanistan and Philippines from 1 October to 31 October 2020 get_json_actions(ccode = c("Afghanistan", "PH"), from = "2020-10-01", to = "2020-10-31") ## Get JSON time series endpoint for all data available from OxCGRT get_json_time()
## Get JSON for Afghanistan at 7 days previous to current date get_json_actions(ccode = "AFG", from = NULL, to = as.character(Sys.Date() - 7)) ## Get JSON for Afghanistan and Philippines from 1 October to 31 October 2020 get_json_actions(ccode = c("Afghanistan", "PH"), from = "2020-10-01", to = "2020-10-31") ## Get JSON time series endpoint for all data available from OxCGRT get_json_time()
Example indicator data for sub-index calculations
indicatorData
indicatorData
A tibble with 16 rows and 6 columns
Variable | Description |
indicator |
Policy indicator code |
value |
Policy indicator value |
flag_value |
Policy indicator flag value |
max_value |
Maximum value for policy indicator |
flag |
Does the policy indicator have a flag value? 1 = Yes; 0 = No |
score |
Policy indicator score from 0 - 100 |
https://github.com/OxCGRT/covid-policy-tracker/blob/master/documentation/index_methodology.md
Table of OxCGRT dataset files available from OxCGRT GitHub data repositories
oxcgrt_data_files
oxcgrt_data_files
A tibble with 90 rows and 6 columns
Variable | Description |
version |
OxCGRT dataset version. Either v1, v2, or final |
filename |
Filename of dataset file |
path |
Path of dataset file |
url |
GitHub URL to dataset file |
url_raw |
GitHub raw URL to dataset file |
sha |
SHA-1 hash value for dataset file |