w_pcntile: Function to create population weighted deprivation...

Description Usage Arguments Value Examples

View source: R/w_pcntile_fun.R

Description

Function to create population weighted deprivation percentiles

Usage

1
w_pcntile(data, population, variable, p = 10, low = FALSE)

Arguments

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 p=10.

low

should low values of the percentile correspond to high deprivation, defaults to FALSE – higher values correspond to higher deprivation

Value

Numeric vector of percentiles (default 1 to 10) of same length as population and variable

Examples

 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)

m-allik/SocEpi documentation built on May 23, 2020, 8:02 p.m.