Main Content

rowexch

Row exchange D-optimal design

Description

dRE = rowexch(nfactors,nruns) uses a row-exchange algorithm (see Algorithms) to generate a D-optimal design dRE with nruns runs (the rows of dRE) for a linear additive model with nfactors factors (the columns of dRE). The model includes a constant term.

example

dRE = rowexch(nfactors,nruns,model) returns a D-optimal design with the terms specified in model.

example

dRE = rowexch(___,Name=Value) specifies options using one or more name-value arguments in addition to any of the input argument combinations in the previous syntaxes. For example, you can specify the maximum number of start points for generating the design, and whether to perform computations in parallel.

example

[dRE,X] = rowexch(___) additionally returns the design matrix X, whose columns are the model terms evaluated at each row of dRE.

example

Examples

collapse all

Generate a five-run D-optimal design for a three-factor linear additive model.

dRE = rowexch(3,5)
dRE = 5×3

    -1    -1    -1
     1    -1     1
    -1     1     1
     1     1    -1
    -1    -1    -1

Each row of dRE contains the factor settings for a run. By default, each factor has two levels.

Generate a nine-run D-optimal design for estimating the parameters of the following model, which has three factors and seven terms:

y=β0+β1X1+β2X2+β3X3+β12X1X2+β13X1X3+β23X2X3+ϵ

[dRE,X] = rowexch(3,7,"interaction")
dRE = 7×3

     1    -1    -1
     1     1    -1
    -1     1    -1
     1    -1     1
     1     1     1
    -1    -1    -1
    -1    -1     1

X = 7×7

     1     1    -1    -1    -1    -1     1
     1     1     1    -1     1    -1    -1
     1    -1     1    -1    -1     1    -1
     1     1    -1     1    -1     1    -1
     1     1     1     1     1     1     1
     1    -1    -1    -1     1     1     1
     1    -1    -1     1     1    -1    -1

Each row of dRE contains the factor settings for a run. All of the factors have two levels. By default, the software sets the number of levels for each factor as 1+ its maximum exponent in the model terms.

The columns of the design matrix X are the model terms evaluated at each row of the design dRE. The terms in order from left to right are: the constant term β0, linear terms (β1, β2, β3), and interaction terms (β12, β13, β23).

Generate a 10-run D-optimal design for estimating the parameters of a two-factor pure quadratic model with levels 1, 2, and 3 for the first factor, and levels –1, 0, and 1 for the second factor.

dRE = rowexch(2,10,"purequadratic",Bounds={[1,2,3],[-1,0,1]})
dRE = 10×2

     3     0
     2    -1
     3     1
     3    -1
     1     0
     1    -1
     2     1
     2     0
     2     1
     1     1

Each row of dRE contains the factor settings for a run.

Generate a D-optimal design for estimating the parameters of the following three-factor, seven-term interaction model:

y=β0+β1X1+β2X2+β3X3+β12X1X2+β13X1X3+β23X2X3+ϵ

Specify to find the best D-optimal design using 10 different initial starting points, and to return the design matrix.

[dRE,X] = rowexch(3,7,"interaction",NumTries=10)
dRE = 7×3

     1     1    -1
     1    -1     1
    -1    -1    -1
     1     1     1
     1    -1    -1
    -1     1    -1
    -1     1     1

X = 7×7

     1     1     1    -1     1    -1    -1
     1     1    -1     1    -1     1    -1
     1    -1    -1    -1     1     1     1
     1     1     1     1     1     1     1
     1     1    -1    -1    -1    -1     1
     1    -1     1    -1    -1     1    -1
     1    -1     1     1    -1    -1     1

Each row of the design dRE contains the factor settings for a run. By default, each factor has two levels.

The columns of the design matrix X are the model terms evaluated at each row of dRE. The terms, in order from left to right, are the constant term (β0), linear terms (with coefficients β1, β2, β3), and interaction terms (with coefficients β12, β13, β23).

Input Arguments

collapse all

Number of factors in the design, specified as a positive integer scalar.

Example: 3

Data Types: single | double

Number of runs in the design, specified as a nonnegative integer scalar.

Example: 5

Data Types: single | double

Model terms, specified as a value in the following table or as a numeric matrix.

ValueModel Contents
"linear" or "additive" (default)Constant and linear terms
"interaction"Constant, linear, and interaction terms
"quadratic"Constant, linear, interaction, and squared terms
"purequadratic"Constant, linear, and squared terms

If you specify model as a numeric matrix, it must contain one column for each factor and one row for each polynomial term in the model. The entries in each row are exponents for the factors in the columns. For example, if a model has factors X1, X2, and X3, then row [0 1 2] in model specifies the term X10X21X32. A row of all zeros in model specifies a constant term.

Example: "interaction"

Example: [0 1 2; 1 2 1]

Data Types: single | double | char | string

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: rowexch(2,5,NumLevels=3) generates a five-run D-optimal design for a linear additive model with two factors, where each factor has three levels.

Flag to avoid duplicate rows in the D-optimal design, specified as a numeric or logical 0 (false) or 1 (true). If you set AvoidDuplicates=true and rowexch calculates nonduplicate points, the rows of the D-optimal design are unique. When AvoidDuplicates is false (the default), rowexch does not avoid calculating duplicate rows.

Example: AvoidDuplicates=true

