R/calculate_index.R
calculate_subindex.Rd
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
)
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.
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.
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.
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()
.
Logical. Should sub-indices for each indicator be added to df
?
Default is TRUE.
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.
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_act… flagged
#> <chr> <chr> <int> <int> <lgl>
#> 1 C1 School closing 2 2 TRUE
#> 2 C2 Workplace closing 0 0 NA
#> 3 C3 Cancel public events 0 0 NA
#> 4 C4 Restrictions on gather… 0 0 NA
#> 5 C5 Close public transport 0 0 NA
#> 6 C6 Stay at home requireme… 0 0 NA
#> 7 C7 Restrictions on intern… 0 0 NA
#> 8 C8 International travel c… 1 1 NA
#> 9 E1 Income support 0 0 NA
#> 10 E2 Debt/contract relief 0 0 NA
#> # … with 13 more rows, and 5 more variables: is_general <lgl>, notes <chr>,
#> # flag_value_display_field <chr>, policy_value_display_field <chr>,
#> # score <dbl>