Description Usage Arguments Value Examples
View source: R/w_pcntile_fun.R
Function to create population weighted deprivation percentiles
| 1 | 
| data | name of the dataset | 
| population | distribution (in numbers) | 
| variable | the deprivation measure to calculate the percentiles for | 
| p | the number of percentiles/groups to split the data in. Default is deciles  | 
| low | should low values of the percentile correspond to high deprivation, defaults to FALSE – higher values correspond to higher deprivation | 
Numeric vector of percentiles (default 1 to 10) of same length as population and variable
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | data <- dep_data
#calculate deciles for overcrowding
data$dec_overcrowd <- w_pcntile(data, total_pop, pcnt_overcrowding)
#average percent of overcrowding by decile
tapply(data$pcnt_overcrowding, data$dec_overcrowd, mean)
#percent of people in each decile
round(tapply(data$total_pop, data$dec_overcrowd, sum)/sum(data$total_pop)*100, 1)
#calculate quintiles from deciles
data$Q_overcrowd <- cut(data$dec_overcrowd, breaks = 5, labels = 1:5)
#calculate quintiles with w_pcntile
data$Q_overcrowd2 <- w_pcntile(data, total_pop, pcnt_overcrowding, p = 5)
#compare results - note small differences
table(data$Q_overcrowd, data$Q_overcrowd2)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.