Hi Josiah,
I understand that you want to make an ANOVA table for your factorial design experiment. The “fitrm” and “ranova” might not be the ideal approach in your case.
I am assuming that you do not have repeated measures or blocking factors. In that case, you can try using “anovan” for n-way ANOVA.
Here is a modified code which uses two-way ANOVA for data analysis.
factorA = [1 1 -1 -1 1 1 -1 -1]; %factor A level upper or lower
factorB = [1 1 1 1 -1 -1 -1 -1]; %Factor B levels
Response = [19.3 20.2 8.1 9.7 20.3 24.5 10.4 11.8]; %Responses, 2 for each combination of Factor levels
% Create a table for ANOVA
Table = table(factorA', factorB', Response', 'VariableNames', {'FactorA', 'FactorB', 'Response'});
% Perform two-way ANOVA
[p, tbl, stats] = anovan(Table.Response, {Table.FactorA, Table.FactorB}, 'model', 'interaction', 'varnames', {'FactorA', 'FactorB'});
% Display the ANOVA table
disp(tbl);
In the above code, the 'model' argument in “anovan” specifies the type of model you want to fit. The value 'interaction' includes both main effects and the interaction effect between the factors. If you want to exclude the interaction, you can use 'linear' instead.
For the second part of question, you can use “fitlm” for a linear regression model that includes both factors and their interaction to model the data.
% Fit a linear model with interaction
lm = fitlm(Table, 'Response~FactorA*FactorB');
% Display the linear model summary
disp(lm);
This code snippet will also display a summary for the model which includes the values for coefficients which can be used to make predictions or further analysis of factors.
You can refer to the following documentations to get more information about “anovan” and “fitlm” functions.
Hope it helps!