Calculate OxCGRT sub-index scores for all indicators

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

Arguments

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

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.

add

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

Value

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

Ernest Guevarra

Examples

x <- get_data(json = get_json_actions(ccode = "AFG", from = NULL, to = "2020-09-01")) calculate_subindices(df = x$policyActions)
#> # A tibble: 18 x 10 #> policy_type_code policy_type_dis… policyvalue policyvalue_act… flagged #> <chr> <chr> <int> <int> <lgl> #> 1 C1 School closing 2 2 TRUE #> 2 C2 Workplace closi… 0 0 NA #> 3 C3 Cancel public e… 0 0 NA #> 4 C4 Restrictions on… 0 0 NA #> 5 C5 Close public tr… 0 0 NA #> 6 C6 Stay at home re… 0 0 NA #> 7 C7 Restrictions on… 0 0 NA #> 8 C8 International t… 1 1 NA #> 9 E1 Income support 0 0 NA #> 10 E2 Debt/contract r… 0 0 NA #> 11 E3 Fiscal measures 0 0 NA #> 12 E4 International s… 0 0 NA #> 13 H1 Public informat… 2 2 TRUE #> 14 H2 Testing policy 3 3 NA #> 15 H3 Contact tracing 2 2 NA #> 16 H4 Emergency inves… 0 0 NA #> 17 H5 Investment in v… 0 0 NA #> 18 H6 Facial Coverings 3 3 TRUE #> # … with 5 more variables: is_general <lgl>, notes <chr>, #> # flag_value_display_field <chr>, policy_value_display_field <chr>, #> # score <dbl>