getTDS {QDiabetes}R Documentation

Lookup Townsend Deprivation Scores from UK Postcodes

Description

Convenient function to look up Townsend deprivation scores using UK postcodes, postcode prefixes, postcode suffixes or a regular expression.

Usage

getTDS(postcode, type = "full", squash = ifelse(type != "regex", FALSE, TRUE))

Arguments

postcode

A vector of UK postcodes, postcode prefixes, postcode suffixes, or a regular expression.

type

A character string indicating the term provided in the postcode parameter. Possible values are:

squash

a logical parameter indicating whether the scores returned should be aggregated into a single median value.

Details

getTDS is a lookup function that queries a dataset of postcodes and Townsend deprivation scores. This dataset was created by joining a dataset of postcodes to a dataset of Townsend deprivation scores, via output area codes. Both data sets are made available by the Office for National Statistics under the Open Government License. The postcode dataset was last updated in February 2019, while the dataset of Townsend deprivation scores uses values obtained from the 2011 UK census (matching the Townsend deprivation score dates used by ClinRisk in the derivation of the QDiabetes-2018 algorithms).

Value

Townsend Deprivation Score.

Where type is not set to "regex", the length and nature of the value returned are governed by the type and squash parameters:

Note

PO Box codes have no associated Townsend deprivation scores and will not work as function inputs. No Northern Ireland postcodes are present in the database searched by getTDS as their use is governed by a separate, more restrictive license.

Author(s)

Benjamin G. Feakins benjamin.feakins@ndph.ox.ac.uk

Source

UK Postcode-to-output-area data were obtained here from the Office for National Statistics.

Output-area-to-Townsend-deprivation-scores data were obtained here from the Office for National Statistics.

Examples

## Simple usage
getTDS(postcode = "OX2 6GG")
getTDS(postcode = c("OX2 6NW", "OX3 7LF"))

## Case & white space insensitive
getTDS(postcode = c("OX37LF", "OX3 7LF", "ox37lf", "ox3 7lf"))

## Median Townsend Deprivaton Score per Postcode Prefix ##
getTDS(postcode = paste0("OX", 1:9), type = "prefix")

## Median Overall Townsend Deprivation Score for a Set of Prefixes ##
getTDS(postcode = paste0("OX", 1:9), type = "prefix", squash = TRUE)

## Median Townsend Deprivaton Score per Postcode Suffix ##
getTDS(postcode = paste0(1:9, "AA"), type = "suffix")

## Median Overall Townsend Deprivation Score for a Set of Prefixes ##
getTDS(postcode = paste0(1:9, "AA"), type = "suffix", squash = TRUE)

## Median Overall Townsend Deprivation Score for Postcodes Matching a Regular Expression ##
getTDS(postcode = "^OX37[A-Z]{2}$", type = "regex")

[Package QDiabetes version 1.0-2 Index]