intcalibrate: Integer Calibration Function

Description Usage Arguments Details Value Examples

Description

This function performs an integer programming algorithm developed for calibrating integer weights, in order to reduce a specific objective function

Usage

1
2
3
4
intcalibrate(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 or integer weights to be calibrated. If real values are provided, they will be rounded before applying the calibration algorithm

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 "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 integer programming algorithm for calibration 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 numerical vector of calibrated integer weights.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)
print(sum(abs(y - data %*% w)))
cw <- intcalibrate(w, ~. + 0, y, lower = 1, upper = 7, sparse = TRUE, data = data)
print(sum(abs(y - data %*% cw)))
barplot(table(cw), main = "Calibrated integer weights")

inca documentation built on Sept. 19, 2019, 9:07 a.m.