# [R] lattice with predicted values

From: Martin Henry H. Stevens <HStevens_at_MUOhio.edu>
Date: Sat 15 Oct 2005 - 02:37:01 EST

Dear lattice wizards,

I am trying to figure out how to plot predicted values in xyplot, where the intercept, but not the slope, varies among conditioning factor levels. I am sure it involves the groups, but I have been unsuccessful in my search in Pinhiero and Bate, in the help files, or in the archive, or in my attempts on my own.

My example follows:

FACT is a factor with levels a,b,c
COV is the covariate

mod ~ lm(Y ~ COV + FACT)

#The following draws the right predictions if the relation is the
same for all factor levels, but I can't figure out how to have the same slopes but different intercepts.

# Function to draw predictions in xyplot

panel.predfinal <- function(mod, x, y) {

```     xfit <- seq(min(x), max(x), length=21)
yfit <- predict(mod, newdata=data.frame(COV=xfit))
llines(xfit,yfit,lty=1) }

xyplot(Y ~ COV | FACT,
panel=function(x,y,groups,subscripts){
panel.xyplot(x,y)
panel.predfinal(mod,x,y) }

```

I would be very grateful for pointers (books, chapters, pages, archives) that might have an example of an xyplot in which something (like the slope) is constant, and something else (like the intercepts) varies by factor level.
Cheers,
Hank

Dr. Martin Henry H. Stevens, Assistant Professor 338 Pearson Hall
Botany Department
Miami University
Oxford, OH 45056

Office: (513) 529-4206
Lab: (513) 529-4262
FAX: (513) 529-4243

```http://www.cas.muohio.edu/~stevenmh/
http://www.muohio.edu/ecology/
http://www.muohio.edu/botany/
```

"E Pluribus Unum"

R-help@stat.math.ethz.ch mailing list