contact_matrix: Generate a contact matrix from diary survey data

Description Usage Arguments Value Author(s) Examples

View source: R/contact_matrix.r

Description

Samples a contact survey using a bootstrap

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
contact_matrix(
  survey,
  countries = c(),
  survey.pop,
  age.limits,
  filter,
  n = 1,
  bootstrap,
  counts = FALSE,
  symmetric = FALSE,
  split = FALSE,
  estimated.participant.age = c("mean", "sample", "missing"),
  estimated.contact.age = c("mean", "sample", "missing"),
  missing.participant.age = c("remove", "keep"),
  missing.contact.age = c("remove", "sample", "keep"),
  weights = c(),
  weigh.dayofweek = FALSE,
  sample.all.age.groups = FALSE,
  quiet = FALSE,
  ...
)

Arguments

survey

a survey object

countries

limit to one or more countries; if not given, will use all countries in the survey; these can be given as country names or 2-letter (ISO Alpha-2) country codes

survey.pop

survey population – either a data frame with columns 'lower.age.limit' and 'population', or a character vector giving the name(s) of a country or countries from the list that can be obtained via wpp_countries; if not given, will use the country populations from the chosen countries, or all countries in the survey if countries is not given

age.limits

lower limits of the age groups over which to construct the matrix

filter

any filters to apply to the data, given as list of the form (column=filter_value) - only contacts that have 'filter_value' in 'column' will be considered

n

number of matrices to sample

bootstrap

whether to sample participants and contacts randomly using a bootstrap; by default, will use bootstrap if n > 1

counts

whether to return counts (instead of means)

symmetric

whether to make matrix symmetric, such that c_ijN_i = cjiN_j.

split

whether to split the number of contacts and assortativity

estimated.participant.age

if set to "mean" (default), people whose ages are given as a range (in columns named "..._est_min" and "..._est_max") but not exactly (in a column named "..._exact") will have their age set to the mid-point of the range; if set to "sample", the age will be sampled from the range; if set to "missing", age ranges will be treated as missing

estimated.contact.age

if set to "mean" (default), people whose ages are given as a range (in columns named "..._est_min" and "..._est_max") but not exactly (in a column named "..._exact") will have their age set to the mid-point of the range; if set to "sample", the age will be sampled from the range; if set to "missing", age ranges will be treated as missing

missing.participant.age

if set to "remove" (default), participants without age information are removed; if set to "keep", participants with missing age are kept and treated as a separate age group

missing.contact.age

if set to "remove" (default), participants that that have contacts without age information are removed; if set to "sample", contacts without age information are sampled from all the contacts of participants of the same age group; if set to "keep", contacts with missing age are kept and treated as a separate age group

weights

columns that contain weights

weigh.dayofweek

whether to weigh the day of the week (weight 5 for weekdays ans 2 for weekends)

sample.all.age.groups

what to do if bootstrapping fails to sample participants from one or more age groups; if FALSE (default), corresponding rows will be set to NA, if TRUE the sample will be discarded and a new one taken instead

quiet

if set to TRUE, output is reduced

...

further arguments to pass to get_survey, check and pop_age (especially column names)

Value

a list of sampled contact matrices, and the underlying demography of the surveyed population

Author(s)

Sebastian Funk

Examples

1
2
data(polymod)
contact_matrix(polymod, countries = "United Kingdom", age.limits = c(0, 1, 5, 15))

Example output

Attaching package:socialmixrThe following object is masked frompackage:utils:

    cite

Using POLYMOD social contact data. To cite this in a publication, use the 'cite' function
Removing participants that have contacts without age information. To change this behaviour, set the 'missing.contact.age' option
$matrix
         contact.age.group
age.group      [0,1)     [1,5)   [5,15)      15+
   [0,1)  0.40000000 0.8000000 1.266667 5.933333
   [1,5)  0.11250000 1.9375000 1.462500 5.450000
   [5,15) 0.02450980 0.5049020 7.946078 6.215686
   15+    0.03230337 0.3581461 1.290730 9.594101

$participants
   age.group participants proportion
1:     [0,1)           15 0.01483680
2:     [1,5)           80 0.07912957
3:    [5,15)          204 0.20178042
4:       15+          712 0.70425321

socialmixr documentation built on Jan. 13, 2021, 10:18 p.m.