knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

set.seed(2353454)
library("varDecomp")
library("data.table")
library("microbenchmark")

data(wage)
wage <- wage[wage$wage > 5000, ]
setDT(wage)
f <- log(wage) ~ racer + educr

Simple benchmark

wage2 <- copy(wage)

microbenchmark::microbenchmark({
    varDecomp(wage, wage2, f, silent = TRUE, precision = .001)
}, times = 10)

microbenchmark::microbenchmark({
    varDecomp(wage, wage2, f, silent = TRUE, precision = 1e-11)
}, times = 10)

Complex benchmark with IPF

wage[, wt := 1]
wage2 <- copy(wage)
wage2[educr == "4-year college+", wt := 2]

microbenchmark::microbenchmark({
    varDecomp(wage, wage2, f, weight = "wt", silent = TRUE, precision = .001)
}, times = 10)

microbenchmark::microbenchmark({
    varDecomp(wage, wage2, f, weight = "wt", silent = TRUE, precision = 1e-11)
}, times = 10)


antrologos/varDecomp documentation built on Sept. 2, 2019, 6:05 p.m.