Generation of smaller regions given an existing spatial variable and a table.

Share:

Description

This function allows to manipulate an object of class simPopObj in a way that a new variable containing smaller regions within an already existing broader region is generated. The distribution of the smaller region within the broader region is respected.

Usage

1
simInitSpatial(simPopObj, additional, region, tspatial)

Arguments

simPopObj

an object of class simPopObj.

additional

a character vector of length one holding the variable name of the variable containing smaller geographical units. This variable name must be available as a column in input argument tspatial.

region

a character vector of length one holding the variable name of the broader region. This variable must be available in the input tspatial as well as in the sample and population slots of input simPopObj.

tspatial

a data.frame containing three columns. The broader region (with the variable name being the same as in input region, the smaller geographical units (with the variable name being the same as in input additional and a third column containing a numeric vector holding counts.))

Details

The distributional information must be contained in an input table that holds combinations of characteristics of the broader region and the smaller regions as well as population counts (which may be available from a census).

Value

An object of class simPopObj with an additional variable in the synthetic population slot.

Author(s)

Bernhard Meindl

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
data(eusilcS)
data(eusilcP)

# no districts are available in the population, so we have to generate those
# we randomly assign districts within "region" in the eusilc population data
# each hh has the same district
simulate_districts <- function(inp) {
  hhid <- "hid"
  region <- "region"

  a <- inp[!duplicated(inp[,hhid]),c(hhid, region)]
  spl <- split(a, a[,region])
  regions <- unique(inp[,region])

  tmpres <- lapply(1:length(spl), function(x) {
    codes <- paste(x, 1:sample(3:9,1), sep="")
    spl[[x]]$district <- sample(codes, nrow(spl[[x]]), replace=TRUE)
    spl[[x]]
  })
  tmpres <- do.call("rbind", tmpres)
  tmpres <- tmpres[,-c(2)]
  out <- merge(inp, tmpres, by.x=c(hhid), by.y=hhid, all.x=TRUE)
  invisible(out)
}

eusilcP <- simulate_districts(eusilcP)
table(eusilcP$district)

# we generate a synthetic population
inp <- specifyInput(data=eusilcS, hhid="db030", hhsize="hsize", strata="db040", weight="db090")
simPopObj <- simStructure(data=inp, method="direct", basicHHvars=c("age", "rb090"))

# we generate the input table using the broad region (variable 'region')
# and the districts, we have generated before.
# we
tab <- as.data.frame(xtabs(rep(1, nrow(eusilcP)) ~ eusilcP$region + eusilcP$district))
colnames(tab) <- c("db040", "district", "Freq")

simPopObj <- simInitSpatial(simPopObj, additional="district", region="db040", tspatial=tab)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.