compare_margins: Compare unweighted or weighted data to targets

Description Usage Arguments Value Examples

View source: R/compare_margins.R

Description

Inspect by what degree the unweighted or weighted sample proportions deviate from the target proportions.

Usage

1

Arguments

universe

Full weighting design created by universe().

data

Data frame that includes weight from iterake(), optional.

weight

Name of weight variable in optional `data` object, optional.

plot

Display plot, default = FALSE.

Value

A tibble of unweighted counts and proportions, difference between unweighted and target proportions. If `data` and `weight` is given, it also includes weighted counts and proportions, difference between weighted and target proportions. Optionally, a plot of this information.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
data(demo_data)

mod <- universe(
        data = demo_data,
        
        category(
            name = "Sex",
            buckets = factor(
                x = levels(demo_data[["Sex"]]),
                levels = levels(demo_data[["Sex"]])
            ),
            targets = c(0.4, 0.5),
            sum.1 = TRUE
        ),

        category(
            name = "BirthYear",
            buckets = c(1986:1990),
            targets = rep(0.2, times = 5)
        ),
    
        category(
            name = "EyeColor",
            buckets = c("brown", "green", "blue"),
            targets = c(0.8, 0.1, 0.1)
        ),
    
        category(
            name = "HomeOwner",
            buckets = c(TRUE, FALSE),
            targets = c(3/4, 1/4)
        )
    )

compare_margins(
    universe = mod,
    plot = TRUE
)

wgts <- iterake(
    universe = mod
)

compare_margins(
    universe = mod,
    data = wgts,
    weight = weight,
    plot = FALSE
)

ttrodrigz/iterake documentation built on July 1, 2020, 7:46 a.m.