coded.data(data, ..., formulas = list(...))
as.coded.data(data, ..., formulas = list(...))
decode.data(data)
val2code(X, codings)
code2val(X, codings)
## S3 method for class 'coded.data':
print(x, ...)
codings(object)
## S3 method for class 'coded.data':
codings(object)
parse.coding(form)
form
)...
coded.data
and as.coded.data
return an object of class coded.data
,
which inherits from data.frame
. print.coded.data
is the print
method for this class; it simply prints the data.frame and then the formulas.
A named list
of the coding formulas is saved in
attr(, "codings")
.
Use coded.data
to convert a data.frame in which the variables
are on their original scales. The variables named in the formulas are
coded and replaced with their coded versions (and also renamed).
In contrast, as.coded.data
does not modify any of the data; it assumes the variables
are already coded, and the coding information is simply added.
decode.data
converts a dataset of class coded.data
and returns data.frame
containing the original variables.
code2val
converts coded values to the original scale using the codings provided,
and returns an object of the same class as X
.
val2code
converts the other direction. When using these functions, it is
essential that the names (or column names in the case of matrices) match those of the corresponding
coded or uncoded variables.
parse.coding
is mostly for internal use; it extracts and returns a list
with two vectors:
a character vector names
with the two variable names,
and a numeric vector const
with the center and divisor.
codings
is a generic function for accessing codings. codings.coded.data
returns the
list of coding formulas from a coded.data
object. See also codings.rsm
.x ~ (var - center) / div
where x
and var
are variable names, and center
and div
are numbers.
The left-hand side gives the name of the coded variable, and the right-hand side
should be a linear expression in the uncoded variable. This expression is evaluated at
variable values of 0 and 1, then the results are used to
solve for the scale center and divisor. These results are rounded to 4 digits
to help ensure that zeros come out exactly.data.frame
library(rsm)
CR = coded.data (ChemReact, x1~(Time-85)/5, x2~(Temp-175)/5)
CR
decode.data (CR) ### will be same as ChemReact
code2val (c(x1=.5, x2=-1), codings = codings(CR))
Run the code above in your browser using DataLab