I applied two-way anova by running R on this dataset to look at the sum of squares
fullwithinteract <- lm(torque~hole+barrel+hole:barrel,df) anova(fullwithinteract)
The problem arises when I tried to compute Sum Sq for barrel using a design matrix. I used the design matrix:
Then let $Y$ be the response vector, and $X$ be the matrix above, I go on to compute in R:
sum(( Y - X %*% solve(t(X)%*%X) %*% t(X) %*% Y)^2)
which gives an answer of 14010.5, while according to the anova table output by R, the answer should be 26565.1+1910.5=28475.6.
What have I misunderstood? Is this even calculatable using a design matrix approach?
REMARKS I hope to remark that using the following two matrices (left for calculating the SSE associated with the full model; right for calculating the SSE associated with the reduced model that nullify the interaction effects), the SSEs computed coincide with that computed by R. Now the main problem is the discrepancy between the SSEs computed using a design matrix and R for the factors barrel and hole.
REMARKS 2 I would like to give some details to how $Y$ is computed. Calling the original dataset df, $Y$ is given by
And the data and the design matrix used in the situation above can be found at: https://www.notion.so/hephaes/Data-e4ed9065085e49a8bc91c760ebba1bf3