x2fx
Convert predictors to design matrix.
d = x2fx (x, model)
converts a matrix of predictors
x to a design matrix d for regression analysis. Distinct
predictor variables should appear in different columns of x.
The optional input model controls the regression model. By default,
x2fx
returns the design matrix for a linear additive model with a
constant term. model can be any one of the following strings:
"linear" | Constant and linear terms (the default) | |
"interaction" | Constant, linear, and interaction terms | |
"quadratic" | Constant, linear, interaction, and squared terms | |
"purequadratic" | Constant, linear, and squared terms |
If x has n columns, the order of the columns of d for a full quadratic model is:
Other models use a subset of these terms, in the same order.
Alternatively, MODEL can be a matrix specifying polynomial terms of arbitrary order. In this case, MODEL should have one column for each column in X and one r for each term in the model. The entries in any r of MODEL are powers for the corresponding columns of x. For example, if x has columns X1, X2, and X3, then a row [0 1 2] in model would specify the term (X1.^0).*(X2.^1).*(X3.^2). A row of all zeros in model specifies a constant term, which you can omit.
d = x2fx (x, model, categ)
treats columns with
numbers listed in the vector categ as categorical variables. Terms
involving categorical variables produce dummy variable columns in d.
Dummy variables are computed under the assumption that possible categorical
levels are completely enumerated by the unique values that appear in the
corresponding column of x.
d = x2fx (x, model, categ, catlevels)
accepts a vector catlevels the same length as categ, specifying
the number of levels in each categorical variable. In this case, values in
the corresponding column of x must be integers in the range from 1 to
the specified number of levels. Not all of the levels need to appear in
x.
Source Code: x2fx