CalibrateSSB {CalibrateSSB}R Documentation

Calibration weighting and estimation

Description

Compute weights by calibration and corresponding estimates, totals and residuals

Usage

CalibrateSSB(
  grossSample,
  calmodel = NULL,
  response = "R",
  popTotals = NULL,
  y = NULL,
  by = NULL,
  partition = NULL,
  lRegmodel = NULL,
  popData = NULL,
  samplingWeights = NULL,
  usePackage = "survey",
  bounds = c(-Inf, Inf),
  calfun = "linear",
  onlyTotals = FALSE,
  onlyw = FALSE,
  uselRegWeights = FALSE,
  ids = NULL,
  residOutput = TRUE,
  leverageOutput = FALSE,
  yOutput = TRUE,
  samplingWeightsOutput = FALSE,
  dropResid2 = TRUE,
  wGrossOutput = TRUE,
  wave = NULL,
  id = NULL,
  extra = NULL,
  allowNApopTotals = NULL,
  partitionPrint = NULL,
  ...
)

Arguments

grossSample

Data frame.

calmodel

Formula defining the linear structure of the calibration model.

response

Variable name of response indicator (net sample when 1).

popTotals

Population totals (similar to population totals as output).

y

Names of variables of interest. Can be a list similar to "by" below.

by

Names of the variables that define the "estimation domains". If NULL (the default option) or NA estimates refer to the whole population. Use list for multiple specifications (resulting in list as output).

partition

Names of the variables that define the "calibration domains" for the model. NULL (the default) implies no calibration domains.

lRegmodel

Formula defining the linear structure of a logistic regression model.

popData

Data frame of population data.

samplingWeights

Name of the variable with initial weights for the sampling units.

usePackage

Specifying the package to be used: "survey" (the default), "ReGenesees" or "none".

bounds

Bounds for the calibration weights. When ReGenesees: Allowed range for the ratios between calibrated and initial weights. The default is c(-Inf,Inf).

calfun

The distance function for the calibration process; the default is 'linear'.

onlyTotals

When TRUE: Only population totals are returned.

onlyw

When TRUE: Only the calibrated weights are returned.

uselRegWeights

When TRUE: Weighted logistic regression is performed as a first calibration step.

ids

Name of sampling unit identifier variable.

residOutput

Residuals in output when TRUE. FALSE is default.

leverageOutput

Leverages in output when TRUE. FALSE is default.

yOutput

y in output when TRUE. FALSE is default.

samplingWeightsOutput

samplingWeights in output when TRUE. FALSE is default.

dropResid2

When TRUE (default) and when no missing population totals - only one set of residuals in output.

wGrossOutput

wGross in output when TRUE (default) and when NA popTotals.

wave

Time or another repeat variable (to be included in output).

id

Identifier variable (to be included in output).

extra

Variables for the extra dataset (to be included in output).

allowNApopTotals

When TRUE missing population totals are allowed. Results in error when FALSE and warning when NULL.

partitionPrint

When TRUE partition progress is printed. Automatic decision when NULL (about 1 min total computing time).

...

Further arguments sent to underlying functions.

Details

When popTotals as input is NULL, population totals are computed from popData (when available) or from grossSample. Some elements of popTotals may be missing (not allowed when using ReGenesees). When using "ReGenesees", both weiging and estimation are done by that package. When using "survey", only calibration weiging are done by that package. The parameters wave, id and extra have no effect on the computations, but result in extra elements in output (to be used by WideFromCalibrate() later).

Value

Unless onlyTotals or onlyw is TRUE, the output is an object of class calSSB. That is, a list with elements:

popTotals

Population totals.

w

The calibrated weights.

wGross

Calibrated gross sample weights when NA popTotals.

estTM

Estimates (with standard error).

resids

Residuals, reduced model when NA popTotals.

resids2

Residuals, full model.

leverages

Diagonal elements of hat-matrix, reduced model when NA popTotals.

leverages2

Diagonal elements of hat-matrix, full model.

y

as input

samplingWeights

as input

wave

as input or via CrossStrata

id

as input

extra

as input

See Also

CalSSBobj, WideFromCalibrate, PanelEstimation, CalibrateSSBpanel.

Examples


# Generates data  - two years
z    <- AkuData(3000)  # 3000 in each quarter
zPop <- AkuData(10000)[,1:7]

# Calibration using "survey"
a <- CalibrateSSB(z, calmodel = "~ sex*age",
                 partition = c("year","q"),  # calibrate within quarter
                 popData = zPop, y = c("unemployed","workforce"),
                 by = c("year","q")) # Estimate within quarter
head(a$w) # calibrated weights
a$estTM   # estimates
a$popTotals   # popTotals used as input below


# Calibration, no package, popTotals as input
b <- CalibrateSSB(z, popTotals=a$popTotals, calmodel="~ sex*age",
      partition = c("year","q"), usePackage = "none", y = c("unemployed","workforce"))
max(abs(a$w-b$w)) # Same weights as above

print(a)
print(b)

## Not run: 
require(ReGenesees)
# Calibration and estimation via ReGenesees
CalibrateSSB(z, calmodel = "~ sex*age",
             partition = c("year","q"),  # calibrate within quarter
             popData = zPop, usePackage = "ReGenesees",
             y = c("unemployed","workforce"),
             by = c("year","q")) # Estimate within quarter

## End(Not run)


[Package CalibrateSSB version 1.3.0 Index]