0
$\begingroup$

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)
$\endgroup$

1 Answer 1

0
$\begingroup$

Obviously, you can exactly predict the value of z_res from A and F alone, because you define

z_res= (res - mean(res)) / sd(res)
F <- ifelse(A==0, res+2 , res-2)

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$$

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – WabiSabi
    Feb 16, 2022 at 17:15
  • $\begingroup$ @WabiSabi I have edited my answer and written down the formula that your code defines. As you are a new contributor, here is a hint: if a question is resolved, do not forget to accept the answer so that the question no longer appears in the unanswered questions. $\endgroup$
    – cdalitz
    Feb 16, 2022 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.