| coded.data {rsm} | R Documentation |
These functions facilitate the use of coded data in response-surface analysis.
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, ...) parse.coding(form)
data |
A data.frame |
... |
Formulas for producing coded variables. |
formulas |
Provides an alternative way to provide the coding formulas. This is useful if you want to retrieve the codings from one dataset and use them for another. |
X |
A vector, matrix, or data.frame to be coded or decoded. |
codings |
a list of formulas (see form) |
x |
Coded dataset to be printed. |
form |
A formula as described above for ... |
Typically, coding formulas are of the form 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.
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.
Russell V. Lenth
Lenth RV (2009). ``Response-Surface Methods in R, Using rsm'', Journal of Statistical Software, 32(7), 1–17. http://www.jstatsoft.org/v32/i07/.
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 = attr(CR, "codings"))