[R] Multipanel weighted regression lines.
Kevin Brown
kevin.brown at mail.mcgill.ca
Mon Jul 14 21:13:37 CEST 2003
Dear R-users,
I am trying to create a multipanel scatter plot which displays weighted
regression lines for each subgroup. I am having diffuculty figuring out
how the Trellis multipanel plotting functions work, in general. Does
someone know where there are some beginners examples on how to create
and use panel.xxx functions in conjunction with the xyplot functions?
Back to the matter at hand - There are two different ways that I could
add these lines, I think.
The first, and simplest would be to first find the coeffecients of the
weighted regression line for each panel ( I can do this). Then I would
add these coeffecients into a vector/matrix (i'm not sure what form of
vector would be suitable) and add them to each panel (I do not know how
to do this).
The second way would be to fiddle around with the function below to add
the "weights" to the lm function call. I do not know how to change this
"plot.regression" function to do that.
plot.regression = function(x,y)
{
panel.xyplot(x,y)
panel.abline(lm(y~x))
}
xyplot(yg~xg | g, panel="plot.regression")
Any help would be great!
Thanks,
Kevin Brown.
More information about the R-help
mailing list