tests/testthat/test_weighted.R

library("testthat")
library("varDecomp")

context("test_weighted")

data(wage)
wage$weight <- 1
wage2 <- copy(wage)
wage2[wage2$educr == "4-year college+", "weight"] <- 2

test_that("no change when no weights supplied", {
    v <- varDecomp(wage, wage2, log(wage) ~ educr, silent = TRUE)
    expect_equal(v$static$est_variance[[3]], 0)
    expect_equal(sum(v$dynamic$value), 0)
})

test_that("change when weights supplied", {
    v <- varDecomp(wage, wage2, log(wage) ~ educr, weight = "weight", silent = TRUE)

    expect_equal(v$static$est_variance[[3]], v$static$obs_variance[[3]], tolerance = .0001)
    expect_equal(v$static$est_variance[[3]], sum(v$dynamic$value))
    expect_gt(v$static$est_variance[[3]], 0)
    expect_gt(v$static$obs_variance[[3]], 0)
    expect_gt(sum(v$dynamic$value), 0)
})
antrologos/varDecomp documentation built on Sept. 2, 2019, 6:05 p.m.