recalib: Calibrate weights

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/recalib.R

Description

Calibrate weights for bootstrap replicates by using iterative proportional updating to match population totals on various household and personal levels.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
recalib(
  dat,
  hid = attr(dat, "hid"),
  weights = attr(dat, "weights"),
  b.rep = attr(dat, "b.rep"),
  period = attr(dat, "period"),
  conP.var = NULL,
  conH.var = NULL,
  epsP = 0.01,
  epsH = 0.02,
  ...
)

Arguments

dat

either data.frame or data.table containing the sample survey for various periods.

hid

character specifying the name of the column in dat containing the household ID.

weights

character specifying the name of the column in dat containing the sample weights.

b.rep

character specifying the names of the columns in dat containing bootstrap weights which should be recalibratet

period

character specifying the name of the column in dat containing the sample period.

conP.var

character vector containig person-specific variables to which weights should be calibrated or a list of such character vectors. Contingency tables for the population are calculated per period using weights.

conH.var

character vector containig household-specific variables to which weights should be calibrated or a list of such character vectors. Contingency tables for the population are calculated per period using weights.

epsP

numeric value specifying the convergence limit for conP.var or conP, see ipf().

epsH

numeric value specifying the convergence limit for conH.var or conH, see ipf().

...

additional arguments passed on to function ipf() from this package.

Details

recalib takes survey data (dat) containing the bootstrap replicates generated by draw.bootstrap and calibrates weights for each bootstrap replication according to population totals for person- or household-specific variables.
dat must be household data where household members correspond to multiple rows with the same household identifier. The data should at least containt the following columns:

For each period and each variable in conP.var and/or conH.var contingency tables are estimated to get margin totals on personal- and/or household-specific variables in the population.
Afterwards the bootstrap replicates are multiplied with the original sample weight and the resulting product ist then adjusted using ipf() to match the previously calcualted contingency tables. In this process the columns of the bootstrap replicates are overwritten by the calibrated weights.

Value

Returns a data.table containing the survey data as well as the calibrated weights for the bootstrap replicates. The original bootstrap replicates are overwritten by the calibrated weights. If calibration of a bootstrap replicate does not converge the bootsrap weight is not returned and numeration of the returned bootstrap weights is reduced by one.

Author(s)

Johannes Gussenbauer, Alexander Kowarik, Statistics Austria

See Also

ipf() for more information on iterative proportional fitting.

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
## Not run: 

eusilc <- demo.eusilc(prettyNames = TRUE)

dat_boot <- draw.bootstrap(eusilc, REP = 10, hid = "hid",
                           weights = "pWeight",
                           strata = "region", period = "year")

# calibrate weight for bootstrap replicates
dat_boot_calib <- recalib(dat_boot, conP.var = "gender", conH.var = "region",
                          verbose = TRUE)


# calibrate on other variables
dat_boot_calib <- recalib(dat_boot, conP.var = c("gender", "age"),
                          conH.var = c("region", "hsize"), verbose = TRUE)

# supply contingency tables directly
conP <- xtabs(pWeight ~ age + gender + year, data = eusilc)
conH <- xtabs(pWeight ~ hsize + region + year,
              data = eusilc[!duplicated(paste(db030,year))])
dat_boot_calib <- recalib(dat_boot, conP.var = NULL,
                          conH.var = NULL, conP = list(conP),
                          conH = list(conH), verbose = TRUE)

## End(Not run)

surveysd documentation built on Jan. 13, 2021, 4:11 p.m.