Worked examples for phe_sii function

Introduction

This vignette provides examples of how to use the phe_sii function with different kinds of indicators.

The following packages must be installed and loaded if not already available

# source functions required
library(PHEindicatormethods)
library(dplyr)

Function and inputs

phe_sii is an aggregate function, returning the slope index of inequality (SII) statistic for each grouping set in the inputted dataframe, with lower and upper confidence limits based on the specified confidence. The user can choose whether to return the Relative Index of Inequality (RII) via an optional argument in the function.

Each grouping set in the input data should have a row for each quantile, labelled with the quantile number, which contains the associated population, indicator value and 95% confidence limits. The user has the option to provide the standard error instead of the 95% confidence limits, in which case this is used directly rather than being calculated by the function.

The user can also specify the indicator type from “0 - default”, “1 - rate” or “2 - proportion”, where different transformations are applied to the input indicator value and confidence limits in the case of a rate or proportion. Examples are provided below for the three cases.

Example 1 - default (normal) distribution

The example below calculates the SII on some life expectancy data. This is assumed to have symmetric confidence intervals around the indicator values, so default standard error calculations would be done (involving no prior transformations).

The relevant fields in the input dataset are specified for the arguments quantile, population and value. value_type is kept equal to 0 (default), and the number of repetitions set to 1000 for faster running of the function as a demonstration.

The standard error (se) has been provided here in the input dataset, meaning this will be used directly and lower/upper 95% confidence limits of the indicator values are not needed.

A warning is generated because one of the GeoCodes (E06000053) in the data does not contain a record for every quantile so no output is provided for this area.


# Pass data through SII function ---------------------------------------
LE_data_SII <- LE_data %>%
        # Group the input dataframe to create subgroups to calculate the SII for
        group_by(Sex, GeoCode) %>% 
        # Run SII function on grouped dataset
        phe_sii(quantile = Decile,
                population = Pop ,
                value = LifeExp,
                value_type = 0, # specify default indicator type
                confidence = c(0.95, 0.998),
                se = SE,
                repetitions = 1000,
                rii = FALSE,
                type = "full") # use smaller no. of repetitions e.g. for testing
#> Warning in phe_sii(., quantile = Decile, population = Pop, value = LifeExp, :
#> WARNING: some records have been removed due to incomplete or invalid data

# View first 10 rows of results
knitr::kable(head(LE_data_SII, 10))  
Sex GeoCode sii sii_lower95_0cl sii_upper95_0cl sii_lower99_8cl sii_upper99_8cl indicator_type multiplier transform CI_confidence CI_method
1 E06000001 11.68886 9.168408 13.97666 7.720956 15.00830 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000002 12.54785 10.427743 14.51780 9.369982 15.29341 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000003 10.05084 8.028534 12.20890 6.614927 12.95070 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000004 14.85223 13.001218 16.42934 11.578135 17.37028 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000005 11.68095 9.301220 14.13498 7.131959 15.15956 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000006 12.27526 10.112061 14.52338 8.076530 15.61090 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000007 11.59893 9.919546 13.11788 9.154041 14.20975 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000008 10.72510 8.476051 12.76296 6.574896 14.02997 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000009 13.59387 11.498310 15.52968 9.897635 16.66558 normal 1 none 95%, 99.8% simulation 1000 reps
1 E06000010 11.20094 9.672415 12.61791 8.672109 13.21949 normal 1 none 95%, 99.8% simulation 1000 reps

Note that some areas are missing quantiles in the dataset, and these are subsequently excluded from the function output with a warning given.

Example 2 - rate

The example below calculates both the SII and RII on Directly Standardised Rate (DSR) data. The value_type argument is set to 1 to specify this indicator is a rate; this means a log transformation will be applied to the value, lower_cl and upper_cl fields before calculating the standard error. The transform argument is set to TRUE because rates do not show a linear relationship across the quantiles so a log transformation will be applied before calculating the SII and then reverted once the SII has been calculated to ensure the SII is given in the original units.

As the number of repetitions is not specified, the function will run on the default 100,000. To return the RII, the rii argument is set to TRUE.

Finally, setting reliability_stat = TRUE will run additional sample sets of the SII/RII confidence limits and return a Mean Average Difference (MAD) value for each subgroup. See below for guidance on how to use this.


# Pass data through SII function ---------------------------------------
DSR_data_SII <- DSR_data %>%
        # Group the input dataframe to create subgroups to calculate the SII for
        group_by(Period) %>% 
        # Run SII function on grouped dataset
        phe_sii(quantile = Quintile,
                population = total_pop ,
                value = value,
                value_type = 1, # specifies indicator is a rate
                lower_cl = lowercl,
                upper_cl = uppercl,
                transform = TRUE,
                rii = TRUE, # returns RII as well as SII (default is FALSE)
                reliability_stat = TRUE) # returns reliability stats (default is FALSE)

