mapping_key() returns a data frame with each reduced variable and its mapping and information loss; the mapping and indices are represented as list-cols (so there is one row per variable in the reduced data set). unnest_mappings() unnests the list columns to return a tidy data frame. mapping_groups() returns a list of mappings (either the variable names or their column position).

mapping_key(.partition)

unnest_mappings(.partition)

mapping_groups(.partition, indices = FALSE)

Arguments

.partition

a partition object

indices

logical. Return just the indices instead of the names? Default is FALSE.

Value

a tibble

Examples

set.seed(123)
df <- simulate_block_data(c(3, 4, 5), lower_corr = .4, upper_corr = .6, n = 100)
# fit partition
prt <- partition(df, threshold = .6)

# tibble: 6 x 4
mapping_key(prt)
#> # A tibble: 9 × 4
#>   variable      mapping   information indices  
#>   <chr>         <list>          <dbl> <list>   
#> 1 block1_x1     <chr [1]>       1     <int [1]>
#> 2 block1_x2     <chr [1]>       1     <int [1]>
#> 3 block1_x3     <chr [1]>       1     <int [1]>
#> 4 block2_x4     <chr [1]>       1     <int [1]>
#> 5 block3_x2     <chr [1]>       1     <int [1]>
#> 6 block3_x3     <chr [1]>       1     <int [1]>
#> 7 block3_x4     <chr [1]>       1     <int [1]>
#> 8 reduced_var_1 <chr [2]>       0.656 <int [2]>
#> 9 reduced_var_2 <chr [3]>       0.627 <int [3]>

# tibble: 12 x 4
unnest_mappings(prt)
#> # A tibble: 12 × 4
#>    variable      mapping   information indices
#>    <chr>         <chr>           <dbl>   <int>
#>  1 block1_x1     block1_x1       1           1
#>  2 block1_x2     block1_x2       1           2
#>  3 block1_x3     block1_x3       1           3
#>  4 block2_x4     block2_x4       1           7
#>  5 block3_x2     block3_x2       1           9
#>  6 block3_x3     block3_x3       1          10
#>  7 block3_x4     block3_x4       1          11
#>  8 reduced_var_1 block3_x1       0.656       8
#>  9 reduced_var_1 block3_x5       0.656      12
#> 10 reduced_var_2 block2_x1       0.627       4
#> 11 reduced_var_2 block2_x2       0.627       5
#> 12 reduced_var_2 block2_x3       0.627       6

# list: length 6
mapping_groups(prt)
#> [[1]]
#> [1] "block1_x1"
#> 
#> [[2]]
#> [1] "block1_x2"
#> 
#> [[3]]
#> [1] "block1_x3"
#> 
#> [[4]]
#> [1] "block2_x4"
#> 
#> [[5]]
#> [1] "block3_x2"
#> 
#> [[6]]
#> [1] "block3_x3"
#> 
#> [[7]]
#> [1] "block3_x4"
#> 
#> [[8]]
#> [1] "block3_x1" "block3_x5"
#> 
#> [[9]]
#> [1] "block2_x1" "block2_x2" "block2_x3"
#>