x2fx
Convert predictor matrix to design matrix
Syntax
D = x2fx(X,
model
)
D = x2fx(X,model
,categ)
D = x2fx(X,model
,categ,catlevels)
Description
D = x2fx(X,
converts
a matrix of predictors model
)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
is
one of the following:
'linear'
— Constant and linear terms. This is 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:
The constant term
The linear terms (the columns of
X
, in order 1, 2, ..., n)The interaction terms (pairwise products of the columns of
X
, in order (1, 2), (1, 3), ..., (1, n), (2, 3), ..., (n–1, n))The squared terms (in order 1, 2, ..., n)
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 row
for each term in the model. The entries in any row 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
specifies
the term (X1.^0).*(X2.^1).*(X3.^2)
. A row of all
zeros in model
specifies a constant term,
which can be omitted.
D = x2fx(X,
treats
columns with numbers listed in the vector model
,categ)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,
accepts
a vector model
,categ,catlevels)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
.
Examples
Version History
Introduced before R2006a