An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090209/60fd42dd/attachment-0001.pl>
How to create grouping in the residual plot
2 messages · Ram Pandit, Dieter Menne
Ram Pandit <pandit.ram <at> gmail.com> writes:
I am working in a country level data. After running the regression, I would like to plot the residuals of each observation based on the group created for a particular variable. For example, one of my independent variable is "Income", I would like to plot the residual based on income categories (<5000, 5001-10,000, 10001-15,000 etc) with "different color" for each income group. Any hints or pointers will be highly appreciated.
(Any sample data set would also be appreciated)
library(nlme) # only required for data set
library(lattice)
data(Orthodont)
lm.or = lm(distance~age+Sex,data=Orthodont)
Orthodont$res = residuals(lm.or)
# in one plot
xyplot(res~age,groups=Sex,data=Orthodont)
# in two panels, with a bit of additional luxury
xyplot(res~age|Sex,data=Orthodont,aspect=1,
panel = function(x, y) {
panel.grid(h=-1, v= -2)
panel.xyplot(x, y,pch=16)
panel.loess(x,y, span=1)
})