Skip to content
Prev 87317 / 398502 Next

Elegant way to express residual calculation in R?

Not sure if the following would qualify as elegant...  It's easier to work
with a matrix instead of data frame:

x.mat <- data.matrix(X)
xmean <- mean(x.mat)
operator.eff <- ave(x.mat, row(x.mat)) - xmean
machine.eff <- ave(x.mat, col(x.mat)) - xmean
(predicted.x <- xmean + operator.eff + machine.eff)
resid.x <- x.mat - predicted.x
sum(resid.x^2)

You can also use aov(), but you already know that...

Andy

From: John McHenry