Learn R Programming

simPop (version 2.1.3)

sampHH: Sample households from given microdata.

Description

The function samples households from microdata containing personal and household information.

Usage

sampHH(pop, sizefactor = 1, hid = "hid", strata = "region", hsize = NULL)

Value

the data frame of new households.

Arguments

pop

data frame containing households and persons

sizefactor

factor of how many times the initial population should be resampled

hid

string specifying the name of the household-id variable in the data.

strata

can be used to sample within strata.

hsize

string specifying the name of the household size variable in the data.

Author

Bernhard Meindl, Matthias Templ and Johannes Gussenbauer

Details

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

References

M. Templ, B. Meindl, A. Kowarik, A. Alfons, O. Dupriez (2017) Simulation of Synthetic Populations for Survey Data Considering Auxiliary Information. Journal of Statistical Survey, 79 (10), 1--38. doi: 10.18637/jss.v079.i10

Examples

Run this code
data(eusilcP)
pop <- eusilcP
colnames(pop)[3] <- "hhsize"

system.time(x1 <- sampHH(pop, strata="region", hsize="hhsize"))
dim(x1)
if (FALSE) {
## approx. 10 second computation time ...
system.time(x1 <- sampHH(pop, sizefactor=4, strata="region", hsize="hhsize"))
dim(x1)
system.time(x2 <- sampHH(pop, strata=NULL, hsize="hhsize"))

pop <- pop[,-which(colnames(pop)=="hhsize")]
system.time(y1 <- sampHH(pop, strata="region", hsize=NULL))
system.time(y2 <- sampHH(pop, strata=NULL, hsize=NULL))
}

Run the code above in your browser using DataLab