Description Usage Arguments Details Value Examples
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
1 2 3 4 5 6 7 8 9 10 |
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 |
geoWeight
uses the solver nleqslv
or the solver
nls.lm
depending on user choice.
A list with the following elements:
number of households (or individuals, records, tax returns, etc.)
number of states (or other geographies or subgroups)
number of characteristics each household has
message from the solver that was used
elapsed time
s x k matrix of optimal parameters
h x s matrix of state weights for each household, computed using the optimal parameters
the input vector of household total weights, length h
list of output from the solver that was used
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.