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 |
-
"full"
— a full five–seven character postcode. -
"prefix"
— a two–four character postcode prefix. -
"suffix"
— a three character postcode suffix. -
"regex"
— a regular expression, allowing any nature of postcode match.
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:
When
squash
is set toFALSE
(the default value) an output vector will be returned that is of equal length to the input vector. Whensquash
is set toTRUE
a numeric output of length one will be returned, comprising the median Townsend deprivation score from all matched postcodes.As each postcode is only associated with a single output area, when
type
is set to"full"
andsquash
is set toFALSE
the Townsend deprivation scores returned will be the exact values associated with each linked output area.As each postcode prefix or suffix may be associated with multiple output areas, when
squash
is set toFALSE
andtype
is set to"prefix"
or"suffix"
the median Townsend deprivation score per prefix/suffix will be returned.
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.
Contains OS data (C) Crown copyright and database right 2020
Contains Royal Mail data (C) Royal Mail copyright and database right 2020
Source: Office for National Statistics licensed under the Open Government Licence v.3.0
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")