Skip to contents

Returns all indicators and data for a given time period and area. Also returns time series data for all time periods available. If tags are specified, only indicators which have one of the specified tags will be returned.

Usage

cvd_indicator(time_period_id = 1, area_id = 1, tag_id)

Arguments

time_period_id

integer - time period to return data for (compulsory)

area_id

integer - area to return data for (compulsory)

tag_id

numeric vector - allows filtering indicators by one or more tags (optional, array)

Value

List of named tibbles (indicators, categories, category_data, timeseries_data, all_data)

Details

CVD Prevent API documentation: Indicator

Examples

# Returns a list of named tibbles. To use we need to unpack the list:
return_list <- cvd_indicator(time_period_id = 17, area_id = 1103)

# See what the list contains
return_list |> summary()
#>                   Length Class  Mode
#> indicators        14     tbl_df list
#> metric_categories  7     tbl_df list
#> metric_data       19     tbl_df list
#> timeseries_data    7     tbl_df list

# extract the indicators
indicators <- return_list$indicators
indicators |>
  dplyr::select(IndicatorID, IndicatorCode, IndicatorShortName) |>
  dplyr::arrange(IndicatorID) |>
  dplyr::slice_head(n = 4)
#> # A tibble: 4 × 3
#>   IndicatorID IndicatorCode IndicatorShortName                                  
#>         <int> <chr>         <chr>                                               
#> 1           2 CVDP002HYP    Hypertension: treatment to recommended age specific…
#> 2           3 CVDP003HYP    Hypertension: treatment to recommended age specific…
#> 3           4 CVDP004HYP    Hypertension: BP monitoring                         
#> 4           7 CVDP002AF     AF: treatment with anticoagulants                   

# extract the metric categories
categories <- return_list$metric_categories
categories |>
  dplyr::filter(IndicatorID == 7, MetricCategoryID %in% c(7, 8)) |>
  dplyr::select(IndicatorID, MetricCategoryTypeName,
  CategoryAttribute, MetricCategoryName, MetricID)
#> # A tibble: 2 × 5
#>   IndicatorID MetricCategoryTypeName CategoryAttribute MetricCategoryName
#>         <int> <chr>                  <chr>             <chr>             
#> 1           7 Age group              Male              40-59             
#> 2           7 Age group              Female            40-59             
#> # ℹ 1 more variable: MetricID <int>

# extract metric data
metric_data <- return_list$metric_data
metric_data |>
  dplyr::filter(MetricID %in% c(126, 132)) |>
  dplyr::select(MetricID, Value, Numerator, Denominator)
#> # A tibble: 2 × 4
#>   MetricID Value Numerator Denominator
#>      <int> <dbl>     <dbl>       <dbl>
#> 1      126   100        15          15
#> 2      132   100        10          10

# extract the time series data
timeseries_data <- return_list$timeseries_data
timeseries_data |>
  dplyr::filter(MetricID %in% c(126, 132), !is.na(Value))
#> # A tibble: 19 × 7
#>    MetricID EndDate           Median StartDate TimePeriodID TimePeriodName Value
#>       <int> <chr>              <dbl> <chr>            <int> <chr>          <dbl>
#>  1      126 Tue, 31 Mar 2020…   84.6 Mon, 01 …            1 To March 2020  100  
#>  2      126 Wed, 31 Mar 2021…   85.7 Mon, 01 …            2 To March 2021  100  
#>  3      126 Thu, 30 Sep 2021…   86.7 Mon, 01 …            3 To September …  94.7
#>  4      126 Thu, 31 Mar 2022…   87.0 Mon, 01 …            4 To March 2022   94.7
#>  5      126 Thu, 30 Jun 2022…   86.7 Mon, 01 …            5 To June 2022    88.9
#>  6      126 Fri, 30 Sep 2022…   87.5 Mon, 01 …            6 To September …  90  
#>  7      126 Sat, 31 Dec 2022…   88.2 Mon, 01 …            7 To December 2…  94.1
#>  8      126 Fri, 31 Mar 2023…   89.5 Mon, 01 …            8 To March 2023   94.7
#>  9      126 Fri, 30 Jun 2023…   89.2 Mon, 01 …            9 To June 2023    94.7
#> 10      126 Sun, 31 Dec 2023…   90   Mon, 01 …           15 To December 2…  94.1
#> 11      126 Sun, 31 Mar 2024…   90.9 Mon, 01 …           17 To March 2024  100  
#> 12      132 Thu, 31 Mar 2022…   81.8 Mon, 01 …            4 To March 2022  100  
#> 13      132 Thu, 30 Jun 2022…   81.8 Mon, 01 …            5 To June 2022   100  
#> 14      132 Fri, 30 Sep 2022…   81.8 Mon, 01 …            6 To September … 100  
#> 15      132 Sat, 31 Dec 2022…   83.3 Mon, 01 …            7 To December 2… 100  
#> 16      132 Fri, 31 Mar 2023…   83.3 Mon, 01 …            8 To March 2023  100  
#> 17      132 Fri, 30 Jun 2023…   84.6 Mon, 01 …            9 To June 2023   100  
#> 18      132 Sun, 31 Dec 2023…   84.6 Mon, 01 …           15 To December 2… 100  
#> 19      132 Sun, 31 Mar 2024…   88.1 Mon, 01 …           17 To March 2024  100  

# indicators are searcheable by one or more Tag.
return_list <-
  cvd_indicator(time_period_id = 17, area_id = 3, tag_id = c(3, 4))