match_restrictions: Alter numeric data records to match linear (in)equality...

Description Usage Arguments Value Note on inequality restrictions See Also Examples

Description

Apply the successive projection algorithm to adjust each record in dat to satisfy a set of linear (in)equality constraints.

Usage

1
2
match_restrictions(dat, restrictions, adjust, weight = rep(1, ncol(dat)),
  remove_tag = TRUE, ...)

Arguments

dat

A data.frame

restrictions

An object of class validator

adjust

(optional) A logical matrix of dimensions dim(dat) where TRUE indicates that a value may be adjusted. When missing, the tagged_values are used. If no tagging was applied, adjust will default to an all TRUE matrix with dimensions equal to dim(dat).

weight

A weight vector of length ncol(dat) or a matrix of dimensions dim(dat).

remove_tag

if a value position indicator is present, remove it?

...

arguments passed to project.

Value

dat, with values adapted.

Note on inequality restrictions

All inequality restrictions of the form a.x < b are treated as a.x ≤q b. The idea is to project the original record x onto the boundary defined by the (in)equations. Projection on a boundary defined by a strict inequation is illdefined sice the value b in the restriction a.x < b is strictly outside the valid region.

See Also

tag_missing

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# a very simple adjustment example

v <- validate::validator(
	x + y == 10,
	x > 0,
	y > 0
)

# x and y will be adjusted by the same amount
match_restrictions(data.frame(x=4,y=5), v)

# One of the inequalies violated
match_restrictions(data.frame(x=-1,y=5), v)

# Weighted distances: 'heavy' variables change less
match_restrictions(data.frame(x=4,y=5), v, weight=c(100,1))

# if w=1/x0, the ratio between coefficients of x0 stay the same (to first order)
x0 <- data.frame(x=4,y=5)
x1 <- match_restrictions(x0, v, weight=1/as.matrix(x0))

x0[,1]/x0[,2]
x1[,1] / x1[2]

# example of tag usage
v <- validate::validator(x + y == 1, x>0,y>0)
d <- data.frame(x=NA,y=0.5)
d <- tag_missing(d)
# impute
d[1,1] <- 1

# only the tagged values will be altered. The tag is
# removed afterwards.
match_restrictions(d,v)

rspa documentation built on June 19, 2019, 5:03 p.m.