problem with the anova calculation

I have a problem with the calculation of the ANOVA. What is wrong with my code?
C_t = [30; 30; 30; 30; 30; 30; 30; 120; 120; 120; 120; 120; 120; 120; 120];
pick = [0; 0.026; 0.0550; 0.120 ; 0.320 ; 0.62 ; 1.2; 0 ;0.03; 0.066; 0.110 ; 0.220; 0.4; 0.740; 1.73];
tbl = table(C_t,pick,'VariableNames',{'C_t','pick'});
tbl.C_t = categorical(tbl.C_t);
mdl = fitlm(tbl,'pick')
tbl = anova(mdl,'summary'

 Accepted Answer

Just change one line to this
mdl = fitlm(tbl,'pick~C_t')

4 Comments

Thank you very much! Now it works. But I have one more question: why doesn't the function tbl = anova(mdl,'summary') work as in matlab help?
tbl = anova(mdl,'summary')
tbl=7×5 table
SumSq DF MeanSq F pValue
______ __ ______ _______ ________
Total 4757.8 99 48.059
Model 274.73 3 91.577 1.961 0.12501
. Linear 243.8 2 121.9 2.6103 0.078726
. Nonlinear 30.934 1 30.934 0.66242 0.41772
Residual 4483.1 96 46.699
. Lack of fit 1483.1 39 38.028 0.72253 0.85732
. Pure error 3000 57 52.632
I don't have (Liner, nonlineral, Lack of fit and pure error) and I care about these values
You don't have linear, etc, because you have indicated that C_t is categorical. The missing terms are only calculated for numerical predictors.
But the example data you posted have only 2 values for C_t. It is not possible to distinguish linear versus nonlinear trends across only two C_t values.
Ok, but how can i calculate leak of fit and purre error from this data?
You can't. This is not a software problem, it is a limitation of your design. With only two values of X (30, 120), a straight line goes through the two (X, avg Y) pairs perfectly, so your data provide no information about whether there would be any deviation from a straight line fit ("lack of fit") if you had a third X value.

Sign in to comment.

More Answers (1)

C_t = [30; 30; 30; 30; 30; 30; 30; 120; 120; 120; 120; 120; 120; 120; 120];
pick = [0; 0.026; 0.0550; 0.120 ; 0.320 ; 0.62 ; 1.2; 0 ;0.03; 0.066; 0.110 ; 0.220; 0.4; 0.740; 1.73];
% Use the table() function to create a table from the data
tbl = table(C_t,pick,'VariableNames',{'C_t','pick'});
% Convert the 'C_t' column to a categorical variable
tbl.C_t = categorical(tbl.C_t);
% Use the fitlm() function to fit a linear regression model to the data
mdl = fitlm(tbl,'pick')
% Use the anova() function to perform an analysis of variance on the model
tbl = anova(mdl,'summary')

1 Comment

I understand that you have added descriptions, but this does not solve my problem.

Sign in to comment.

Asked:

on 6 Dec 2022

Commented:

on 10 Dec 2022

Community Treasure Hunt

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

Start Hunting!