Detect outlier values by country.

detect_outliers(df, var = "value", alpha = 0.05)

Arguments

df

data.frame: A pddcs formatted data frame. Output of fetch_indicator().

var

character: Column to use for outlier detection. Defaults to "value".

alpha

numeric: Significance level for a two-tailed test. Defaults to 0.05.

Value

tibble

Details

[Experimental]

Examples

# Fetch source data
df <- fetch_indicator('SH.MED.PHYS.ZS', source = 'who')

# Detect outliers (alpha = 0.05)
df2 <- detect_outliers(df)
df2[df2$outlier,]
#> # A tibble: 84 × 8
#>    iso3c  year indicator      value note                  source outlier p_value
#>    <chr> <dbl> <chr>          <dbl> <chr>                 <chr>  <lgl>     <dbl>
#>  1 ALB    2018 SH.MED.PHYS.ZS 2.16  Plausible bound is 2… who    TRUE      1.00 
#>  2 ALB    2020 SH.MED.PHYS.ZS 1.88  Plausible bound is 1… who    TRUE      0.983
#>  3 ARM    2017 SH.MED.PHYS.ZS 4.40  Plausible bound is 4… who    TRUE      1.00 
#>  4 AUS    2020 SH.MED.PHYS.ZS 4.13  Plausible bound is 4… who    TRUE      0.987
#>  5 AZE    2019 SH.MED.PHYS.ZS 3.17  Plausible bound is 3… who    TRUE      0.989
#>  6 BEL    2020 SH.MED.PHYS.ZS 6.08  Plausible bound is 6… who    TRUE      1.00 
#>  7 BGD    2020 SH.MED.PHYS.ZS 0.667 Plausible bound is 6… who    TRUE      0.977
#>  8 BGR    2018 SH.MED.PHYS.ZS 4.21  Plausible bound is 4… who    TRUE      0.984
#>  9 BRA    2019 SH.MED.PHYS.ZS 2.31  Plausible bound is 2… who    TRUE      0.976
#> 10 CHN    2018 SH.MED.PHYS.ZS 2.10  Plausible bound is 2… who    TRUE      0.980
#> # … with 74 more rows

# Detect outliers (alpha = 0.01)
df3 <- detect_outliers(df, alpha = 0.01)
df3[df3$outlier,]
#> # A tibble: 16 × 8
#>    iso3c  year indicator      value note                  source outlier p_value
#>    <chr> <dbl> <chr>          <dbl> <chr>                 <chr>  <lgl>     <dbl>
#>  1 ALB    2018 SH.MED.PHYS.ZS 2.16  Plausible bound is 2… who    TRUE      1.00 
#>  2 ARM    2017 SH.MED.PHYS.ZS 4.40  Plausible bound is 4… who    TRUE      1.00 
#>  3 BEL    2020 SH.MED.PHYS.ZS 6.08  Plausible bound is 6… who    TRUE      1.00 
#>  4 CYP    2019 SH.MED.PHYS.ZS 3.14  Plausible bound is 3… who    TRUE      0.996
#>  5 ESP    1990 SH.MED.PHYS.ZS 2.03  Plausible bound is 2… who    TRUE      0.999
#>  6 HUN    2020 SH.MED.PHYS.ZS 6.06  Plausible bound is 6… who    TRUE      1.00 
#>  7 ITA    1993 SH.MED.PHYS.ZS 5.48  Plausible bound is 5… who    TRUE      0.997
#>  8 ITA    1994 SH.MED.PHYS.ZS 5.58  Plausible bound is 5… who    TRUE      0.998
#>  9 JOR    1998 SH.MED.PHYS.ZS 0.989 Plausible bound is 9… who    TRUE      0.999
#> 10 LTU    2020 SH.MED.PHYS.ZS 5.08  Plausible bound is 5… who    TRUE      0.999
#> 11 NIC    2018 SH.MED.PHYS.ZS 1.66  Plausible bound is 1… who    TRUE      0.998
#> 12 POL    2020 SH.MED.PHYS.ZS 3.77  Plausible bound is 3… who    TRUE      1.00 
#> 13 SRB    2016 SH.MED.PHYS.ZS 3.11  Plausible bound is 3… who    TRUE      0.999
#> 14 SWE    2019 SH.MED.PHYS.ZS 7.09  Plausible bound is 7… who    TRUE      1.00 
#> 15 TKM    2002 SH.MED.PHYS.ZS 7.09  Plausible bound is 7… who    TRUE      1.00 
#> 16 TTO    2018 SH.MED.PHYS.ZS 5.41  Plausible bound is 5… who    TRUE      0.996