# View results
knitr::kable(DSR_data_SII)  
Period sii rii sii_lower95_0 sii_upper95_0 rii_lower95_0 rii_upper95_0 sii_mad95_0 rii_mad95_0 indicator_type multiplier transform CI_confidence CI_method
2010 -14.03684 0.9010655 -17.97811 -10.146642 0.8751240 0.9274451 0.0234944 0.0001571 rate 1 log 95% simulation 1e+05 reps
2011 -12.83196 0.9086641 -16.70894 -8.939911 0.8827748 0.9354365 0.0136774 0.0000929 rate 1 log 95% simulation 1e+05 reps
2012 -11.09234 0.9199455 -14.95422 -7.241970 0.8936288 0.9469718 0.0178689 0.0001231 rate 1 log 95% simulation 1e+05 reps
2013 -10.06041 0.9266342 -13.85506 -6.221805 0.9004021 0.9539631 0.0229077 0.0001637 rate 1 log 95% simulation 1e+05 reps
2014 -10.06085 0.9263086 -13.81445 -6.289236 0.9002485 0.9532685 0.0135240 0.0000958 rate 1 log 95% simulation 1e+05 reps
2015 -8.53077 0.9368534 -12.22840 -4.818631 0.9107526 0.9638217 0.0181906 0.0001304 rate 1 log 95% simulation 1e+05 reps

Example 3 - proportion

This example calculates the SII for a prevalence indicator. Proportions need to be between 0 and 1 - this formatting is done in the mutate command below, before passing the grouped dataset to the phe_sii function.

The value_type argument is set to 2 to specify the indicator is a proportion, and a logit transformation is applied to the value, lower_cl and upper_cl fields before calculating the standard error. The transform argument is set to TRUE because proportions do not show a linear relationship across the quantiles so a logit transformation will be applied before calculating the SII and then reverted once the SII has been calculated to ensure the SII is given in the original units.

The function will again run on the default 100,000 reps, and neither the RII or MAD values will be returned.

There is the option to specify a numeric multiplier in the arguments, which will scale the SII, SII_lowerCL, SII_upperCL (and SII_MAD) before outputting. This could be used if an absolute (i.e. positive) slope is desired for an indicator, where the “high is bad” polarity would otherwise give negative SII results.

Below, a multiplier of -100 is used, to output absolute prevalence figures that are expressed on a scale between 0 and 100.


# Pass data through SII function ---------------------------------------
prevalence_SII <- prevalence_data %>%
          # Group the input dataframe to create subgroups to calculate the SII for
        group_by(Period, SchoolYear, AreaCode) %>% 
          # Format prevalences to be between 0 and 1
        mutate(Rate = Rate/100,
               LCL = LCL/100,
               UCL = UCL/100) %>% 
           # Run SII function on grouped dataset
        phe_sii(quantile = Decile,
                        population = Measured,
                        value = Rate,
                        value_type = 2, # specifies indicator is a proportion
                        lower_cl = LCL,
                        upper_cl = UCL,
                        transform = TRUE,
                        multiplier = -100) # negative multiplier to scale SII outputs

# View first 10 rows of results
knitr::kable(head(prevalence_SII,10)) 
Period SchoolYear AreaCode sii sii_lower95_0 sii_upper95_0 indicator_type multiplier transform CI_confidence CI_method
607 6 E92000001 10.964626 10.439506 11.489417 proportion -100 logit 95% simulation 1e+05 reps
607 R E92000001 5.970062 5.549233 6.393388 proportion -100 logit 95% simulation 1e+05 reps
708 6 E92000001 11.271798 10.879529 11.661644 proportion -100 logit 95% simulation 1e+05 reps
708 R E92000001 6.200092 5.894184 6.507201 proportion -100 logit 95% simulation 1e+05 reps
809 6 E92000001 11.804672 11.421531 12.186043 proportion -100 logit 95% simulation 1e+05 reps
809 R E92000001 6.911770 6.615907 7.206786 proportion -100 logit 95% simulation 1e+05 reps
910 6 E92000001 12.459329 12.075018 12.841109 proportion -100 logit 95% simulation 1e+05 reps
910 R E92000001 7.141644 6.850106 7.433279 proportion -100 logit 95% simulation 1e+05 reps
1011 6 E92000001 13.057800 12.672642 13.444791 proportion -100 logit 95% simulation 1e+05 reps
1011 R E92000001 7.139306 6.856602 7.424345 proportion -100 logit 95% simulation 1e+05 reps

Interpreting the Mean Average Difference (MAD)

If reliability_stat is set to TRUE in the function, a MAD value is returned for each subgroup as a measure of how much the SII (or RII) confidence limits vary.

Note: this option will increase the runtime of the function, as the MAD calculation involves an additional 9 sample sets of the confidence limits to be taken.

A MAD of 0.005 implies that, on rerunning the phe_sii function, the confidence limits can be expected to change by approximately 0.005. The more repetitions the function is run on, the smaller this statistic should be. The tolerance will depend on the level of accuracy to which the user wishes to present the confidence limits - ideally, to display them to 1 d.p., the MAD should be smaller than 0.01. To 2 d.p., smaller than 0.001, etc.