if we have
dd <- structure(list(x = c(-0.27461139896373, -0.36715415967394, -0.396878987664827,
-0.46247810661517, -0.348554552166752, -0.312871287128712, -0.305359246171965,
-0.297850026219192, -0.38399462004035, -0.442901234567901, -0.436306074264866,
-0.316390041493775), y = c(0.805840995132504, 1.9359410430839,
0.820987654320988, 1.4328231292517, 0.91156462585034, 1.75308641975309,
1.15646258503401, 1.42795138888889, 1.25575279421433, 3.13271604938272,
0.825788751714678, 0.583974649162517), x2 = c(6.75, 4, 7.75,
6.5, 5.33333333333333, 5.41666666666667, 5.16666666666667, 4.16666666666667,
4.08333333333333, 2.83333333333333, 5.91666666666667, 5.75),
g = c("a1", "a3", "a5", "a6", "a2", "a1", "a2", "a1", "a2",
"a1", "a3", "a4")), .Names = c("x", "y", "x2", "g"), class = "data.frame", row.names = c(NA,
-12L))
and do the model:
mm <- lm(y ~ x + x2 + g,
data = dd)
summary(mm)
we can get residuals in two ways:
res <- residuals(mm,type="partial")
partial.residuals <- resid(mm) + mm$coefficients["x"] * dd$x
why do these results differ?
res[,1]
partial.residuals
I want to plot the partial residuals of y on x