# Residual sum of squares equals zero with no error code

Why are the values for sums of squares the same for A, B and F across all models despite having different model structure? Why are the residual sum of squares zero?

I recognize that res was simulated to depend on A, B and their interaction term A*B and the F is a correlated variable with A, But I cannot make sense of sum of squares residuals = 0 or why the sum of squares do not change for the fixed variables.

# Simulated Data

alpha = 1
beta1 = 2
beta2 = -1
beta3 = -2
set.seed(786)
A = c(rep(c(0), 500), rep(c(1), 500))
B = rep(c(rep(c(0), 250), rep(c(1), 250)), 2)
e = rnorm(1000, 10, sd=2)
res = alpha + beta1*A + beta2*B + beta3*A*B + e
z_res= (res - mean(res)) / sd(res)
F <- ifelse(A==0, res+2 , res-2)
dat<-as.data.frame(cbind(A,B,F, z_res))


# Various models

mod <- aov(z_res ~ A + B+ F, data=dat)
summary(mod)

mod<-aov(z_res ~ A + B + A*B+ A*F, data=dat)
summary(mod)

mod<-aov(z_res ~ A + B +A*F, data=dat)
summary(mod)


z_res= (res - mean(res)) / sd(res)

The corresponding model z_res ~ A + F gives $$R^2=1$$ and thus a prefect fit, as it should be. For convenience, let z := z_res and y := res. Then you have defined: $$z = \frac{y-c}{d} \quad\mbox{and}\quad F = y + 2 - 4\cdot A$$ It follows that $$z = \frac{F -2 + 4\cdot A -c}{d}=\beta_0 + \beta_1 F + \beta_2 A$$
• It is not clear to me why those definitions lead to all the variation in z_res being accounted for by A and F. I realize that may be obvious to others but I am not seeing it. If res = alpha + beta1*A + beta2*B + beta3*A*B + e and z_res is the standardized version of that, why do F and A account for all the variation in z_res if F was never in the model for res? I would have expected a model with A*B to account for more variation in z_res since that was in the model for res. Feb 16, 2022 at 17:15