roundWeights {inca} | R Documentation |
Function for Rounding Weights
Description
This function performs an optimal rounding of the provided real weights, in order to reduce a specific objective function
Usage
roundWeights(weights, formula, targets, objective = c("L1", "aL1", "rL1",
"LB1", "rB1", "rbLasso1", "L2", "aL2", "rL2", "LB2", "rB2", "rbLasso2"),
tgtBnds = NULL, lower = -Inf, upper = Inf, scale = NULL,
sparse = FALSE, data = environment(formula))
Arguments
weights |
A numerical vector of real weights to be rounded |
formula |
A formula to express a linear system for hitting the |
targets |
A numerical vector of point-targets to hit |
objective |
A character specifying the objective function used for calibration. By default, it is |
tgtBnds |
A two-column matrix containing the bounds for the point-targets |
lower |
A numerical vector or value defining the lower bounds of the weights |
upper |
A numerical vector or value defining the upper bounds of the weights |
scale |
A numerical vector of positive values |
sparse |
A logical value denoting if the linear system is sparse or not. By default, it is |
data |
A |
Details
The optimal rounding can be performed by considering one of the following objective functions:
"L1"
for the summation of absolute errors
"aL1"
for the asymmetric summation of absolute errors
"rL1"
for the summation of absolute relative errors
"LB1"
for the summation of absolute errors if outside the boundaries
"rB1"
for the summation of absolute relative errors if outside the boundaries
"rbLasso1"
for the summation of absolute relative errors if outside the boundaries plus a Lasso penalty based on the distance from the provided weights
"L2"
for the summation of square errors
"aL2"
for the asymmetric summation of square errors
"rL2"
for the summation of square relative errors
"LB2"
for the summation of square errors if outside the boundaries
"rB2"
for the summation of square relative errors if outside the boundaries
"rbLasso2"
for the summation of square relative errors if outside the boundaries plus a Lasso penalty based on the distance from the provided weights
A two-column matrix must be provided to tgtBnds
when objective = "LB1"
, objective = "rB1"
,
objective = "rbLasso1"
, objective = "LB2"
, objective = "rB2"
, and objective = "rbLasso2"
.
The argument scale
must be specified with a vector of positive reals number when objective = "rL1"
or objective = "rL2"
.
Value
A vector of integer weights to be the input of the calibration algorithm
Examples
library(inca)
set.seed(0)
w <- rpois(150, 4)
data <- matrix(rbinom(150000, 1, .3) * rpois(150000, 4), 1000, 150)
y <- data %*% w
w <- runif(150, 0, 7.5)
rw <- roundWeights(w, ~. + 0, y, lower = 1, upper = 7, sparse = TRUE, data = data)
barplot(table(rw), main = "Rounded weigths")