get_beta_params_age: Get Beta parameters for age groups

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/funcs.R

Description

This function finds the two shape parameters for the Beta distribution for aggregated age groups given individual-level vaccination data. The individual-level data is comprised of the age of the individual (age) and a binary indicator of vaccination status (vacc). The function first uses a Binomial GAM to estimate the mean (mu) and variance (sigma) of the proportion vaccinated for each of the defined age groups and then finds the shape parameters of the Beta distribution analytically using get_beta_params.

Usage

1
get_beta_params_age(age = NULL, vacc = NULL, breaks = NULL)

Arguments

age

a vector giving the age at vaccination of each individual

vacc

a binary vector indicating the vaccination status of each individual

breaks

a scalar or vector of age group breaks (passed to .bincode). If NULL (default), calculates Beta parameters for all data together.

Details

Note that a Binomial GLM is used if the number of age groups is 2 or less.

Value

A dataframe containing the sample size, mu, sigma, and Beta distribution paramters for each age group

Author(s)

John Giles

See Also

Other beta_params: get_beta_params()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# dhs_namibia_2013 vaccination coverage file downloaded from the website
data("dhs_namibia_2013_namibia_2013")

# For all observations together (population mean)
tmp <- get_beta_params_age(age=dhs_namibia_2013$age.in.months,
                           vacc=dhs_namibia_2013$measles.y,
                           breaks=NULL)


# Two age groups < 12 months and > 12 months
tmp <- get_beta_params_age(age=dhs_namibia_2013$age.in.months,
                           vacc=dhs_namibia_2013$measles.y,
                           breaks=12)
par(mfrow=c(1,2))
for(i in 1:2) curve(dbeta(x, tmp$shape1[i], tmp$shape2[i]), 0, 1,
                    xlab='Proportion vaccinated', ylab='Density',
                    main=tmp$age[i], lwd=2)


# 6-month age groups
tmp <- get_beta_params_age(age=dhs_namibia_2013$age.in.months,
                           vacc=dhs_namibia_2013$measles.y,
                           breaks=seq(0, 60, 6))
par(mfrow=c(2,5))
for(i in 1:10) curve(dbeta(x, tmp$shape1[i], tmp$shape2[i]), 0, 1,
                     xlab='Proportion vaccinated', ylab='Density',
                     main=tmp$age[i], lwd=2)


# Each unique age in months
tmp <- get_beta_params_age(age=dhs_namibia_2013$age.in.months,
                           vacc=dhs_namibia_2013$measles.y,
                           breaks=seq(0, 60, 1))

par(mfrow=c(1,1))
plot(tmp$mu, type='l')


# 3-month age groups for each region
require(foreach)
tmp <- foreach(i=unique(dhs_namibia_2013$region.residence), .combine='rbind') %do% {

  sel <- dhs_namibia_2013$region.residence == i

  cbind(
    data.frame(region=i),
    get_beta_params_age(age=dhs_namibia_2013$age.in.months[sel],
                        vacc=dhs_namibia_2013$measles.y[sel],
                        breaks=seq(0, 60, 3))
  )
}

gilesjohnr/propvacc documentation built on Aug. 24, 2020, 3:20 a.m.