Learn R Programming

simPop (version 0.2.6)

addKnownMargins: add known margins/totals for a combination of variables for the population to an object of class synthPopObj.

Description

The function takes a data.frame containing known marginals/totals for a some variables that must exist in the population (stored in slot 'pop' of input object 'inp') and updates slot 'table' of the input object. This slot finally contains the known totals.

Usage

addKnownMargins(inp, margins)

Arguments

inp
a synthPopObj containing population and household survey data as well as optionally margins in standardized format.
margins
a data.frame containing for a combination of unique variable levels for n-variables the number of known occurences in the population. The numbers must be listed in the last column of data.frame 'margins' while the characteristics must be list

Value

  • an object of class synthPopObj with updated slot 'table'.

Details

households are drawn from the data and new ID's are generated for the new households.

Examples

Run this code
data(eusilcS)
data(eusilcP)
inp <- specifyInput(data=eusilcS, hhid="db030", hhsize="hsize", strata="db040", weight="db090")
inp <- simStructure(data=inp, method="direct", basicHHvars=c("age", "rb090"))
inp <- simCategorical(inp, additional=c("pl030", "pb220a"), method="multinom")

margins <- as.data.frame(
  xtabs(rep(1, nrow(eusilcP)) ~ eusilcP$region + eusilcP$gender + eusilcP$citizenship))
colnames(margins) <- c("db040", "rb090", "pb220a", "freq")
inp <- addKnownMargins(inp, margins)
str(inp)

Run the code above in your browser using DataLab