To find the sum of squares for treatment from an array in MATLAB, you can use the "anova1" function from the Statistics and Machine Learning Toolbox.
First, let's create a sample data array:
main.m43 chars2 lines
This creates a 4x3 matrix with four samples and three treatments.
Next, we can use the "anova1" function to perform a one-way ANOVA on the data:
main.m39 chars2 lines
The "anova1" function returns three outputs:
By setting the second input to "[]" and the third input to "'off'", we prevent the "anova1" function from creating graphical output.
The sum of squares for treatment can be found in the ANOVA table:
main.m18 chars2 lines
This retrieves the value in the second row and second column of the ANOVA table, which corresponds to the sum of squares for treatment.
Finally, we can check our answer by calculating the sum of squares for error and verifying that the total sum of squares equals the sum of squares for treatment plus the sum of squares for error:
main.m83 chars3 lines
If the ANOVA was performed correctly, SS_total should equal the total sum of squares, which is calculated as:
main.m51 chars2 lines
gistlibby LogSnag