n_dist2targ {COINr}R Documentation

Normalise as distance to target

Description

A measure of the distance of each value of x to a specified target which can be a high or low target depending on direction. See details below.

Usage

n_dist2targ(x, targ, direction = 1, cap_max = FALSE)

Arguments

x

A numeric vector

targ

An target value

direction

Either 1 (default) or -1. In the former case, the indicator is assumed to be "positive" so that the target is at the higher end of the range. In the latter, the indicator is "negative" so that the target is typically at the low end of the range.

cap_max

If TRUE, any value of x that exceeds targ will be assigned a score of 1, otherwise will have a score greater than 1.

Details

If direction = 1, the formula is:

\frac{x - x_{min}}{x_{targ} - x_{min}}

else if direction = -1:

\frac{x_{max} - x}{x_{max} - x_{targ}}

Values surpassing x_targ in either case can be optionally capped at 1 if cap_max = TRUE.

Value

Numeric vector

Examples

x <- runif(20)
n_dist2targ(x, 0.8, cap_max = TRUE)


[Package COINr version 1.1.7 Index]