From: Bryan Hanson <hanson_at_depauw.edu>

Date: Sun, 20 Jul 2008 12:44:25 -0400

R-help_at_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. Received on Sun 20 Jul 2008 - 16:47:36 GMT

Date: Sun, 20 Jul 2008 12:44:25 -0400

I can¹t seem to find an answer to this in the help pages, archives, or Deepayan¹s Lattice Book.

TIF for any suggestions, Bryan

- Example: a function then, the call to the function

fancy.lm <- function(x, y, fit = TRUE, resid = TRUE){

model <- lm(y ~ x)

y.pred <- predict(model) # Compute residuals for plotting
res.x <- as.vector(rbind(x, x, rep(NA,length(x)))) # NAs induce breaks in
line

res.y <- as.vector(rbind(y, y.pred, rep(NA,length(x)))) # after Fig 5.1 of
DAAG (clever!)

p <- xyplot(y ~ x, pch = 20,

panel = function(...) {

panel.xyplot(...) # not strictly necessary if I understand correctly })

plot(p, more = TRUE)

if (fit) {

plot(update(p, more = TRUE,

panel = function(...){ panel.xyplot(...) panel.abline(model, col = "red")}))}

if (resid) {

plot(update(p, more = TRUE,

panel = function(...){

panel.xyplot(res.x, res.y, col = "lightblue", type = "l") }))}

}

x <- jitter(c(1:10), factor = 5)

y <- jitter(c(1:10), factor = 10)

fancy.lm(x, y, fit = TRUE, resid = TRUE)

- Session Info > sessionInfo() R version 2.7.1 (2008-06-23) i386-apple-darwin8.10.1

locale:

en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:

[1] datasets grid grDevices graphics stats utils methods

[8] base

other attached packages:

[1] fastICA_1.1-9 DescribeDisplay_0.1.3 ggplot_0.4.2 [4] RColorBrewer_1.0-2 reshape_0.8.0 MASS_7.2-42 [7] pcaPP_1.5 mvtnorm_0.9-0 hints_1.0.1-1

[10] mvoutlier_1.3 robustbase_0.2-8 lattice_0.17-8

[13] rggobi_2.1.9 RGtk2_2.12.5-3

loaded via a namespace (and not attached):

[1] tools_2.7.1

R-help_at_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. Received on Sun 20 Jul 2008 - 16:47:36 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 22 Jul 2008 - 02:31:41 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*