Following this R instruction
> fit <- lm(spending ~ sex + status + income + verbal, data=spending)
I would like to calculate the mean and median of the residuals. Both my friend and I get different answers for the mean for the same data.
> mean(resid(fit))
[1] -3.065293e-17
while with the other model, results are:
> fit1<- lm(spending ~ status + income + sex + verbal, data=spending)
> mean(resid(fit1))
[1] 4.064605e-16
Why did we get the same median but different mean if we are using the same data set?
4.064605e-16 / -3.065923e-17
! (More important point: just becauseall.equal
uses a default tolerance of.Machine$double.eps^0.5
, which is around $10^{-8}$, does not mean it is appropriate for this comparison. It's not. The appropriate tolerance depends on the typical sizes of the residuals themselves, which we do not know in this case.) $\endgroup$