On Fri, Sep 9, 2011 at 9:38 PM, Bigelow, Seth <sbige...@fs.fed.us> wrote:
> I wish to display a single-panel Lattice figure with grouped data and fitted 
> regression lines. I don't seem to be able to get the
> individual regression lines to display, e.g.;
>
> d <- data.frame(q = rep(1:6, each=10), cc = rep(seq(10,100, 10),6))           
>                # create data frame with group identifier 'q', independent 
> variable cc
> d$ba = d$q*0.1*d$cc + 5*rnorm(nrow(d))                                        
>                                    # create dependent variable 'ba'
>
> mypanel <- function(...){                                                     
>                                                          # panel function
>                panel.lmline(d$cc, d$ba, groups = d$q)                         
>                                          #
>                panel.xyplot(...)
>                }

But panel.lmline() does not honour a 'groups' argument, so there is no
reason for this to work.

> xyplot(ba~cc,d,
>                groups=q,
>                panel = panel.superpose,
>                panel.groups=mypanel
>                )
>
> Can anyone suggest how to get lines to display by group?

How about

xyplot(ba~cc,d, groups=q, type=c("p", "r"))

> (and how to get lmline panel to fit line without estimating an intercept?)

xyplot(ba~cc,d, groups=q, panel = panel.superpose,
       panel.groups = function(x, y, ...) {
           panel.xyplot(x, y, ...)
           panel.abline(0, coef(lm(y ~ 0 + x)), ...)
       })

-Deepayan
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to