.makeLarsData | R Documentation |
This function adds columns to a data matrix representing quadratic, cubic, 2-way-interaction, and linear:quadratic interactions. It is especially useful for preparing a data matrix for trainLars
or predictLars
.
.makeLarsData( data, resp, preds, scale = TRUE, quadratic = TRUE, cubic = TRUE, interaction = TRUE, interQuad = TRUE, na.rm = FALSE )
data |
Data frame. |
resp |
Character or integer or |
preds |
Character or integer. Names or indices of columns to use as predictors. |
scale |
Logical or a list. If TRUE then scale values in |
quadratic |
Logical. If TRUE then include quadratic terms in model construction stage for non-factor predictors. Quadratic columns will be named |
cubic |
Logical. If TRUE then include cubic terms in model construction stage for non-factor predictors. Cubic columns will be named |
interaction |
Logical. If TRUE then include 2-way interaction terms (including interactions between factor predictors). Interaction columns will be named |
interQuad |
Logical. If TRUE then include all possible interactions of the form |
na.rm |
Logical. If TRUE then remove all rows of |
If scale
is TRUE
then predictors with zero variance will be removed from the data before creating higher-order terms.
An object of class larsData
(which is also a list
) with six elements:
* A character named "resp
" indicating the name of the column of that contains the response variable.
* A character list named "preds
" indicating the name of the columns of that contain the original predictors.
* A data frame named "data
" containing data
but with extra columns representing the added terms;
* A list object named "scales
" representing the scale (mean and standard derviation) used to center and rescale values in the data frame; and
* A list named "groups
" with groups (names of predictors that should be considered together based on marginality).
* A list named "features
" indicating what kind of features were added to data
(e.g., quadratic, cubic, etc.).
trainLars
, predictLars
## Not run: set.seed(123) x <- data.frame(y=c(rep(1, 10), rep(0, 10)), x1=1:10, x2=runif(20) * 1:20, x3=rnorm(20) - 1:20) out <- .makeLarsData(x, resp='y', preds=c('x1', 'x2', 'x3')) str(out) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.