On 10/14/05, Martin Henry H. Stevens <[EMAIL PROTECTED]> wrote: > 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) }
A not very satisfactory (but probably good enough for linear fits) is pred <- predict(mod) xyplot(Y ~ COV | FACT, pred = pred, panel = function(x, y, pred, subscripts, ...) { panel.xyplot(x,y,...) llines(x, pred[subscripts], ...) }) Deepayan ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html