Learn R Programming

SocEpi (version 1.0.0)

w_pcntile: Function to create population weighted deprivation percentiles

Description

Function to create population weighted deprivation percentiles

Usage

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

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab