Calculate OxCGRT sub-index score for a single indicator
Source:R/calculate_index.R
calculate_subindex.Rd
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 topolicy_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 topolicyvalue_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 toflagged
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
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])
#> [1] 66.66667
x <- get_data(json = get_json_actions(ccode = "AFG",
from = NULL,
to = "2020-09-01"))
calculate_subindices(df = x$policyActions)
#> # A tibble: 23 × 10
#> policy_type_code policy_type_display policyvalue policyvalue_actual flagged
#> <chr> <chr> <int> <int> <lgl>
#> 1 C1 School closing 2 2 TRUE
#> 2 C2 Workplace closing 2 2 TRUE
#> 3 C3 Cancel public events 0 0 NA
#> 4 C4 Restrictions on gath… 0 0 NA
#> 5 C5 Close public transpo… 0 0 NA
#> 6 C6 Stay at home require… 0 0 NA
#> 7 C7 Restrictions on inte… 0 0 NA
#> 8 C8 International travel… 1 1 NA
#> 9 E1 Income support 0 0 NA
#> 10 E2 Debt/contract relief 0 0 NA
#> # ℹ 13 more rows
#> # ℹ 5 more variables: is_general <lgl>, notes <chr>,
#> # flag_value_display_field <chr>, policy_value_display_field <chr>,
#> # score <dbl>