geoWeight: Split weights across geographies

Description Usage Arguments Details Value Examples

View source: R/geoWeight.r

Description

geoWeight calculates state weights for each household in a microdata file that add up to the household total weight, such that weighted state totals for selected characteristics hit or come close to desired targets

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
geoWeight(
  wh,
  xmat,
  targets,
  dweights = get_dweights(targets),
  method = "Broyden",
  betavec = rep(0, length(targets)),
  maxiter = NULL,
  opts = NULL
)

Arguments

wh

vector of household total weights, length h (see h, s, k definitions below)

xmat

h x k matrix of data for households

targets

s x k matrix of desired target values

dweights

optional vector of weighting factors for targets, length s * k

method

optional parameter for approach to use; must be one of c('Broyden', 'Newton', 'LM'); default is 'Broyden'

betavec

optional vector of initial guess at parameters, length s * k; default is zero for all

Details

geoWeight uses the solver nleqslv or the solver nls.lm depending on user choice.

Value

A list with the following elements:

h

number of households (or individuals, records, tax returns, etc.)

s

number of states (or other geographies or subgroups)

k

number of characteristics each household has

solver_message

message from the solver that was used

etime

elapsed time

beta_opt_mat

s x k matrix of optimal parameters

whs

h x s matrix of state weights for each household, computed using the optimal parameters

wh

the input vector of household total weights, length h

output

list of output from the solver that was used

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Example 1: Determine state weights for a simple problem with random data
p <- make_problem(h=10, s=3, k=2)
dw <- get_dweights(p$targets)

res1 <- geoWeight(wh = p$wh, xmat = p$xmat, targets = p$targets,
  dweights = dw)

res2 <- geoWeight(wh = p$wh, xmat = p$xmat, targets = p$targets,
  dweights = dw, method = 'Newton')

res3 <- geoWeight(wh = p$wh, xmat = p$xmat, targets = p$targets,
  dweights = dw, method = 'LM')

res1
res2
res3
c(res1$sse_unweighted, res2$sse_unweighted, res3$sse_unweighted)

# verify that the state weights produce the desired targets
whs <- get_weights(beta, delta, xmat)
t(res2$whs) %*% p$xmat
p$targets

donboyd5/geoWeight documentation built on July 5, 2020, 8:55 p.m.