2^k factorial design ANOVA Table
30 ビュー (過去 30 日間)
古いコメントを表示
I have a very simple factorial design experiment that I need to make an anova table for, but hours of banging my head against the wall has got me this:
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 comibination of Factor levels
Table = table(factorA', factorB', Response', 'VariableNames', {'FactorA', 'FactorB', 'Response'})
rm = fitrm(Table,'FactorA-FactorB~Response') %As far as I can tell this is the correct setup for the rm function
Anova_table = ranova(rm)
This code gives me an output, but I'm pretty sure it's wrong, so I need to know if what I have is giving me the right output or if I'm on the wrong track. I also need an equation that models the data given a certain set of selected factors and factor levels but I can't understand how to do this either.
Any input is greatly appreciated.
0 件のコメント
回答 (1 件)
Shivansh
2023 年 12 月 5 日
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で ANOVA についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!