Title: | Variable Descriptions |
---|---|
Description: | Abstract descriptions of (yet) unobserved variables. |
Authors: | Torsten Hothorn [aut, cre] |
Maintainer: | Torsten Hothorn <[email protected]> |
License: | GPL-2 |
Version: | 1.1-1 |
Built: | 2024-11-19 19:20:18 UTC |
Source: | https://github.com/r-forge/ctm |
The variables package offers a small collection of objects describing conceptual variables and corresponding methods, for example for generating a grid of values for a (yet) unmeasured variable.
The package was written to support the basefun and mlt packages and will be of limited use outside these packages.
This package is authored by Torsten Hothorn <[email protected]>.
Torsten Hothorn (2018), Most Likely Transformations: The mlt Package, Journal of Statistical Software, forthcoming. URL: https://cran.r-project.org/package=mlt.docreg
Access properties of variable objects
## S3 method for class 'var' variable.names(object, ...) desc(object) unit(object) support(object) bounds(object) is.bounded(object)
## S3 method for class 'var' variable.names(object, ...) desc(object) unit(object) support(object) bounds(object) is.bounded(object)
object |
a variable object |
... |
additional arguments, currently not used |
These generics have corresponding methods for factor_var
,
ordered_var
and numeric_var
objects as well
as for vars
collections of those.
Check if observations correspond to their formal descriptions
check(object, data)
check(object, data)
object |
an object of class |
data |
a |
The function returns true of data
matches the description
in object
.
Formal description of an unordered categorical variable
factor_var(name, desc = NULL, levels, ...)
factor_var(name, desc = NULL, levels, ...)
name |
character, the name of the variable |
desc |
character, a description of what is measured |
levels |
character, the levels of the factor |
... |
ignored |
A conceptual description of a (yet) unobserved unordered categorical variable.
An object of class factor\_var
inheriting from var
with
corresponding methods.
factor_var("eye", "eye color", c("blue", "brown", "green", "grey", "mixed"))
factor_var("eye", "eye color", c("blue", "brown", "green", "grey", "mixed"))
Make a grid of values
mkgrid(object, ...) ## S3 method for class 'continuous_var' mkgrid(object, n = 2, add = TRUE, ...)
mkgrid(object, ...) ## S3 method for class 'continuous_var' mkgrid(object, n = 2, add = TRUE, ...)
object |
an object of class |
n |
number of grid points for a continous variable |
add |
logical, adds the |
... |
additional arguments |
The function returns a names list of values for each variable.
Formal description of numeric variable
numeric_var(name, desc = NULL, unit = NULL, support = c(0, 1), add = c(0, 0), bounds = NULL, ...)
numeric_var(name, desc = NULL, unit = NULL, support = c(0, 1), add = c(0, 0), bounds = NULL, ...)
name |
character, the name of the variable |
desc |
character, a description of what is measured |
unit |
character, the measurement unit |
support |
the support of the measurements, see below |
add |
add these values to the support before generating a
grid via |
bounds |
an interval defining the bounds of a real sample space |
... |
ignored |
A numeric variable can be discrete (support is then the set of all possible values, either integer or double; integers of length 2 are interpreted as all integers inbetween) or continuous (support is a double of length 2 giving the support of the data).
If a continuous variable is bounded, bounds
defines the
corresponding interval.
An object of class numeric\_var
inheriting from var
with
corresponding methods.
numeric_var("age", "age of patient", "years", support = 25:75) numeric_var("time", "survival time", "days", support = 0:365) numeric_var("time", "survival time", "days", support = c(0.0, 365), bounds = c(0, Inf))
numeric_var("age", "age of patient", "years", support = 25:75) numeric_var("time", "survival time", "days", support = 0:365) numeric_var("time", "survival time", "days", support = c(0.0, 365), bounds = c(0, Inf))
Formal description of an ordered categorical variable
ordered_var(name, desc = NULL, levels, sparse = FALSE, ...)
ordered_var(name, desc = NULL, levels, sparse = FALSE, ...)
name |
character, the name of the variable |
desc |
character, a description of what is measured |
levels |
character, the ordered levels of the factor |
sparse |
logical, set-up a sparse model matrix |
... |
ignored |
A conceptual description of a (yet) unobserved ordered categorical variable.
An object of class ordered\_var
inheriting from var
with
corresponding methods.
ordered_var("temp", "temperature", c("cold", "lukewarm", "warm", "hot"))
ordered_var("temp", "temperature", c("cold", "lukewarm", "warm", "hot"))
Concatenate or generate multiple variable descriptions
## S3 method for class 'var' c(...) as.vars(object)
## S3 method for class 'var' c(...) as.vars(object)
object |
an object |
... |
a list of variable objects |
c()
can be used to concatenate multiple variable objects; the corresponding
generics also work for the resulting object. as.vars()
tries to infer a
formal description from data.
f <- factor_var("x", levels = LETTERS[1:3]) n <- numeric_var("y") fn <- c(f, n) variable.names(fn) support(fn) is.bounded(fn) mkgrid(fn, n = 9) as.vars(iris)
f <- factor_var("x", levels = LETTERS[1:3]) n <- numeric_var("y") fn <- c(f, n) variable.names(fn) support(fn) is.bounded(fn) mkgrid(fn, n = 9) as.vars(iris)