numeric.encoder {midr} | R Documentation |
Encoder for Quantitative Variables
Description
numeric.encoder()
returns an encoder for a quantitative variable.
Usage
numeric.encoder(
x,
k,
type = 1L,
encoding.digits = NULL,
tag = "x",
frame = NULL,
weights = NULL
)
numeric.frame(
reps = NULL,
breaks = NULL,
type = NULL,
encoding.digits = NULL,
tag = "x"
)
## S3 method for class 'encoder'
print(x, digits = NULL, ...)
Arguments
x |
a numeric vector to be encoded. |
k |
an integer specifying the coarseness of the encoding. If not positive, all unique values of x are used as sample points. |
type |
an integer specifying the encoding method. If |
encoding.digits |
an integer specifying the rounding digits for the encoding in case |
tag |
character string. The name of the variable. |
frame |
a "numeric.frame" object or a numeric vector that defines the sample points of the binning. |
weights |
optional. A numeric vector of sample weights for each value of |
reps |
a numeric vector to be used as the representative values (knots). |
breaks |
a numeric vector to be used as the binning breaks. |
digits |
the minimum number of significant digits to be used. |
... |
not used. |
Details
numeric.encoder()
selects sample points from the variable x
and returns a list containing the encode()
function to convert a vector into a dummy matrix.
If type
is 1
, k
is considered the maximum number of knots, and the values between two knots are encoded as two decimals, reflecting the relative position to the knots.
If type
is 0
, k
is considered the maximum number of intervals, and the values are converted using one-hot encoding on the intervals.
Value
numeric.encoder()
returns a list containing the following components:
frame |
an object of class "numeric.frame". |
encode |
a function to encode |
n |
the number of encoding levels. |
type |
the type of encoding, "linear" or "constant". |
numeric.frame()
returns a "numeric.frame" object containing the encoding information.
Examples
data(iris, package = "datasets")
enc <- numeric.encoder(x = iris$Sepal.Length, k = 5L, tag = "Sepal.Length")
enc$frame
enc$encode(x = c(4:8, NA))
frm <- numeric.frame(breaks = seq(3, 9, 2), type = 0L)
enc <- numeric.encoder(x = iris$Sepal.Length, frame = frm)
enc$encode(x = c(4:8, NA))
enc <- numeric.encoder(x = iris$Sepal.Length, frame = seq(3, 9, 2))
enc$encode(x = c(4:8, NA))