Filter löschen
Filter löschen

How to obtain a design matrix which is a real latin square with integer numbers ?

3 Ansichten (letzte 30 Tage)
For a DOE, I need to generate a design matrix with 9 runs for 3 factors. The factors are discrete with levels 1,2,3 for exemple. I would like that the runs respect the "latin square" properties :
Each points represents a run. The couples for factor 1 and factor 2 are all represented (so 3²=9 runs) and factor 3 is fixed so that each latin letter a-b-c appears only once per line and column.
I have found the lhsdesign() function that I use as
X=lhsdesign(9,3,'smooth','off')
before
icdf('unid',X,3)
but the result do not respect the "latin square" property.
Any idea ?

Akzeptierte Antwort

Shivansh
Shivansh am 19 Mär. 2024
Hi Christel!
It seems you want to generate a design matrix with nine runs for the provided three factors. The "lhsdesign" function in MATLAB generates a Latin hypercube sample but it doesn't enforce the Latin square property itself. The "lhsdesign" generates continuous numbers generated between 0 and 1 which can be discretized but it won't be the best approach to ensure Latin square property as it can't guarantee that each level appears exactly once in each row and column for all factors. You can read more about "lhsdesign" function by refering to the following MATLAB documentation: https://www.mathworks.com/help/stats/lhsdesign.html.
You can manually design a 3*3 Latin square matrix for the first two factors and then create a complementary Latin square for the third factor. You can refer to the following MATLAB code to get a better idea of the approach.
% Define the first Latin square (for factors 1 and 2)
latinSquare1 = [1, 2, 3;
3, 1, 2;
2, 3, 1];
% Define a complementary Latin square for factor 3
% This is another way to arrange levels 1, 2, and 3 in a Latin square
latinSquare2 = [2, 3, 1;
1, 2, 3;
3, 1, 2];
% Combine the two squares to form the design matrix
% Each row in designMatrix represents a run
% Columns 1 and 2 are from latinSquare1, column 3 from latinSquare2
designMatrix = [latinSquare1(:), repmat((1:3)', 3, 1), latinSquare2(:)];
% Display the design matrix
disp('Design Matrix:');
Design Matrix:
disp(designMatrix);
1 1 2 3 2 1 2 3 3 2 1 3 1 2 2 3 3 1 3 1 1 2 2 3 1 3 2
The output matrix respects the Latin square properties as each level of the first two factors appears exactly once in each row and column, and the third factor is arranged so that its levels also follow the Latin square pattern. You can adjust the code based on your requirement for the third factor.
You can refer to the following MATLAB documentation to learn more about "repmat": https://www.mathworks.com/help/matlab/ref/repmat.html.
I hope it helps!

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by