I have a "long" data frame that is defined as:
q <- data.frame(Indicator.Code=factor(),Year=numeric(),Value=numeric())
and try to build in one xyplot values โโas a function of the year for each other Indicator.Code , as shown below
xyplot( Value~Year,data=q,group=Indicator.Code)
So far so good. Now I am trying to add lines corresponding to linear regressions
rlm(q$Value[q$Indicator.Code==a]~q$Year[q$Indicator.Code==a])
for all Indicator.Code values.
I do not know how to do that. The usual way to add regression lines, i.e.
xyplot( Value~Year,data=q,group=Indicator.Code), panel = function(x, y) { panel.xyplot(x, y) panel.abline(rlm(y ~ x)) }))
not working properly (it calculates a single regression and adds a single regression line for the entire dataset). In addition, I have already calculated the regressions (I need them for things other than graphics), and I hate the idea of โโreprogramming them.
Any hints a newbie could listen to?
source share