This function computes (with respect to the raw input data) the indices of all contributing units to given cells identified by ids.

contributing_indices(prob, ids = NULL)

Arguments

prob

a sdcProblem object created with makeProblem()

ids

a character vector containing default ids (strIDs) that define table cells. Valid inputs can be extracted by using sdcProb2df() and looking at column strID. If this argument is NULL, the corresponding units are computed for all cells in the table.

Value

a named list where names correspond to the given ids` and the values to the row numbers within the raw input data.

Examples

# loading test problem
p <- sdc_testproblem(with_supps = FALSE)
dt <- sdcProb2df(p, dimCodes = "original")

# question: which units contribute to cell region = "A" and gender = "female"?

# compute the id ("0102")
dt[region == "A" & gender == "female", strID]
#> [1] "0102"

# which indices contribute to the cell?
ids <- contributing_indices(prob = p, ids = "0101")
#> computing contributing indices | rawdata <--> table; this might take a while

# check
dataObj <- get.sdcProblem(p, "dataObj")
rawData <- slot(dataObj, "rawData")
rawData[ids[["0101"]]]
#>     region gender freq tmpsamplingweights val
#>  1:      A   male    1                  1  10
#>  2:      A   male    1                  1  11
#>  3:      A   male    1                  1   5
#>  4:      A   male    1                  1   7
#>  5:      A   male    1                  1  13
#>  6:      A   male    1                  1  15
#>  7:      A   male    1                  1  13
#>  8:      A   male    1                  1   6
#>  9:      A   male    1                  1   9
#> 10:      A   male    1                  1   7
#> 11:      A   male    1                  1   9
#> 12:      A   male    1                  1   8
#> 13:      A   male    1                  1   9
#> 14:      A   male    1                  1  10
#> 15:      A   male    1                  1  10
#> 16:      A   male    1                  1  18
#> 17:      A   male    1                  1   6
#> 18:      A   male    1                  1  12

# compute contributing ids for all cells
contributing_indices(p)
#> computing contributing indices | rawdata <--> table; this might take a while
#> $`0000`
#>   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
#>  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
#>  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
#>  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
#>  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
#>  [91]  91  92  93  94  95  96  97  98  99 100
#> 
#> $`0001`
#>  [1]   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  40
#> [20]  41  42  43  44  45  46  47  48  49  50  51  52  53  64  65  66  67  68  69
#> [39]  70  71  72  73  74  75  90  91  92  93  94  95  96  97  98  99 100
#> 
#> $`0002`
#>  [1]  1  2 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 54 55 56 57
#> [26] 58 59 60 61 62 63 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#> 
#> $`0100`
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
#> 
#> $`0101`
#>  [1]  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
#> 
#> $`0102`
#> [1] 1 2
#> 
#> $`0200`
#>  [1] 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
#> [26] 46 47 48 49 50 51 52 53
#> 
#> $`0201`
#>  [1] 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#> 
#> $`0202`
#>  [1] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#> 
#> $`0300`
#>  [1] 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#> 
#> $`0301`
#>  [1] 64 65 66 67 68 69 70 71 72 73 74 75
#> 
#> $`0302`
#>  [1] 54 55 56 57 58 59 60 61 62 63
#> 
#> $`0400`
#>  [1]  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94
#> [20]  95  96  97  98  99 100
#> 
#> $`0401`
#>  [1]  90  91  92  93  94  95  96  97  98  99 100
#> 
#> $`0402`
#>  [1] 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#>