# NOT RUN {
# load data
eusilc <- demo.eusilc(n = 1, prettyNames = TRUE)
# personal constraints
conP1 <- xtabs(pWeight ~ age, data = eusilc)
conP2 <- xtabs(pWeight ~ gender + region, data = eusilc)
conP3 <- xtabs(pWeight*eqIncome ~ gender, data = eusilc)
# household constraints
conH1 <- xtabs(pWeight ~ hsize + region, data = eusilc)
# simple usage ------------------------------------------
calibweights1 <- ipf(
eusilc,
conP = list(conP1, conP2, eqIncome = conP3),
bound = NULL,
verbose = TRUE
)
# compare personal weight with the calibweigth
calibweights1[, .(hid, pWeight, calibWeight)]
# advanced usage ----------------------------------------
# use an array of tolerances
epsH1 <- conH1
epsH1[1:4, ] <- 0.005
epsH1[5, ] <- 0.2
# create an initial weight for the calibration
eusilc[, regSamp := .N, by = region]
eusilc[, regPop := sum(pWeight), by = region]
eusilc[, baseWeight := regPop/regSamp]
calibweights2 <- ipf(
eusilc,
conP = list(conP1, conP2),
conH = list(conH1),
epsP = 1e-6,
epsH = list(epsH1),
bound = 4,
w = "baseWeight",
verbose = TRUE
)
# show an adjusted version of conP and the original
attr(calibweights2, "conP_adj")
attr(calibweights2, "conP")
# }
Run the code above in your browser using DataLab