DesignMatrix[{{x11,x12,…,y1},{x21,x22,…,y2},…},{f1,f2,…},{x1,x2,…}]
constructs the design matrix for the linear model β0+β1 f1+β2 f2+….
DesignMatrix
DesignMatrix[{{x11,x12,…,y1},{x21,x22,…,y2},…},{f1,f2,…},{x1,x2,…}]
constructs the design matrix for the linear model β0+β1 f1+β2 f2+….
Details and Options
- DesignMatrix[{y1,y2,…},{f1,f2,…},x] assumes data of the form {{1,y1},{2,y2},…}. »
- With data in the form
, the number of coordinates xi1, xi2, … should equal the number of variables xi. - The design matrix m is formed from the values of basis functions fi at data points in the form
-
- DesignMatrix takes the following options:
-
IncludeConstantBasis True whether to include a constant basis function NominalVariables None variables considered as nominal or categorical WorkingPrecision Automatic precision used in internal computations - With the setting IncludeConstantBasis->False, the design matrix for a model of form β1 f1+β2 f2+⋯ is constructed. »
Examples
open all close allBasic Examples (3)
Design matrix for a linear model:
data = Table[{i, i ^ (3 / 2) + RandomReal[]}, {i, 5}]DesignMatrix[data, x, x]//MatrixFormDesignMatrix[data, {x, x ^ 2}, x]//MatrixFormDesignMatrix[data, {x, x ^ 2}, x, IncludeConstantBasis -> False]//MatrixFormDesign matrix with two predictor variables:
data2 = Table[{RandomInteger[10], RandomInteger[10], RandomReal[]}, {10}]DesignMatrix[data2, {x, y}, {x, y}]//MatrixFormDesignMatrix[data2, {x, y, x * y}, {x, y}]//MatrixFormAssume predictor values 1, 2, …:
DesignMatrix[RandomReal[10, 5], x, x]//MatrixFormScope (2)
Use any numeric functions of the predictors:
data = Table[{i, RandomReal[]}, {i, 5}]DesignMatrix[data, {Sin[x], Sqrt[x]}, x]//MatrixFormGet the design matrix using exact arithmetic:
data = RandomInteger[99, {5, 2}]DesignMatrix[data, {x, Sin[x]}, x] //MatrixFormDesignMatrix[N[data], {x, Sin[x]}, x] //MatrixFormUse arbitrary-precision arithmetic:
DesignMatrix[N[data, 24], {x, Sin[x]}, x] //MatrixFormUse fixed 24-digit precision arithmetic:
DesignMatrix[data, {x, Sin[x]}, x, WorkingPrecision -> 24] //MatrixFormOptions (3)
IncludeConstantBasis (1)
A constant term is included by default:
data = Table[{i, RandomReal[]}, {i, 10}]DesignMatrix[data, x, x]//MatrixFormConstruct a design matrix without a constant term:
DesignMatrix[data, x, x, IncludeConstantBasis -> False]//MatrixFormNominalVariables (2)
Treat x as a numeric variable:
data = {{0, 1.5}, {2, 2.3}, {2, 1.8}, {0, 2.5}};DesignMatrix[data, x, x]//MatrixFormDesignMatrix[data, x, x, NominalVariables -> x]//MatrixFormUse nominal variables that are not numeric:
DesignMatrix[{{a, 1.5}, {b, 2.3}, {b, 1.8}, {a, 2.5}}, x, x, NominalVariables -> x]//MatrixFormDesignMatrix[{{a, 0, 1.5}, {b, 2, 2.3}, {a, 2, 1.8}, {b, 0, 2.5}}, {x, y}, {x, y}, NominalVariables -> x]//MatrixFormTreat all predictors as nominal:
DesignMatrix[{{a, 0, 1.5}, {b, 2, 2.3}, {a, 2, 1.8}, {b, 0, 2.5}}, {x, y}, {x, y}, NominalVariables -> All]//MatrixFormProperties & Relations (1)
DesignMatrix constructs the design matrix used by LinearModelFit:
data = Table[{i, RandomReal[]}, {i, 5}]DesignMatrix[data, x, x]//MatrixFormlm = LinearModelFit[data, x, x];lm["DesignMatrix"]//MatrixFormThe matrix is the same for GeneralizedLinearModelFit:
glm = GeneralizedLinearModelFit[data, x, x];glm["DesignMatrix"]//MatrixFormRelated Guides
History
Text
Wolfram Research (2008), DesignMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DesignMatrix.html.
CMS
Wolfram Language. 2008. "DesignMatrix." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DesignMatrix.html.
APA
Wolfram Language. (2008). DesignMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DesignMatrix.html
BibTeX
@misc{reference.wolfram_2026_designmatrix, author="Wolfram Research", title="{DesignMatrix}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/DesignMatrix.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_designmatrix, organization={Wolfram Research}, title={DesignMatrix}, year={2008}, url={https://reference.wolfram.com/language/ref/DesignMatrix.html}, note=[Accessed: 13-June-2026]}