Data Types: logical

Lower and upper bounds for each factor, specified as a 2-by-nfactors numeric matrix or a cell array of nfactors elements. For a matrix, the first row contains the lower bounds, and the second row contains the upper bounds. For a cell array, each element contains a vector of allowable values for the corresponding factor. If Bounds is a cell array, rowexch ignores the value of NumLevels.

Example: Bounds=[0 0; 2 1]

Example: Bounds={[0 1 2],[0 1]}

Data Types: single | double | cell

Indices of categorical factors, specified as a numeric vector of positive integers. By default, rowexch sets two levels (1 and 2) for categorical factors.

Example: CategoricalVariables=[1 3]

Data Types: single | double

Flag to display the iteration counter window, specified as "on" or "off". The window displays the trial number (see NumTries) and the iteration number during computation.

Example: Display="off"

Data Types: char | string

Function to exclude unwanted runs, specified as a function handle. If the function is f, it must support the syntax b = f(S), where S is a k-by-nfactors matrix. b is a vector of k Boolean values, where b(i) is true if the ith row of S is excluded.

Example: ExcludeFcn=@excludefun

Data Types: function_handle

Initial design matrix, specified as an nruns-by-nfactors numeric matrix. The default is a randomly selected set of points.

Example: InitialDesign=[-1 0 1; 0 1 1; 0 -1 1]

Data Types: single | double

Maximum number of iterations per trial in the row-exchange algorithm, specified as a positive integer scalar. For more information, see Algorithms.

Example: MaxIterations=20

Data Types: single | double

Number of levels for each factor, specified as an integer scalar greater than 1, or a 1-by-nfactors numeric vector of integers greater than 1. rowexch ignores the value of NumLevels when you specify Bounds as a cell array. The default value of NumLevels depends on the value of model.

Value of modelDefault Value of NumLevels
"linear" or "additive" (default)2
"interaction"2
"quadratic"3
"purequadratic"3

If you specify model as a numeric matrix, then the default number of levels for each factor is 1 + the maximum exponent in model for that factor. Any factor whose indices you specify in CategoricalVariables has two levels (1 and 2) by default.

Note

If you specify AvoidDuplicates=true, the software adds more levels for any noncategorical factors, as needed, to avoid duplicate rows in the design.

Example: NumLevels=[2 3]

Data Types: single | double

Number of trials for generating a D-optimal design starting from a new initial design matrix, specified as a positive integer scalar. If NumTries > 1 and you specify InitialDesign, then rowexch uses InitialDesign for the first trial, and a randomly selected set of points in subsequent trials.

Tip

If NumTries=1, rowexch might generate a locally D-optimal design. Specify a larger value of NumTries to return a globally D-optimal design. For more information, see Algorithms.

Example: NumTries=3

Data Types: single | double

Options for computing in parallel and setting random streams, specified as a structure. Create the Options structure using statset. This table lists the option fields and their values.

Field NameValueDefault
UseParallelSet this value to true to run computations in parallel.false
UseSubstreams

Set this value to true to run computations in a reproducible manner.

To compute reproducibly, set Streams to a type that allows substreams: "mlfg6331_64" or "mrg32k3a".

false
StreamsSpecify this value as a RandStream object or cell array of such objects. Use a single object except when the UseParallel value is true and the UseSubstreams value is false. In that case, use a cell array that has the same size as the parallel pool.If you do not specify Streams, then rowexch uses the default stream or streams.

Note

You need Parallel Computing Toolbox™ to run computations in parallel.

Example: Options=statset(UseParallel=true,UseSubstreams=true,Streams=RandStream("mlfg6331_64"))

Data Types: struct

Output Arguments

collapse all

D-optimal design for model, returned as an nruns-by-nfactors numeric matrix. Each row (run) of dRE contains the settings for each factor in the design, which rowexch generates using a row-exchange algorithm.

Design matrix, returned as a numeric matrix with nruns rows. The number of columns in X depends on the value of model.

If you specify model as "quadratic" or a numeric matrix that includes constant, linear, interaction, and squared terms, the columns of X (in order), are:

  1. Constant term

  2. Linear terms in the order 1, 2, ..., nfactors

  3. Interaction terms in the order (1, 2), (1, 3), ..., (1, nfactors), (2, 3), ..., (nfactors – 1, nfactors)

  4. Squared terms in the order 1, 2, ..., nfactors

If you specify any other named value for model, X contains a subset of these terms, in the same order.

Algorithms

Both cordexch and rowexch use iterative search algorithms that incrementally change an initial design matrix X to increase D = |XTX| at each iteration. In both algorithms, randomness is built into the selection of the initial design and the choice of the incremental changes. As a result, both algorithms might return locally D-optimal designs instead of globally D-optimal designs. Run each algorithm multiple times and select the best result for your final design. To automate this repetition and comparison, set the NumTries name-value argument of either function.

At each iteration, the row-exchange algorithm exchanges an entire row of X with a row from a design matrix C evaluated at a candidate set of feasible treatments. The rowexch function automatically generates a design matrix that is appropriate for the specified model, operating in two steps by calling the candgen and candexch functions in sequence. Provide your own C by calling candexch directly. In either case, if C is large, its static presence in memory might affect the computation speed.

Extended Capabilities

expand all

Version History

Introduced before R2006a

expand all