How can I get a print-out of the summary for a model fit to each lattice panel?
For example, using the sleepstudy dataste from lme4:
library(lme4)
data(sleepstudy)
I can fit a linear model to all the data and print the summary:
plot(sleepstudy$Days, sleepstudy$Reaction)
model <- lm(formula = Reaction ~ Days,data = sleepstudy)
abline(model, col = "salmon")
summary(model)
How can I do print a summary for each lattice panel?
xyplot(Reaction ~ Days | Subject,
data = sleepstudy,
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
fm <- lm(y ~ poly(x, 2))
panel.lines(x, fitted(fm), col.line="salmon")
}
)