Package 'oxcgrt'

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

Help Index


Calculate an OxCGRT index or indices

Description

Calculate an OxCGRT index or indices

Usage

calculate_index(df, codes, tolerance)

calculate_gov_response(df)

calculate_containment_health(df)

calculate_stringency(df)

calculate_economic_support(df)

calculate_indices(df)

Arguments

df

A data.frame produced by a call to calculate_subindices().

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.

Value

A numeric value for mean subindex scores of specified policy types. For calculate_indices(), a tibble calculated OxCGRT indices

Author(s)

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.

Examples

## 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

Description

Calculate OxCGRT sub-index score for a single indicator

Calculate OxCGRT sub-index scores for all indicators

Usage

calculate_subindex(indicator_code, value, flag_value)

calculate_subindices(
  df,
  indicator_code = "policy_type_code",
  value = "policyvalue_actual",
  flag_value = "flagged",
  add = TRUE
)

Arguments

indicator_code

A character value specifying the name of the variable in df containing the policy type codes. By default, this is set to policy_type_code which is the variable name used by the OxCGRT API.

value

A character value specifying the name of the column in df containing the values in ordinal scale assigned to each policy type. By default, this is set to policyvalue_actual which is the variable name used by the OxCGRT API.

flag_value

A character value specifying the name of the column in df containing the flag values for each policy type. By default, this is set to flagged which is the variable name used by the OxCGRT API.

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 get_data_actions().

add

Logical. Should sub-indices for each indicator be added to df? Default is TRUE.

Value

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.

Author(s)

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.

Examples

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

Description

Codebook for the Oxford COVID-19 Government Response Tracker

Usage

codebook

Format

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

Source

https://github.com/OxCGRT/covid-policy-tracker/blob/master/documentation/codebook.md


Get policy actions and stringency data from JSON

Description

Get policy actions and stringency data from JSON

Usage

get_data(json)

Arguments

json

A JSON string, URL or file created using get_json_time() or get_json_actions().

Value

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.

Examples

## 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

Description

Get policy actions data from JSON

Usage

get_data_action(json)

get_data_actions(json)

Arguments

json

A JSON string, URL or file created using get_json_actions() or a vector of JSON strings or URLs.

Value

A tibble of policy actions with their respective policy values for specified country/countries and specified date/dates.

Examples

## 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

Description

Get time series stringency index data from JSON

Usage

get_data_time(json)

Arguments

json

A JSON string, URL or file created using get_json_time()

Value

A tibble of time series stringency index data

Examples

x <- get_json_time(from = "2020-07-18", to = "2020-07-20")

get_data_time(x)

Get legacy data version 1

Description

Get legacy data version 1

Usage

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
)

Arguments

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 type is "timeseries". Ignored if type is "complete". Can be one of "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", or "s13".

notes

Logical. Should "complete" dataset be retrieved with notes or not. Default is TRUE. Ignored if type is "timeseries".

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.

Value

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.

Examples

get_data_v1_complete()
get_data_v1_timeseries()
get_data_v1()

Get JSON for OxCGRT data

Description

Get JSON for OxCGRT data

Usage

get_json_time(from = "2020-01-02", to = Sys.Date())

get_json_actions(ccode, from = "2020-01-02", to = Sys.Date())

Arguments

from

Start date for stringency index data to be collected. This can go as far back as 2020-01-02 (Default). Format YYYY-MM-DD. Accepts either character string or date class.

to

End date for stringency index data to be collected. This defaults to current date. Format YYYY-MM-DD. Accepts either character string or date class.

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).

Value

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.

Author(s)

Ernest Guevarra

Examples

## 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

Description

Example indicator data for sub-index calculations

Usage

indicatorData

Format

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

Source

https://github.com/OxCGRT/covid-policy-tracker/blob/master/documentation/index_methodology.md


Table of OxCGRT dataset files available from OxCGRT GitHub data repositories

Description

Table of OxCGRT dataset files available from OxCGRT GitHub data repositories

Usage

oxcgrt_data_files

Format

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