How to Analyze Factorial Design?

13 次查看(过去 30 天)
Juan Camilo de la Cruz Alzate
回答: Abhimenyu 2024-11-11,8:42
I'm been trying to analize a factorial desing 2^3, with 4 center points on matlab. My teacher said i have to analyze it with matlab instead minitab.
I tried to use the function anovan, but i can't find a way to include my especifications for the analysys of variance for my 2^3 desing.

回答(1 个)

Abhimenyu
Abhimenyu 2024-11-11,8:42
Hi Juan,
I understand that you want to analyze a factorial design of 2^3. A (2^3) factorial design involves three factors, each at two levels, resulting in (2^3 =) 8 experimental runs.
Adding center points to this design helps in detecting any curvature in the response surface, providing insights into potential non-linear relationships between the factors and the response.
Please find the example MATLAB code below to understand the analysis of the factorial design:
  • Generate the (2^3) Factorial Design: A design with three factors is defined, each having two levels. This creates a full factorial design. The design matrix uses coded levels (-1, 1) to simplify the interpretation of effects. Coded levels are standard in factorial designs as they center the data, making it easier to identify interactions and main effects.
% Generate the 2^3 factorial design with coded levels
factors = 3; % Number of factors
levels = 2; % Levels for each factor
design = fullfact([levels levels levels]);
% Convert to coded levels (-1, 1)
design(design == 1) = -1;
design(design == 2) = 1;
  • Center Points: Center points are added to the design to test for curvature. They are typically placed at the midpoint of the factor levels (coded as 0, 0, 0)
% Add center points (coded as [0, 0, 0])
centerPoints = repmat([0, 0, 0], 4, 1);
design = [design; centerPoints];
  • Response Data: Please input your experimental data here. The response variable corresponds to the observed outcomes for each run of the design, including both factorial and center points.
% Generate response data (example data)
% Replace this with your actual response data
response = [10; 12; 14; 16; 18; 20; 22; 24; 15; 15; 15; 15];
  • Fit the Linear Model: The design matrix and response data are combined into a table for analysis. The factors are labeled X1, X2, and X3, and the response as Y. The fitlm function fits a linear model including all main effects and interactions (X1*X2*X3).
% Step 3: Fit the linear model
tbl = array2table([design, response], 'VariableNames', {'X1', 'X2', 'X3', 'Y'});
mdl = fitlm(tbl, 'Y ~ X1*X2*X3');
  • ANOVA: The analysis of variance (ANOVA) is performed to test the significance of each factor and their interactions. The ANOVA table provides p-values that help determine which effects are statistically significant.
% Step 4: Perform ANOVA
anovaResults = anova(mdl, 'summary');
% Display results
disp(anovaResults);
SumSq DF MeanSq F pValue _________ __ __________ __________ _________ Total 178.67 11 16.242 Model 168 7 24 9 0.025369 . Linear 168 3 56 21 0.0065485 . Nonlinear 6.926e-29 4 1.7315e-29 6.4931e-30 1 Residual 10.667 4 2.6667 . Lack of fit 10.667 1 10.667 Inf 0 . Pure error 0 3 0
disp(mdl);
Linear regression model: Y ~ 1 + X1*X2 + X1*X3 + X2*X3 + X1:X2:X3 Estimated Coefficients: Estimate SE tStat pValue ___________ _______ ___________ __________ (Intercept) 16.333 0.4714 34.648 4.1402e-06 X1 1 0.57735 1.7321 0.1583 X2 2 0.57735 3.4641 0.025721 X3 4 0.57735 6.9282 0.0022784 X1:X2 1.3288e-15 0.57735 2.3016e-15 1 X1:X3 1.3681e-15 0.57735 2.3696e-15 1 X2:X3 2.1751e-15 0.57735 3.7674e-15 1 X1:X2:X3 -5.3748e-16 0.57735 -9.3095e-16 1 Number of observations: 12, Error degrees of freedom: 4 Root Mean Squared Error: 1.63 R-squared: 0.94, Adjusted R-Squared: 0.836 F-statistic vs. constant model: 9, p-value = 0.0254
For more information on the fullfact, fitlm, and anova functions in MATLAB R2024b, please refer to the documentation links provided below:
  1. https://www.mathworks.com/help/stats/fullfact.html
  2. https://www.mathworks.com/help/stats/fitlm.html
  3. https://www.mathworks.com/help/stats/anova.html
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 ANOVA 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by