Skip to content
Prev 106176 / 398506 Next

xyplot: discrete points + continuous curve per panel

On 12/13/06, RMan54 <RMan54 at cox.net> wrote:
Depends on how much work you are willing to do. There is no reason for
panel.curve to not work, provided you give it a "curve" to plot. This
is normally done in the form of a vectorized function of one variable,
which will be called with a vector of values spanning the x-axis of
your plot. It is your responsibility to construct such a function
inside each panel (presumably it would involve your myPred function).

The easy way, that generally works well for longitudinal data (with
increasing x values within a panel), is to add a column of predicted
values to your data frame. For most model fitting routines in R, the
paradigm is:

fm <- some.model(y ~ whatever, data = mydata, ...)
mydata$fit <- fitted(fm)

xyplot(y + fit ~ whatever,
       type = list("p", "l"), distribute.type = TRUE)

A real example being:

library(lme4)
data(Oxboys, package = "nlme")
Oxboys$fit <- fitted(lmer(height ~ age + (1|Subject), data = Oxboys))
xyplot(height + fit ~ age | Subject, Oxboys,
       type = c("p", "l"), distribute.type = TRUE,
       aspect = "xy")


Things will be more complicated if you already have a grouping
variable (the solution is to pass down the vector of fitted values to
the panel function and use 'subscripts' to retrieve the ones that
belong in the panel).

-Deepayan