zscore: z-scores

Description Usage Arguments Value Examples

View source: R/z_score_fun.R

Description

zscores calculates standardized scores or z-scores, with a mean close to zero and standard deviation (sd) close to one, for the variable given in variable. The standardization uses a population weighted mean and standard deviation, which are calculated based on the population distribution given by population.

Usage

1
zscore(population, variable)

Arguments

population

Population counts.

variable

Continuous deprivation measure, such as a percentage, to calculate the z-scores for.

Value

A list including the following:

z.score

standardized score using weighted mean and sd

w.mean

weighted mean

w.sd

weighted standard deviation

weight

population weight

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data <- dep_data

# store all results in object z_oc
z_oc <- zscore(data$total_pop, data$pcnt_overcrowding)

# extract z-score
data$z_overcrowd <- z_oc$z.score
mean(data$z_overcrowd) # mean of z-score
sd(data$z_overcrowd) # sd z-score

# extract weighted mean and sd, compare weighted values to unweighted values
mean(data$pcnt_overcrowding)
z_oc$w.mean
sd(data$pcnt_overcrowding)
z_oc$w.sd

SocEpi documentation built on July 2, 2020, 1:07 a.m.