intcalibrate | R Documentation |
This function performs an integer programming algorithm developed for calibrating integer weights, in order to reduce a specific objective function
intcalibrate(
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,
penalty = c("null", "l0norm", "lasso", "ridge", "raking", "minentropy", "quadrat",
"quadmod", "hellinger", "mcp", "scad", "relasso", "modrelasso", "rehuber",
"modrehuber"),
tuning = 0,
data
)
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 |
A numerical vector of point-targets to hit |
objective |
A character specifying the objective function used for calibration. By default |
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 |
penalty |
A character specifying the penalty function. By default |
tuning |
A positive value denoting the tuning parameter to control the intensity of the penalty function |
data |
A |
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
"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
The calibrated weights can also be restricted further using one of the following penalty functions:
"null"
does not penalize, and it is used for backward compatibility
"l0norm"
counts the number of non-zero adjustments
"lasso"
sums the absolute values of the adjustments
"ridge"
sums the adjustments squared
"raking"
uses raking ratios
"minentropy"
uses the minimum entropy
"quadrat"
uses a nomalized euclidean distance
"quadmod"
uses a modified normalization in the euclidean distance
"hellinger"
uses the Hellinger's distance
"mcp"
uses a variation of the minimax concave penalty
"scad"
uses a variation of the smoothly clipped absolute deviations
"relasso"
sums the absolute value of the relative adjustments
"modrelasso"
sums the absolute value of the modified relative adjustments
"rehuber"
uses the Huber loss on the relative adjustments
"modrehuber"
uses the Huber loss on the modified relative adjustmnets
In particular, the adjustments are considered from the initial rounded weights rather than the input vector of weights with real numbers.
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"
.
A numerical vector of calibrated integer weights.
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)
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)))
qw <- intcalibrate(w, ~. + 0, y, lower = 1, upper = 7, sparse = TRUE, data = data,
penalty = "quadrat", tuning = 0.7)
print(sum(abs(y - data %*% qw)))
barplot(table(cw), main = "Calibrated integer weights")
barplot(table(qw), main = "Calibrated integer weights")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.