Construct calibration rows from categorical data
calibration_matrix.RdBuilds a binary cell-by-task matrix and aligned target and label vectors, including unobserved target levels.
Arguments
- data
Nonempty data frame with categorical columns. Values are converted to character labels.
- targets
Named list of named numeric target fractions. List names match data columns and vector names specify their levels.
Details
Unknown or missing observed values are rejected. A complete margin whose target total differs from one by more than 1e-12 generates a warning, not an automatic renormalization.
Examples
z <- calibration_matrix(data.frame(region = c("a", "a", "b")),
list(region = c(a = .5, b = .25, c = .25)))
check_feasibility(z$M, z$target)
#> $status
#> [1] "infeasible_to_tolerance"
#>
#> $scope
#> [1] "unrestricted_simplex"
#>
#> $lower
#> [1] 0.25
#>
#> $upper
#> [1] 0.25
#>
#> $exact
#> [1] TRUE
#>
#> $primal_status
#> [1] 0
#>
#> $pattern_indices
#> [1] 1 3
#>
#> $pattern_counts
#> [1] 2 1
#>
#> $dual_status
#> [1] 0
#>
#> $gap
#> [1] 0
#>
#> $weight_witness
#> [1] 0.75 0.25
#>
#> $dual_witness
#> [1] 0 0 1
#>
#> $comparison_guard
#> [1] 1e-12
#>
#> $numerical_status
#> [1] "infeasible_to_tolerance"
#>
#> $certificate
#> $certificate$lower_num
#> [1] 1048576
#>
#> $certificate$lower_den
#> [1] 4194304
#>
#> $certificate$upper_num
#> [1] 1048576
#>
#> $certificate$upper_den
#> [1] 4194304
#>
#> $certificate$exact
#> [1] TRUE
#>
#> $certificate$lower
#> [1] 0.25
#>
#> $certificate$upper
#> [1] 0.25
#>
#> $certificate$weight_num
#> [1] 786432 0 262144
#>
#> $certificate$dual_num
#> [1] 0 0 1048576
#>
#> $certificate$dual_den
#> [1] 1048576
#>
#> $certificate$resolution
#> [1] 1048576
#>
#> $certificate$target_num
#> [1] 2 1 1
#>
#> $certificate$target_den
#> [1] 4
#>
#> $certificate$status
#> [1] "infeasible_to_tolerance"
#>
#>
#> $min_max_weight
#> [1] 0.3333333
#>
#> $concentration_status
#> [1] 0
#>