roundWeights: Function for Rounding Weights

roundWeightsR 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", "L2", "aL2", "rL2", "LB2", "rB2", "LC",
    "aLC", "rLC", "SE", "aSE", "rSE"),
  tgtBnds = NULL,
  lower = -Inf,
  upper = Inf,
  scale = NULL,
  sparse = FALSE,
  data
)

Arguments

weights

A numerical vector of real weights to be rounded

formula

A formula to express a linear system for hitting the targets

targets

A numerical vector of point-targets to hit

objective

A character specifying the objective function used for calibration. By default, it is "L1". See details for more information

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 FALSE

data

A data.frame or matrix object containing the data to be used for calibration

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

"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

"LC"

for the summation of the logcosh errors

"aLC"

for the asymmetric summation of the logcosh errors

"rLC"

for the summation of the logcosh relative errors

"SE"

for the summation of the exponential absolute errors

"aSE"

for the asymmetric summation of the exponential absolute errors

"rSE"

for the summation of the exponential absolute relative errors

A two-column matrix must be provided to tgtBnds when objective = "aL1", objective = "LB1", objective = "rB1", objective = "aL2", objective = "LB2", objective = "rB2", objective = "aLC", and objective = "aSE".

The argument scale must be specified with a vector of positive real numbers when objective = "rL1", objective = "rL2", objective = "rLC", or objective = "rSE".

Value

A vector of integer weights to be the input of the calibration algorithm

Examples

library(inca)
set.seed(0)
w <- rpois(10, 4)
data <- matrix(rbinom(1000, 1, .3) * rpois(1000, 4), 100, 10)
y <- data %*% w
w <- runif(10, 0, 7.5)
rw <- roundWeights(w, ~. + 0, y, lower = 1, upper = 7, sparse = TRUE, data = data)
barplot(table(rw), main = "Rounded weigths")


inca documentation built on June 8, 2025, 1:31 p.m.