tests/testthat/test-spencer.R

# Author: ilya
###############################################################################
context("test-spencer")


test_that("spencer works", {
    # data from GDA1981IREDA, Table 15 and 16, page 375-376: 
    # Ghana (1970 Males + Females),
    # population between 10 and 40 years by single age.
    Pop  <-c(286487, 282182, 319718, 345610, 329133, 324683, 330555, 269536, 
             271593, 253798, 242297, 165755, 233159, 185812, 175647, 187138, 
             160864, 128099, 178568, 123386, 194999, 113372, 139088, 106190, 
             127482, 178375, 123286, 95637, 151514, 82614, 239243, 74788, 
             112354, 61746, 72366, 144828, 92563, 53924, 94635, 52351, 178832)
    
    Age  <-c(0:40)
    
    sp_smoothed <- spencer(Value = Pop, Age = Age)
    
    Tab16answer <- c(
        rep(NA, 10), 
        233847, 216876, 201938, 189873, 179734, 171529, 164280, 158214,
        152477, 147735, 143099, 139301, 135930, 133889, 132458, 132495,
        132660, 132894, 131463, 128560, 123150, 116725, 109180, 102386,
        96394, 92586, 89962, 88681, 86812, 84209, 79819
    )
    
    expect_equivalent( # unlike equal, equivalent ignores attributes
        na.omit(sp_smoothed),
        Tab16answer[!is.na(sp_smoothed)],
        tolerance = .5
    )
})
timriffe/DemoTools documentation built on Oct. 14, 2024, 12:53 p.m.